]> git.wh0rd.org - fontconfig.git/commitdiff
Refactor FcCacheBankToIndex into an inlineable part (in fcint.h) which
authorPatrick Lam <plam@MIT.EDU>
Tue, 29 Nov 2005 14:57:10 +0000 (14:57 +0000)
committerPatrick Lam <plam@MIT.EDU>
Tue, 29 Nov 2005 14:57:10 +0000 (14:57 +0000)
    checks the front of the list and a non-inlineable part which finds and
    moves the appropriate element to the front of the list.
reviewed by: plam

ChangeLog
fc-lang/fc-lang.c
src/fccache.c
src/fcint.h

index 39de7e67e33a551ceb1dc94edbb5e76bb906363e..d49ecc4df9843a5a26f2d1c2b6b4d6f106a0587e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2005-11-29  Dirk Mueller  <dmueller@suse.de>
+       reviewed by: plam
+       
+       * fc-lang/fc-lang.c:
+       * src/fccache.c (FcDirCacheConsume, FcCacheHaveBank,
+                        FcCacheBankToIndex, FcCacheBankToIndexMTF,
+                        FcCacheAddBankDir):
+       * src/fcint.h:
+
+       Refactor FcCacheBankToIndex into an inlineable part
+       (in fcint.h) which checks the front of the list and a
+       non-inlineable part which finds and moves the appropriate element
+       to the front of the list.
+
 2005-11-29  Patrick Lam  <plam@mit.edu>
        * src/fccfg.c (FcConfigBuildFonts):
        * src/fccache.c (FcCacheReadDirs):
index ab20fd095fa523fda00e284895ea72d62971b378..936a00b25e9f5b4e47b59c9ca8a87eb91ef9c22d 100644 (file)
@@ -51,8 +51,11 @@ FcMemFree (int kind, int size)
 {
 }
 
+int* _fcBankId = 0;
+int* _fcBankIdx = 0;
+
 int
-FcCacheBankToIndex (int bank)
+FcCacheBankToIndexMTF (int bank)
 {
     return -1;
 }
index 00948c3b51b3a336f567c86680bcbc0e208e7db7..13c38963da40764226aa6241c422736fb8037c3d 100644 (file)
@@ -782,12 +782,12 @@ FcDirCacheConsume (int fd, const char * dir, FcFontSet *set)
                              PROT_READ, MAP_SHARED, fd, pos);
     if (current_dir_block == MAP_FAILED)
        return FcFalse;
-    
-    if (!FcFontSetUnserialize (&metadata, set, current_dir_block))
-       return FcFalse;
 
     FcCacheAddBankDir (metadata.bank, dir);
 
+    if (!FcFontSetUnserialize (&metadata, set, current_dir_block))
+       return FcFalse;
+
     return FcTrue;
 }
 
@@ -989,7 +989,7 @@ FcCacheMachineSignature ()
 }
 
 static int banks_ptr = 0, banks_alloc = 0;
-static int * bankId = 0, * bankIdx = 0;
+int * _fcBankId = 0, * _fcBankIdx = 0;
 static const char ** bankDirs = 0;
 
 static FcBool
@@ -1001,25 +1001,25 @@ FcCacheHaveBank (int bank)
        return FcTrue;
 
     for (i = 0; i < banks_ptr; i++)
-       if (bankId[i] == bank)
+       if (_fcBankId[i] == bank)
            return FcTrue;
 
     return FcFalse;
 }
 
 int
-FcCacheBankToIndex (int bank)
+FcCacheBankToIndexMTF (int bank)
 {
     int i, j;
 
     for (i = 0; i < banks_ptr; i++)
-       if (bankId[bankIdx[i]] == bank)
+       if (_fcBankId[_fcBankIdx[i]] == bank)
        {
-           int t = bankIdx[i];
+           int t = _fcBankIdx[i];
 
            for (j = i; j > 0; j--)
-               bankIdx[j] = bankIdx[j-1];
-           bankIdx[0] = t;
+               _fcBankIdx[j] = _fcBankIdx[j-1];
+           _fcBankIdx[0] = t;
            return t;
        }
 
@@ -1028,15 +1028,15 @@ FcCacheBankToIndex (int bank)
        int * b, * bidx;
        const char ** bds;
 
-       b = realloc (bankId, (banks_alloc + 4) * sizeof(int));
+       b = realloc (_fcBankId, (banks_alloc + 4) * sizeof(int));
        if (!b)
            return -1;
-       bankId = b;
+       _fcBankId = b;
 
-       bidx = realloc (bankIdx, (banks_alloc + 4) * sizeof(int));
+       bidx = realloc (_fcBankIdx, (banks_alloc + 4) * sizeof(int));
        if (!bidx)
            return -1;
-       bankIdx = bidx;
+       _fcBankIdx = bidx;
 
        bds = realloc (bankDirs, (banks_alloc + 4) * sizeof (char *));
        if (!bds)
@@ -1047,15 +1047,15 @@ FcCacheBankToIndex (int bank)
     }
 
     i = banks_ptr++;
-    bankId[i] = bank;
-    bankIdx[i] = i;
+    _fcBankId[i] = bank;
+    _fcBankIdx[i] = i;
     return i;
 }
 
 static void
 FcCacheAddBankDir (int bank, const char * dir)
 {
-    int bi = FcCacheBankToIndex (bank);
+    int bi = FcCacheBankToIndexMTF (bank);
 
     if (bi < 0)
        return;
index 561c5cb5bd6382857f2fd68894125bfcc658e7ab..c61a2326cc0047e4fc781f5dc9f6152c0cacd896 100644 (file)
@@ -462,8 +462,15 @@ FcDirCacheWrite (FcFontSet *set, FcStrSet * dirs, const FcChar8 *dir);
 FcBool
 FcDirCacheRead (FcFontSet * set, FcStrSet * dirs, const FcChar8 *dir);
 
+extern int *_fcBankId, *_fcBankIdx;
 int
-FcCacheBankToIndex (int bank);
+FcCacheBankToIndexMTF (int bank);
+
+static __inline__ int
+FcCacheBankToIndex (int bank)
+{
+    return _fcBankId[*_fcBankIdx] == bank ? *_fcBankIdx : FcCacheBankToIndexMTF(bank);
+}
 
 const char *
 FcCacheFindBankDir (int bank);