Make cache reference counting more efficient.

Eliminate need to reference cache object once per cached font, instead
just count the number of fonts used from the cache and bump the reference
count once by that amount. I think this makes this refernece technique
efficient enough for use.
This commit is contained in:
Keith Packard 2006-09-04 22:26:24 -07:00
parent 9e612141df
commit 17389539a0
3 changed files with 16 additions and 1 deletions

View File

@ -476,6 +476,15 @@ FcDirCacheMapFd (int fd, struct stat *fd_stat)
return cache; return cache;
} }
void
FcDirCacheReference (FcCache *cache, int nref)
{
FcCacheSkip *skip = FcCacheFindByAddr (cache);
if (skip)
skip->ref += nref;
}
void void
FcDirCacheUnload (FcCache *cache) FcDirCacheUnload (FcCache *cache)
{ {

View File

@ -239,6 +239,8 @@ FcConfigAddCache (FcConfig *config, FcCache *cache)
fs = FcCacheSet (cache); fs = FcCacheSet (cache);
if (fs) if (fs)
{ {
int nref = 0;
for (i = 0; i < fs->nfont; i++) for (i = 0; i < fs->nfont; i++)
{ {
FcPattern *font = FcFontSetFont (fs, i); FcPattern *font = FcFontSetFont (fs, i);
@ -260,9 +262,10 @@ FcConfigAddCache (FcConfig *config, FcCache *cache)
if (!FcConfigAcceptFont (config, font)) if (!FcConfigAcceptFont (config, font))
continue; continue;
FcPatternReference (font); nref++;
FcFontSetAdd (config->fonts[FcSetSystem], font); FcFontSetAdd (config->fonts[FcSetSystem], font);
} }
FcDirCacheReference (cache, nref);
} }
/* /*

View File

@ -513,6 +513,9 @@ FcCacheObjectDereference (void *object);
FcPrivate void FcPrivate void
FcCacheFini (void); FcCacheFini (void);
void
FcDirCacheReference (FcCache *cache, int nref);
/* fccfg.c */ /* fccfg.c */
FcPrivate FcBool FcPrivate FcBool