dix: don't use a local wrapper for calling HashResourceID

Calls to Hash(client, id) were replaced with calls directly to
HashResourceID(id, clientTable[client].hashsize) and the Hash-function
was removed.

Signed-off-by: Erkki Seppälä <erkki.seppala@vincit.fi>
This commit is contained in:
Erkki Seppälä 2011-04-06 10:16:53 +03:00
parent a0b0fb83f9
commit a2ac01a8ea
2 changed files with 20 additions and 18 deletions

View File

@ -655,13 +655,13 @@ HashResourceID(XID id, int numBits)
case 11: case 11:
return ((int)(0x7FF & (id ^ (id>>11)))); return ((int)(0x7FF & (id ^ (id>>11))));
} }
return -1; if (numBits >= 11)
} return ((int)(0x7FF & (id ^ (id>>11))));
else
static int {
Hash(int client, XID id) assert(numBits >= 0);
{ return id & ~((~0) << numBits);
return HashResourceID(id, clientTable[client].hashsize); }
} }
static XID static XID
@ -672,7 +672,7 @@ AvailableID(int client, XID id, XID maxid, XID goodid)
if ((goodid >= id) && (goodid <= maxid)) if ((goodid >= id) && (goodid <= maxid))
return goodid; return goodid;
for (; id <= maxid; id++) { for (; id <= maxid; id++) {
res = clientTable[client].resources[Hash(client, id)]; res = clientTable[client].resources[HashResourceID(id, clientTable[client].hashsize)];
while (res && (res->id != id)) while (res && (res->id != id))
res = res->next; res = res->next;
if (!res) if (!res)
@ -798,7 +798,7 @@ AddResource(XID id, RESTYPE type, pointer value)
} }
if ((rrec->elements >= 4 * rrec->buckets) && (rrec->hashsize < MAXHASHSIZE)) if ((rrec->elements >= 4 * rrec->buckets) && (rrec->hashsize < MAXHASHSIZE))
RebuildTable(client); RebuildTable(client);
head = &rrec->resources[Hash(client, id)]; head = &rrec->resources[HashResourceID(id, clientTable[client].hashsize)];
res = malloc(sizeof(ResourceRec)); res = malloc(sizeof(ResourceRec));
if (!res) { if (!res) {
(*resourceTypes[type & TypeMask].deleteFunc) (value, id); (*resourceTypes[type & TypeMask].deleteFunc) (value, id);
@ -846,7 +846,7 @@ RebuildTable(int client)
for (res = *rptr; res; res = next) { for (res = *rptr; res; res = next) {
next = res->next; next = res->next;
res->next = NULL; res->next = NULL;
tptr = &tails[Hash(client, res->id)]; tptr = &tails[HashResourceID(res->id, clientTable[client].hashsize)];
**tptr = res; **tptr = res;
*tptr = &res->next; *tptr = &res->next;
} }
@ -878,7 +878,7 @@ FreeResource(XID id, RESTYPE skipDeleteFuncType)
int elements; int elements;
if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && clientTable[cid].buckets) { if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && clientTable[cid].buckets) {
head = &clientTable[cid].resources[Hash(cid, id)]; head = &clientTable[cid].resources[HashResourceID(id, clientTable[cid].hashsize)];
eltptr = &clientTable[cid].elements; eltptr = &clientTable[cid].elements;
prev = head; prev = head;
@ -912,7 +912,7 @@ FreeResourceByType(XID id, RESTYPE type, Bool skipFree)
ResourcePtr *prev, *head; ResourcePtr *prev, *head;
if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && clientTable[cid].buckets) { if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && clientTable[cid].buckets) {
head = &clientTable[cid].resources[Hash(cid, id)]; head = &clientTable[cid].resources[HashResourceID(id, clientTable[cid].hashsize)];
prev = head; prev = head;
while ((res = *prev)) { while ((res = *prev)) {
@ -947,7 +947,7 @@ ChangeResourceValue(XID id, RESTYPE rtype, pointer value)
ResourcePtr res; ResourcePtr res;
if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && clientTable[cid].buckets) { if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && clientTable[cid].buckets) {
res = clientTable[cid].resources[Hash(cid, id)]; res = clientTable[cid].resources[HashResourceID(id, clientTable[cid].hashsize)];
for (; res; res = res->next) for (; res; res = res->next)
if ((res->id == id) && (res->type == rtype)) { if ((res->id == id) && (res->type == rtype)) {
@ -1185,7 +1185,7 @@ dixLookupResourceByType(pointer *result, XID id, RESTYPE rtype,
return BadImplementation; return BadImplementation;
if ((cid < MAXCLIENTS) && clientTable[cid].buckets) { if ((cid < MAXCLIENTS) && clientTable[cid].buckets) {
res = clientTable[cid].resources[Hash(cid, id)]; res = clientTable[cid].resources[HashResourceID(id, clientTable[cid].hashsize)];
for (; res; res = res->next) for (; res; res = res->next)
if (res->id == id && res->type == rtype) if (res->id == id && res->type == rtype)
@ -1218,7 +1218,7 @@ dixLookupResourceByClass(pointer *result, XID id, RESTYPE rclass,
*result = NULL; *result = NULL;
if ((cid < MAXCLIENTS) && clientTable[cid].buckets) { if ((cid < MAXCLIENTS) && clientTable[cid].buckets) {
res = clientTable[cid].resources[Hash(cid, id)]; res = clientTable[cid].resources[HashResourceID(id, clientTable[cid].hashsize)];
for (; res; res = res->next) for (; res; res = res->next)
if (res->id == id && (res->type & rclass)) if (res->id == id && (res->type & rclass))

View File

@ -275,10 +275,12 @@ extern _X_EXPORT RESTYPE TypeMask;
/** @brief A hashing function to be used for hashing resource IDs /** @brief A hashing function to be used for hashing resource IDs
@param id The resource ID to hash @param id The resource ID to hash
@param numBits The number of bits in the resulting hash @param numBits The number of bits in the resulting hash. Must be >=0.
@note This function can only handle INITHASHSIZE..MAXHASHSIZE bit @note This function is really only for handling
hashes and will return -1 if numBits is not within those bounds. INITHASHSIZE..MAXHASHSIZE bit hashes, but will handle any number
of bits by either masking numBits lower bits of the ID or by
providing at most MAXHASHSIZE hashes.
*/ */
extern _X_EXPORT int HashResourceID(XID id, extern _X_EXPORT int HashResourceID(XID id,
int numBits); int numBits);