summaryrefslogtreecommitdiff
path: root/dix/resource.c
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2016-10-28 09:28:32 -0700
committerKeith Packard <keithp@keithp.com>2016-10-28 09:28:32 -0700
commitc85f81825e196e96337347e0ce3a538fb2e38f16 (patch)
treea3ed443f87e2b62223928b821c642b4bb3c58106 /dix/resource.c
parent356db2340f5b473a7191c7969586ca5b0396c48f (diff)
dix: Bump MAXHASHSIZE for the resource db [v2]
[This was originally a workaround for a client-side resource leak: http://lists.freedesktop.org/archives/xorg-devel/2012-November/034555.html Obviously that's a broken app, but the performance problem it illustrates - that walking the linked list ends up burning all your CPU time - is real enough. - ajax] v2: Replace with a shorter code sequence which computes the same results for all but numBits == 7 Reviewed-by: Adam Jackson <ajax@redhat.com> Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'dix/resource.c')
-rw-r--r--dix/resource.c33
1 files changed, 9 insertions, 24 deletions
diff --git a/dix/resource.c b/dix/resource.c
index 68efd2471..b6ef99f10 100644
--- a/dix/resource.c
+++ b/dix/resource.c
@@ -156,7 +156,7 @@ static void RebuildTable(int /*client */
#define INITBUCKETS 64
#define INITHASHSIZE 6
-#define MAXHASHSIZE 11
+#define MAXHASHSIZE 16
typedef struct _Resource {
struct _Resource *next;
@@ -668,29 +668,14 @@ InitClientResources(ClientPtr client)
int
HashResourceID(XID id, int numBits)
{
- id &= RESOURCE_ID_MASK;
- switch (numBits)
- {
- case 6:
- return ((int)(0x03F & (id ^ (id>>6) ^ (id>>12))));
- case 7:
- return ((int)(0x07F & (id ^ (id>>7) ^ (id>>13))));
- case 8:
- return ((int)(0x0FF & (id ^ (id>>8) ^ (id>>16))));
- case 9:
- return ((int)(0x1FF & (id ^ (id>>9))));
- case 10:
- return ((int)(0x3FF & (id ^ (id>>10))));
- case 11:
- return ((int)(0x7FF & (id ^ (id>>11))));
- }
- if (numBits >= 11)
- return ((int)(0x7FF & (id ^ (id>>11))));
- else
- {
- assert(numBits >= 0);
- return id & ~((~0) << numBits);
- }
+ static XID mask;
+
+ if (!mask)
+ mask = RESOURCE_ID_MASK;
+ id &= mask;
+ if (numBits < 9)
+ return (id ^ (id >> numBits) ^ (id >> (numBits<<1))) & ~((~0) << numBits);
+ return (id ^ (id >> numBits)) & ~((~0) << numBits);
}
static XID