]> git.wh0rd.org - fontconfig.git/commitdiff
:
authorPatrick Lam <plam@MIT.EDU>
Thu, 1 Sep 2005 06:14:46 +0000 (06:14 +0000)
committerPatrick Lam <plam@MIT.EDU>
Thu, 1 Sep 2005 06:14:46 +0000 (06:14 +0000)
Save subdirectory names in cache files to save time. This completely
    restores the original fontconfig API, BTW. Note that directories
    without fonts don't get a cache file; but then how many files would it
    have in that directory...

fc-cache/fc-cache.c
fontconfig/fontconfig.h
src/fccache.c
src/fcdir.c
src/fcint.h

index fc0c4e511913ca3e90acd3f559281ffc9486d8c8..fed64295b00f2d1106ac3300455ba4e00706311a 100644 (file)
@@ -203,7 +203,7 @@ scanDirs (FcStrList *list, FcConfig *config, char *program, FcBool force, FcBool
                printf ("caching, %d fonts, %d dirs\n", 
                        set->nfont, nsubdirs (subdirs));
 
-           if (!FcDirSave (set, dir))
+           if (!FcDirSave (set, subdirs, dir))
            {
                fprintf (stderr, "Can't save cache in \"%s\"\n", dir);
                ret++;
index 8d0975e4149131fe6ce5b6bef1f4687b0b152b56..312256f879e3321faae2c137f188bc6f4895a9f9 100644 (file)
@@ -447,7 +447,7 @@ FcDirScan (FcFontSet            *set,
           FcBool           force);
 
 FcBool
-FcDirSave (FcFontSet *set, const FcChar8 *dir);
+FcDirSave (FcFontSet *set, FcStrSet *dirs, const FcChar8 *dir);
 
 /* fcfreetype.c */
 FcPattern *
index 6b6b8e36c54614b7aca380ffc1d748a1ca60cad8..efc1cf0342615324b7d70894cea67930494ee9b0 100644 (file)
@@ -46,7 +46,7 @@ static FcBool
 FcDirCacheConsume (int fd, FcFontSet *set);
 
 static FcBool
-FcDirCacheRead (FcFontSet * set, const FcChar8 *dir);
+FcDirCacheRead (FcFontSet * set, FcStrSet * dirs, const FcChar8 *dir);
 
 static int
 FcCacheNextOffset(off_t w);
@@ -543,27 +543,11 @@ FcCacheReadDirs (FcConfig * config, FcGlobalCache * cache,
            free (file);
            continue;
        }
-       d = opendir ((char *) dir);
-       if (!d)
-       {
-           FcStrSetDestroy (subdirs);
-           free (file);
-           continue;
-       }
-       while ((e = readdir (d)))
-       {
-           if (e->d_name[0] != '.' && strlen (e->d_name) < FC_MAX_FILE_LEN)
-           {
-               strcpy ((char *) base, (char *) e->d_name);
-               if (FcFileIsDir (file) && !FcStrSetAdd (subdirs, file))
-                   ret++;
-           }
-       }
-       closedir (d);
-       if (!FcDirCacheValid (dir) || !FcDirCacheRead (set, dir))
+       if (!FcDirCacheValid (dir) || !FcDirCacheRead (set, subdirs, dir))
        {
            if (FcDebug () & FC_DBG_FONTSET)
                printf ("scan dir %s\n", dir);
+
            FcDirScanConfig (set, subdirs, cache, 
                             config->blanks, dir, FcFalse, config);
        }
@@ -602,13 +586,14 @@ FcCacheRead (FcConfig *config, FcGlobalCache * cache)
 
 /* read serialized state from the cache file */
 static FcBool
-FcDirCacheRead (FcFontSet * set, const FcChar8 *dir)
+FcDirCacheRead (FcFontSet * set, FcStrSet * dirs, const FcChar8 *dir)
 {
     FcChar8         *cache_file = FcStrPlus (dir, (FcChar8 *) "/" FC_DIR_CACHE_FILE);
     int fd;
     char * current_arch_machine_name;
     char candidate_arch_machine_name[9+MACHINE_SIGNATURE_SIZE];
     off_t current_arch_start = 0;
+    FcChar8        subdirName[FC_MAX_FILE_LEN + 1 + 12 + 1];
 
     if (!cache_file)
         goto bail;
@@ -626,7 +611,10 @@ FcDirCacheRead (FcFontSet * set, const FcChar8 *dir)
     if (FcCacheReadString (fd, candidate_arch_machine_name, 
                           sizeof (candidate_arch_machine_name)) == 0)
        goto bail1;
-    
+
+    while (strlen(FcCacheReadString (fd, subdirName, sizeof (subdirName))) > 0)
+        FcStrSetAdd (dirs, subdirName);
+
     if (!FcDirCacheConsume (fd, set))
        goto bail1;
        
@@ -635,7 +623,7 @@ FcDirCacheRead (FcFontSet * set, const FcChar8 *dir)
     return FcTrue;
 
  bail1:
-    close(fd);
+    close (fd);
  bail:
     free (cache_file);
     return FcFalse;
@@ -710,10 +698,10 @@ FcDirCacheProduce (FcFontSet *set, FcCache *metadata)
 
 /* write serialized state to the cache file */
 FcBool
-FcDirCacheWrite (FcFontSet *set, const FcChar8 *dir)
+FcDirCacheWrite (FcFontSet *set, FcStrSet *dirs, const FcChar8 *dir)
 {
     FcChar8         *cache_file = FcStrPlus (dir, (FcChar8 *) "/" FC_DIR_CACHE_FILE);
-    int fd;
+    int fd, i;
     FcCache metadata;
     off_t current_arch_start = 0, truncate_to;
     char * current_arch_machine_name, * header;
@@ -763,6 +751,10 @@ FcDirCacheWrite (FcFontSet *set, const FcChar8 *dir)
     if (!FcCacheWriteString (fd, header))
        goto bail1;
 
+    for (i = 0; i < dirs->size; i++)
+        FcCacheWriteString (fd, dirs->strs[i]);
+    FcCacheWriteString (fd, "");
+
     write (fd, &metadata, sizeof(FcCache));
     lseek (fd, FcCacheNextOffset (lseek(fd, 0, SEEK_END)), SEEK_SET);
     write (fd, current_dir_block, metadata.count);
index 4ee84def97190cddd50c9ad34ceedb0f6661cd00..6b7d638b46e5995bf8ac6203030b031072204bac 100644 (file)
@@ -212,7 +212,7 @@ FcDirScan (FcFontSet            *set,
 }
 
 FcBool
-FcDirSave (FcFontSet *set, const FcChar8 *dir)
+FcDirSave (FcFontSet *set, FcStrSet * dirs, const FcChar8 *dir)
 {
-    return FcDirCacheWrite (set, dir);
+    return FcDirCacheWrite (set, dirs, dir);
 }
index 8a68570a1900dc4b2cec1ce2f5639823d51271d7..b69274c15ee2a18b6aedea8a8e92d52d4cf1889e 100644 (file)
@@ -442,7 +442,7 @@ FcFontSet *
 FcCacheRead (FcConfig *config, FcGlobalCache * cache);
 
 FcBool
-FcDirCacheWrite (FcFontSet *set, const FcChar8 *dir);
+FcDirCacheWrite (FcFontSet *set, FcStrSet * dirs, const FcChar8 *dir);
 
 int
 FcCacheBankToIndex (int bank);