Make cache reference counting more efficient.
authorKeith Packard <keithp@neko.keithp.com>
Tue, 5 Sep 2006 05:26:24 +0000 (22:26 -0700)
committerKeith Packard <keithp@neko.keithp.com>
Tue, 5 Sep 2006 05:26:24 +0000 (22:26 -0700)
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.

src/fccache.c
src/fccfg.c
src/fcint.h

index 69a29f2..77a303d 100644 (file)
@@ -477,6 +477,15 @@ FcDirCacheMapFd (int fd, struct stat *fd_stat)
 }
 
 void
+FcDirCacheReference (FcCache *cache, int nref)
+{
+    FcCacheSkip *skip = FcCacheFindByAddr (cache);
+
+    if (skip)
+       skip->ref += nref;
+}
+
+void
 FcDirCacheUnload (FcCache *cache)
 {
     FcCacheObjectDereference (cache);
index 1139744..d9502f0 100644 (file)
@@ -239,6 +239,8 @@ FcConfigAddCache (FcConfig *config, FcCache *cache)
     fs = FcCacheSet (cache);
     if (fs)
     {
+       int     nref = 0;
+       
        for (i = 0; i < fs->nfont; i++)
        {
            FcPattern   *font = FcFontSetFont (fs, i);
@@ -260,9 +262,10 @@ FcConfigAddCache (FcConfig *config, FcCache *cache)
            if (!FcConfigAcceptFont (config, font))
                continue;
                
-           FcPatternReference (font);
+           nref++;
            FcFontSetAdd (config->fonts[FcSetSystem], font);
        }
+       FcDirCacheReference (cache, nref);
     }
 
     /*
index a054219..7dab169 100644 (file)
@@ -513,6 +513,9 @@ FcCacheObjectDereference (void *object);
 FcPrivate void
 FcCacheFini (void);
     
+void
+FcDirCacheReference (FcCache *cache, int nref);
+
 /* fccfg.c */
 
 FcPrivate FcBool