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...
This commit is contained in:
Patrick Lam 2005-09-01 06:14:46 +00:00
parent 5e678e9459
commit 2304e38f9b
5 changed files with 21 additions and 29 deletions

View File

@ -203,7 +203,7 @@ scanDirs (FcStrList *list, FcConfig *config, char *program, FcBool force, FcBool
printf ("caching, %d fonts, %d dirs\n", printf ("caching, %d fonts, %d dirs\n",
set->nfont, nsubdirs (subdirs)); set->nfont, nsubdirs (subdirs));
if (!FcDirSave (set, dir)) if (!FcDirSave (set, subdirs, dir))
{ {
fprintf (stderr, "Can't save cache in \"%s\"\n", dir); fprintf (stderr, "Can't save cache in \"%s\"\n", dir);
ret++; ret++;

View File

@ -447,7 +447,7 @@ FcDirScan (FcFontSet *set,
FcBool force); FcBool force);
FcBool FcBool
FcDirSave (FcFontSet *set, const FcChar8 *dir); FcDirSave (FcFontSet *set, FcStrSet *dirs, const FcChar8 *dir);
/* fcfreetype.c */ /* fcfreetype.c */
FcPattern * FcPattern *

View File

@ -46,7 +46,7 @@ static FcBool
FcDirCacheConsume (int fd, FcFontSet *set); FcDirCacheConsume (int fd, FcFontSet *set);
static FcBool static FcBool
FcDirCacheRead (FcFontSet * set, const FcChar8 *dir); FcDirCacheRead (FcFontSet * set, FcStrSet * dirs, const FcChar8 *dir);
static int static int
FcCacheNextOffset(off_t w); FcCacheNextOffset(off_t w);
@ -543,27 +543,11 @@ FcCacheReadDirs (FcConfig * config, FcGlobalCache * cache,
free (file); free (file);
continue; continue;
} }
d = opendir ((char *) dir); if (!FcDirCacheValid (dir) || !FcDirCacheRead (set, subdirs, 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 (FcDebug () & FC_DBG_FONTSET) if (FcDebug () & FC_DBG_FONTSET)
printf ("scan dir %s\n", dir); printf ("scan dir %s\n", dir);
FcDirScanConfig (set, subdirs, cache, FcDirScanConfig (set, subdirs, cache,
config->blanks, dir, FcFalse, config); config->blanks, dir, FcFalse, config);
} }
@ -602,13 +586,14 @@ FcCacheRead (FcConfig *config, FcGlobalCache * cache)
/* read serialized state from the cache file */ /* read serialized state from the cache file */
static FcBool 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); FcChar8 *cache_file = FcStrPlus (dir, (FcChar8 *) "/" FC_DIR_CACHE_FILE);
int fd; int fd;
char * current_arch_machine_name; char * current_arch_machine_name;
char candidate_arch_machine_name[9+MACHINE_SIGNATURE_SIZE]; char candidate_arch_machine_name[9+MACHINE_SIGNATURE_SIZE];
off_t current_arch_start = 0; off_t current_arch_start = 0;
FcChar8 subdirName[FC_MAX_FILE_LEN + 1 + 12 + 1];
if (!cache_file) if (!cache_file)
goto bail; goto bail;
@ -627,6 +612,9 @@ FcDirCacheRead (FcFontSet * set, const FcChar8 *dir)
sizeof (candidate_arch_machine_name)) == 0) sizeof (candidate_arch_machine_name)) == 0)
goto bail1; goto bail1;
while (strlen(FcCacheReadString (fd, subdirName, sizeof (subdirName))) > 0)
FcStrSetAdd (dirs, subdirName);
if (!FcDirCacheConsume (fd, set)) if (!FcDirCacheConsume (fd, set))
goto bail1; goto bail1;
@ -635,7 +623,7 @@ FcDirCacheRead (FcFontSet * set, const FcChar8 *dir)
return FcTrue; return FcTrue;
bail1: bail1:
close(fd); close (fd);
bail: bail:
free (cache_file); free (cache_file);
return FcFalse; return FcFalse;
@ -710,10 +698,10 @@ FcDirCacheProduce (FcFontSet *set, FcCache *metadata)
/* write serialized state to the cache file */ /* write serialized state to the cache file */
FcBool 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); FcChar8 *cache_file = FcStrPlus (dir, (FcChar8 *) "/" FC_DIR_CACHE_FILE);
int fd; int fd, i;
FcCache metadata; FcCache metadata;
off_t current_arch_start = 0, truncate_to; off_t current_arch_start = 0, truncate_to;
char * current_arch_machine_name, * header; char * current_arch_machine_name, * header;
@ -763,6 +751,10 @@ FcDirCacheWrite (FcFontSet *set, const FcChar8 *dir)
if (!FcCacheWriteString (fd, header)) if (!FcCacheWriteString (fd, header))
goto bail1; goto bail1;
for (i = 0; i < dirs->size; i++)
FcCacheWriteString (fd, dirs->strs[i]);
FcCacheWriteString (fd, "");
write (fd, &metadata, sizeof(FcCache)); write (fd, &metadata, sizeof(FcCache));
lseek (fd, FcCacheNextOffset (lseek(fd, 0, SEEK_END)), SEEK_SET); lseek (fd, FcCacheNextOffset (lseek(fd, 0, SEEK_END)), SEEK_SET);
write (fd, current_dir_block, metadata.count); write (fd, current_dir_block, metadata.count);

View File

@ -212,7 +212,7 @@ FcDirScan (FcFontSet *set,
} }
FcBool FcBool
FcDirSave (FcFontSet *set, const FcChar8 *dir) FcDirSave (FcFontSet *set, FcStrSet * dirs, const FcChar8 *dir)
{ {
return FcDirCacheWrite (set, dir); return FcDirCacheWrite (set, dirs, dir);
} }

View File

@ -442,7 +442,7 @@ FcFontSet *
FcCacheRead (FcConfig *config, FcGlobalCache * cache); FcCacheRead (FcConfig *config, FcGlobalCache * cache);
FcBool FcBool
FcDirCacheWrite (FcFontSet *set, const FcChar8 *dir); FcDirCacheWrite (FcFontSet *set, FcStrSet * dirs, const FcChar8 *dir);
int int
FcCacheBankToIndex (int bank); FcCacheBankToIndex (int bank);