]> git.wh0rd.org - fontconfig.git/blobdiff - src/fccfg.c
Eliminate NormalizeDir. Eliminate gratuitous stat/access calls per dir.
[fontconfig.git] / src / fccfg.c
index 2135d67f790316cdf4aaa5525ccac98b2d5f4342..3c3681a100620e9c803e811aae0f55195121e340 100644 (file)
@@ -23,6 +23,8 @@
  */
 
 #include "fcint.h"
+#include <dirent.h>
+#include <sys/types.h>
 
 #if defined (_WIN32) && (defined (PIC) || defined (DLL_EXPORT))
 #define STRICT
@@ -98,13 +100,17 @@ FcConfigCreate (void)
            if (!FcConfigSetCache (config, cache_dir))
            {
                FcStrFree (cache_dir);
-               goto bail6;
+               goto bail8;
            }
            FcStrFree (cache_dir);
        }
     }
 #endif
 
+    config->cacheDirs = FcStrSetCreate ();
+    if (!config->cacheDirs)
+       goto bail9;
+    
     config->blanks = 0;
 
     config->substPattern = 0;
@@ -118,6 +124,8 @@ FcConfigCreate (void)
     
     return config;
 
+bail9:
+    FcStrFree (config->cache);
 bail8:
     FcFontSetDestroy (config->rejectPatterns);
 bail7:
@@ -224,6 +232,7 @@ FcConfigDestroy (FcConfig *config)
 
     FcStrSetDestroy (config->configDirs);
     FcStrSetDestroy (config->fontDirs);
+    FcStrSetDestroy (config->cacheDirs);
     FcStrSetDestroy (config->configFiles);
     FcStrSetDestroy (config->acceptGlobs);
     FcStrSetDestroy (config->rejectGlobs);
@@ -281,7 +290,7 @@ FcConfigBuildFonts (FcConfig *config)
     {
        list = FcConfigGetFontDirs (config);
        if (!list)
-           goto bail2;
+           goto bail3;
        
        while ((dir = FcStrListNext (list)))
        {
@@ -332,8 +341,10 @@ FcConfigBuildFonts (FcConfig *config)
     FcConfigSetFonts (config, fonts, FcSetSystem);
     
     return FcTrue;
-bail2:
+bail3:
     FcStrSetDestroy (oldDirs);
+bail2:
+    FcGlobalCacheDestroy (cache);
 bail1:
     FcFontSetDestroy (fonts);
 bail0:
@@ -388,30 +399,6 @@ FcConfigAddFontDir (FcConfig           *config,
     return FcStrSetAddFilename (config->fontDirs, d);
 }
 
-const FcChar8 *
-FcConfigNormalizeFontDir (FcConfig     *config, 
-                         const FcChar8 *d)
-{
-    /* If this is a bottleneck, we can cache the fontDir inodes. */
-    ino_t      di;
-    dev_t      dd;
-    int                n;
-    struct stat s;
-
-    if (stat ((char *)d, &s) == -1)
-       return 0;
-    di = s.st_ino; dd = s.st_dev;
-
-    for (n = 0; n < config->fontDirs->num; n++)
-    {
-       if (stat ((char *)config->fontDirs->strs[n], &s) == -1)
-           continue;
-       if (di == s.st_ino && dd == s.st_dev)
-           return config->fontDirs->strs[n];
-    }
-    return 0;
-}
-
 FcBool
 FcConfigAddDir (FcConfig           *config,
                const FcChar8       *d)
@@ -432,6 +419,25 @@ FcConfigGetFontDirs (FcConfig      *config)
     return FcStrListCreate (config->fontDirs);
 }
 
+FcBool
+FcConfigAddCacheDir (FcConfig      *config,
+                    const FcChar8  *d)
+{
+    return FcStrSetAddFilename (config->cacheDirs, d);
+}
+
+FcStrList *
+FcConfigGetCacheDirs (FcConfig *config)
+{
+    if (!config)
+    {
+       config = FcConfigGetCurrent ();
+       if (!config)
+           return 0;
+    }
+    return FcStrListCreate (config->cacheDirs);
+}
+    
 FcBool
 FcConfigAddConfigFile (FcConfig            *config,
                       const FcChar8   *f)
@@ -526,17 +532,21 @@ FcBool
 FcConfigAddBlank (FcConfig     *config,
                  FcChar32      blank)
 {
-    FcBlanks   *b;
+    FcBlanks   *b, *freeme = 0;
     
     b = config->blanks;
     if (!b)
     {
-       b = FcBlanksCreate ();
+       freeme = b = FcBlanksCreate ();
        if (!b)
            return FcFalse;
     }
     if (!FcBlanksAdd (b, blank))
+    {
+        if (freeme)
+            FcBlanksDestroy (freeme);
        return FcFalse;
+    }
     config->blanks = b;
     return FcTrue;
 }
@@ -814,6 +824,7 @@ FcConfigEvaluate (FcPattern *p, FcExpr *e)
     FcValue    v, vl, vr;
     FcResult   r;
     FcMatrix   *m;
+    FcChar8     *str;
     
     switch (e->op) {
     case FcOpInteger:
@@ -944,7 +955,9 @@ FcConfigEvaluate (FcPattern *p, FcExpr *e)
                switch (e->op) {
                case FcOpPlus:
                    v.type = FcTypeString;
-                   v.u.s = FcStrStaticName (FcStrPlus (vl.u.s, vr.u.s));
+                   str = FcStrPlus (vl.u.s, vr.u.s);
+                   v.u.s = FcStrStaticName (str);
+                   FcStrFree (str);
                         
                    if (!v.u.s)
                        v.type = FcTypeVoid;
@@ -1425,7 +1438,8 @@ FcConfigSubstituteWithPat (FcConfig    *config,
                    /*
                     * Delete the marked value
                     */
-                   FcConfigDel (&st[i].elt->values, thisValue);
+                    if (thisValue)
+                       FcConfigDel (&st[i].elt->values, thisValue);
                    /*
                     * Adjust any pointers into the value list to ensure
                     * future edits occur at the same place
@@ -1480,6 +1494,7 @@ FcConfigSubstituteWithPat (FcConfig    *config,
                FcConfigPatternAdd (p, e->field, l, FcTrue);
                break;
            default:
+                FcValueListDestroy (FcValueListPtrCreateDynamic(l));
                break;
            }
        }
@@ -1797,6 +1812,7 @@ FcConfigAppFontAddFile (FcConfig    *config,
        }
        FcStrListDone (sublist);
     }
+    FcStrSetDestroy (subdirs);
     return FcTrue;
 }
 
@@ -1844,6 +1860,7 @@ FcConfigAppFontAddDir (FcConfig       *config,
        }
        FcStrListDone (sublist);
     }
+    FcStrSetDestroy (subdirs);
     return FcTrue;
 }