[PATCH 3/5] resource: Remove a redundant field from client resource tracking
Adam Jackson
ajax at redhat.com
Fri Jan 7 11:27:27 PST 2011
We only ever need log2(buckets) when rebuilding the table, which is
comparatively rare. Compute it when we need it instead of tracking it
by hand.
Signed-off-by: Adam Jackson <ajax at redhat.com>
---
dix/resource.c | 21 +++++++++++++++------
1 files changed, 15 insertions(+), 6 deletions(-)
diff --git a/dix/resource.c b/dix/resource.c
index fcda116..a5737f3 100644
--- a/dix/resource.c
+++ b/dix/resource.c
@@ -158,7 +158,6 @@ static void RebuildTable(
#define SERVER_MINID 32
#define INITBUCKETS 64
-#define INITHASHSIZE 6
#define MAXHASHSIZE 11
typedef struct _Resource {
@@ -172,7 +171,6 @@ typedef struct _ClientResource {
ResourcePtr *resources;
int elements;
int buckets;
- int hashsize; /* log(2)(buckets) */
XID fakeID;
XID endFakeID;
XID expectID;
@@ -233,6 +231,19 @@ static const struct ResourceType predefTypes[] = {
CallbackListPtr ResourceStateCallback;
+static int
+ilog2(unsigned int x)
+{
+ int r = 0;
+
+ while (x > 1) {
+ r++;
+ x >>= 1;
+ }
+
+ return r;
+}
+
static _X_INLINE void
CallResourceStateCallback(ResourceState state, ResourceRec *res)
{
@@ -313,7 +324,6 @@ InitClientResources(ClientPtr client)
return FALSE;
clientTable[i].buckets = INITBUCKETS;
clientTable[i].elements = 0;
- clientTable[i].hashsize = INITHASHSIZE;
/* Many IDs allocated from the server client are visible to clients,
* so we don't use the SERVER_BIT for them, but we have to start
* past the magic value constants used in the protocol. For normal
@@ -335,7 +345,7 @@ static int
Hash(int client, XID id)
{
id &= RESOURCE_ID_MASK;
- switch (clientTable[client].hashsize)
+ switch (ilog2(clientTable[client].buckets))
{
case 6:
return ((int)(0x03F & (id ^ (id>>6) ^ (id>>12))));
@@ -495,7 +505,7 @@ AddResource(XID id, RESTYPE type, pointer value)
FatalError("client not in use\n");
}
if ((rrec->elements >= 4*rrec->buckets) &&
- (rrec->hashsize < MAXHASHSIZE))
+ (ilog2(rrec->buckets) < MAXHASHSIZE))
RebuildTable(client);
head = &rrec->resources[Hash(client, id)];
res = malloc(sizeof(ResourceRec));
@@ -544,7 +554,6 @@ RebuildTable(int client)
*rptr = NULL;
*tptr = rptr;
}
- clientTable[client].hashsize++;
for (j = clientTable[client].buckets,
rptr = clientTable[client].resources;
--j >= 0;
--
1.7.3.1
More information about the xorg-devel
mailing list