summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErkki Seppälä <erkki.seppala@vincit.fi>2011-04-06 10:16:53 +0300
committerErkki Seppälä <erkki.seppala@vincit.fi>2012-04-18 12:44:49 +0300
commita2ac01a8ea8508ed35aa844a589672c1165e05e4 (patch)
treea77b0008a255b6f8380952649eca01ceec11b1f6
parenta0b0fb83f91bb82534a0d83fdd6c0222567b098d (diff)
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>
-rw-r--r--dix/resource.c30
-rw-r--r--include/resource.h8
2 files changed, 20 insertions, 18 deletions
diff --git a/dix/resource.c b/dix/resource.c
index 9714061b8..cdbe54741 100644
--- a/dix/resource.c
+++ b/dix/resource.c
@@ -655,13 +655,13 @@ HashResourceID(XID id, int numBits)
case 11:
return ((int)(0x7FF & (id ^ (id>>11))));
}
- return -1;
-}
-
-static int
-Hash(int client, XID id)
-{
- return HashResourceID(id, clientTable[client].hashsize);
+ if (numBits >= 11)
+ return ((int)(0x7FF & (id ^ (id>>11))));
+ else
+ {
+ assert(numBits >= 0);
+ return id & ~((~0) << numBits);
+ }
}
static XID
@@ -672,7 +672,7 @@ AvailableID(int client, XID id, XID maxid, XID goodid)
if ((goodid >= id) && (goodid <= maxid))
return goodid;
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))
res = res->next;
if (!res)
@@ -798,7 +798,7 @@ AddResource(XID id, RESTYPE type, pointer value)
}
if ((rrec->elements >= 4 * rrec->buckets) && (rrec->hashsize < MAXHASHSIZE))
RebuildTable(client);
- head = &rrec->resources[Hash(client, id)];
+ head = &rrec->resources[HashResourceID(id, clientTable[client].hashsize)];
res = malloc(sizeof(ResourceRec));
if (!res) {
(*resourceTypes[type & TypeMask].deleteFunc) (value, id);
@@ -846,7 +846,7 @@ RebuildTable(int client)
for (res = *rptr; res; res = next) {
next = res->next;
res->next = NULL;
- tptr = &tails[Hash(client, res->id)];
+ tptr = &tails[HashResourceID(res->id, clientTable[client].hashsize)];
**tptr = res;
*tptr = &res->next;
}
@@ -878,7 +878,7 @@ FreeResource(XID id, RESTYPE skipDeleteFuncType)
int elements;
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;
prev = head;
@@ -912,7 +912,7 @@ FreeResourceByType(XID id, RESTYPE type, Bool skipFree)
ResourcePtr *prev, *head;
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;
while ((res = *prev)) {
@@ -947,7 +947,7 @@ ChangeResourceValue(XID id, RESTYPE rtype, pointer value)
ResourcePtr res;
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)
if ((res->id == id) && (res->type == rtype)) {
@@ -1185,7 +1185,7 @@ dixLookupResourceByType(pointer *result, XID id, RESTYPE rtype,
return BadImplementation;
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)
if (res->id == id && res->type == rtype)
@@ -1218,7 +1218,7 @@ dixLookupResourceByClass(pointer *result, XID id, RESTYPE rclass,
*result = NULL;
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)
if (res->id == id && (res->type & rclass))
diff --git a/include/resource.h b/include/resource.h
index e8f263705..ae5dd51e7 100644
--- a/include/resource.h
+++ b/include/resource.h
@@ -275,10 +275,12 @@ extern _X_EXPORT RESTYPE TypeMask;
/** @brief A hashing function to be used for hashing resource IDs
@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
- hashes and will return -1 if numBits is not within those bounds.
+ @note This function is really only for handling
+ 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,
int numBits);