]> git.wh0rd.org - fontconfig.git/commitdiff
Implement move-to-front array for banks (perf regression reported by Ronny
authorPatrick Lam <plam@MIT.EDU>
Wed, 5 Oct 2005 18:41:55 +0000 (18:41 +0000)
committerPatrick Lam <plam@MIT.EDU>
Wed, 5 Oct 2005 18:41:55 +0000 (18:41 +0000)
    V. Vindenes).

ChangeLog
src/fccache.c

index b7cfb91d206461ac243bafebdd56154d9359279f..3bbf227025c987ee584f77616fa4e7bb44ac494d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2005-10-05  Patrick Lam  <plam@mit.edu>
+       * src/fccache.c (FcCacheHaveBank):
+
+       Implement move-to-front array for banks (perf regression
+       reported by Ronny V. Vindenes).
+
 2005-10-04  Patrick Lam  <plam@mit.edu>
        * src/fccache.c (FcDirCacheValid, FcDirCacheUnlink, 
                         FcDirCacheHasCurrentArch):
index 43e45af92cfbbcdb59595d49818c57274348bc7c..0e8c476ffa26b8368acb57a318fb0b9c92a43968 100644 (file)
@@ -949,7 +949,7 @@ FcCacheMachineSignature ()
 }
 
 static int banks_ptr = 0, banks_alloc = 0;
-static int * bankId = 0;
+static int * bankId = 0, * bankIdx = 0;
 
 static FcBool
 FcCacheHaveBank (int bank)
@@ -969,28 +969,37 @@ FcCacheHaveBank (int bank)
 int
 FcCacheBankToIndex (int bank)
 {
-    static int lastBank = FC_BANK_DYNAMIC, lastIndex = -1;
-    int i;
-    int * b;
-
-    if (bank == lastBank)
-       return lastIndex;
+    int i, j;
 
     for (i = 0; i < banks_ptr; i++)
-       if (bankId[i] == bank)
-           return i;
+       if (bankId[bankIdx[i]] == bank)
+       {
+           int t = bankIdx[i];
+
+           for (j = i; j > 0; j--)
+               bankIdx[j] = bankIdx[j-1];
+           bankIdx[0] = t;
+           return t;
+       }
 
     if (banks_ptr >= banks_alloc)
     {
+       int * b, * bidx;
        b = realloc (bankId, (banks_alloc + 4) * sizeof(int));
        if (!b)
            return -1;
-
        bankId = b;
+
+       bidx = realloc (bankIdx, (banks_alloc + 4) * sizeof(int));
+       if (!bidx)
+           return -1;
+       bankIdx = bidx;
+
        banks_alloc += 4;
     }
 
     i = banks_ptr++;
     bankId[i] = bank;
+    bankIdx[i] = i;
     return i;
 }