From 2304e38f9bc070ccd54f80187c208d93b6eeb373 Mon Sep 17 00:00:00 2001 From: Patrick Lam Date: Thu, 1 Sep 2005 06:14:46 +0000 Subject: [PATCH] : 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 | 2 +- fontconfig/fontconfig.h | 2 +- src/fccache.c | 40 ++++++++++++++++------------------------ src/fcdir.c | 4 ++-- src/fcint.h | 2 +- 5 files changed, 21 insertions(+), 29 deletions(-) diff --git a/fc-cache/fc-cache.c b/fc-cache/fc-cache.c index fc0c4e5..fed6429 100644 --- a/fc-cache/fc-cache.c +++ b/fc-cache/fc-cache.c @@ -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++; diff --git a/fontconfig/fontconfig.h b/fontconfig/fontconfig.h index 8d0975e..312256f 100644 --- a/fontconfig/fontconfig.h +++ b/fontconfig/fontconfig.h @@ -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 * diff --git a/src/fccache.c b/src/fccache.c index 6b6b8e3..efc1cf0 100644 --- a/src/fccache.c +++ b/src/fccache.c @@ -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); diff --git a/src/fcdir.c b/src/fcdir.c index 4ee84de..6b7d638 100644 --- a/src/fcdir.c +++ b/src/fcdir.c @@ -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); } diff --git a/src/fcint.h b/src/fcint.h index 8a68570..b69274c 100644 --- a/src/fcint.h +++ b/src/fcint.h @@ -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); -- 2.39.2