From c85f81825e196e96337347e0ce3a538fb2e38f16 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 28 Oct 2016 09:28:32 -0700 Subject: [PATCH] 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 Signed-off-by: Keith Packard --- dix/resource.c | 33 +++++++++------------------------ 1 file 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