From: Patrick Lam Date: Tue, 29 Nov 2005 14:57:10 +0000 (+0000) Subject: Refactor FcCacheBankToIndex into an inlineable part (in fcint.h) which X-Git-Tag: fc-2_3_93~14 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=b8948e85420469c83098a6b97d7979189a8734d9;p=fontconfig.git 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. reviewed by: plam --- diff --git a/ChangeLog b/ChangeLog index 39de7e6..d49ecc4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2005-11-29 Dirk Mueller + 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 * src/fccfg.c (FcConfigBuildFonts): * src/fccache.c (FcCacheReadDirs): diff --git a/fc-lang/fc-lang.c b/fc-lang/fc-lang.c index ab20fd0..936a00b 100644 --- a/fc-lang/fc-lang.c +++ b/fc-lang/fc-lang.c @@ -51,8 +51,11 @@ FcMemFree (int kind, int size) { } +int* _fcBankId = 0; +int* _fcBankIdx = 0; + int -FcCacheBankToIndex (int bank) +FcCacheBankToIndexMTF (int bank) { return -1; } diff --git a/src/fccache.c b/src/fccache.c index 00948c3..13c3896 100644 --- a/src/fccache.c +++ b/src/fccache.c @@ -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; diff --git a/src/fcint.h b/src/fcint.h index 561c5cb..c61a232 100644 --- a/src/fcint.h +++ b/src/fcint.h @@ -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);