From 9b30cc524867a0ad3d0d2227e167f4284830ab4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michel=20D=C3=A4nzer?= Date: Thu, 17 Apr 2008 16:10:10 +0200 Subject: [PATCH] Optimize dixLookupPrivate for repeated lookups of the same private. This gives me a 20% speedup for EXA text rendering, though I still seem to burn quite a lot of cycles in here... --- include/privates.h | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/include/privates.h b/include/privates.h index 8d59b728f..093d17779 100644 --- a/include/privates.h +++ b/include/privates.h @@ -46,13 +46,20 @@ dixAllocatePrivate(PrivateRec **privates, const DevPrivateKey key); static _X_INLINE pointer dixLookupPrivate(PrivateRec **privates, const DevPrivateKey key) { - PrivateRec *rec = *privates; + PrivateRec *rec, *prev; pointer *ptr; - while (rec) { - if (rec->key == key) - return rec->value; - rec = rec->next; + for (rec = *privates, prev = NULL; rec; prev = rec, rec = rec->next) { + if (rec->key != key) + continue; + + if (prev) { + prev->next = rec->next; + rec->next = *privates; + *privates = rec; + } + + return rec->value; } ptr = dixAllocatePrivate(privates, key);