Takashi IWAI <tiwai@xxxxxxx> made a patch to reduce the amount of stat () calls in the case when one is absolutely sure that all cache files are OK and up-to-date and can be trusted. For details see http://bugzilla.novell.com/show_bug.cgi?id=148361 from comment #20 on. There are problems if the cache files are not correct of course, but nevertheless Takashi's patch might be a useful performance hack if a user is able to make sure that all cache files can be trusted.
--- src/fcint.h-dist 2006-02-08 20:57:29.000000000 +0100 +++ src/fcint.h 2006-02-08 20:58:06.000000000 +0100 @@ -414,6 +414,10 @@ struct _FcConfig { */ time_t rescanTime; /* last time information was scanned */ int rescanInterval; /* interval between scans */ + /* + * Validate cache files at each open? + */ + FcBool validateCache; }; extern FcConfig *_fcConfig; --- src/fccfg.c-dist 2006-02-08 21:07:16.000000000 +0100 +++ src/fccfg.c 2006-02-08 21:07:38.000000000 +0100 @@ -117,6 +117,7 @@ FcConfigCreate (void) config->rescanTime = time(0); config->rescanInterval = 30; + config->validateCache = 1; return config; --- src/fcxml.c-dist 2006-02-08 20:55:00.000000000 +0100 +++ src/fcxml.c 2006-02-08 20:57:18.000000000 +0100 @@ -293,6 +293,7 @@ typedef enum _FcElement { FcElementBlank, FcElementRescan, + FcElementValidatecache, FcElementPrefer, FcElementAccept, @@ -353,6 +354,7 @@ static struct { { "blank", FcElementBlank }, { "rescan", FcElementRescan }, + { "validatecache", FcElementValidatecache }, { "prefer", FcElementPrefer }, { "accept", FcElementAccept }, @@ -1099,6 +1101,20 @@ FcParseRescan (FcConfigParse *parse) } static void +FcParseValidatecache (FcConfigParse *parse) +{ + int n = FcVStackElements (parse); + while (n-- > 0) + { + FcVStack *v = FcVStackFetch (parse, n); + if (v->tag != FcVStackBool) + FcConfigMessage (parse, FcSevereWarning, "non-boolean validatecache"); + else + parse->config->validateCache = v->u.bool; + } +} + +static void FcParseInt (FcConfigParse *parse) { FcChar8 *s, *end; @@ -2086,6 +2102,9 @@ FcEndElement(void *userData, const XML_C case FcElementRescan: FcParseRescan (parse); break; + case FcElementValidatecache: + FcParseValidatecache (parse); + break; case FcElementPrefer: FcParseFamilies (parse, FcVStackPrefer); --- src/fccache.c-dist 2006-02-08 20:58:21.000000000 +0100 +++ src/fccache.c 2006-02-08 21:38:23.000000000 +0100 @@ -221,9 +221,10 @@ FcGlobalCacheLoad (FcGlobalCache *cac /* Directory must be older than the global cache file; also cache must be newer than the config file. */ - if (stat ((char *) name_buf, &dir_stat) < 0 || - dir_stat.st_mtime > cache_stat.st_mtime || - (config_time.set && cache_stat.st_mtime < config_time.time)) + if (config->validateCache && + (stat ((char *) name_buf, &dir_stat) < 0 || + dir_stat.st_mtime > cache_stat.st_mtime || + (config_time.set && cache_stat.st_mtime < config_time.time))) { FcCache md; off_t off; @@ -876,6 +877,27 @@ FcCacheReadDirs (FcConfig * config, FcGl continue; } + if (! config->validateCache) + { + /* We trust cache files -- if not found, just ignore that directory + */ + if ((cache && FcGlobalCacheReadDir (set, subdirs, cache, (char *)dir, + config)) || + FcDirCacheRead (set, subdirs, dir, config)) + { + sublist = FcStrListCreate (subdirs); + FcStrSetDestroy (subdirs); + if (!sublist) + { + fprintf (stderr, "Can't create subdir list in \"%s\"\n", dir); + ret++; + continue; + } + ret += FcCacheReadDirs (config, cache, sublist, set, processed_dirs); + } + continue; + } + if (access ((char *) dir, X_OK) < 0) { switch (errno) { --- fonts.dtd-dist 2006-02-08 21:12:11.000000000 +0100 +++ fonts.dtd 2006-02-08 21:14:00.000000000 +0100 @@ -40,7 +40,7 @@ <!-- Global library configuration data --> -<!ELEMENT config (blank|rescan)*> +<!ELEMENT config (blank|rescan|validatecache)*> <!-- Specify the set of Unicode encoding values which @@ -82,6 +82,13 @@ <!ELEMENT rescan (int)> <!-- + Validate cache files dynamically + If this is set to false, fontconfig trusts cache files and never + checks the timestamp or changes of contents. + --> +<!ELEMENT validatecache (bool)> + +<!-- Edit list of available fonts at startup/reload time --> <!ELEMENT selectfont (rejectfont | acceptfont)* >
-- Mike FABIAN <mfabian@xxxxxxx> http://www.suse.de/~mfabian 睡眠不足はいい仕事の敵だ。
_______________________________________________ Fontconfig mailing list Fontconfig@xxxxxxxxxxxxxxxxxxxxx http://lists.freedesktop.org/mailman/listinfo/fontconfig