diff options
author | Akira TAGOH <akira@tagoh.org> | 2017-10-03 13:08:54 +0900 |
---|---|---|
committer | Akira TAGOH <akira@tagoh.org> | 2017-11-20 17:37:22 +0530 |
commit | b01bf646f110cacfaeb5fe097475d3582fa6cd33 (patch) | |
tree | e8932d3d6af31d6276c49fdbf7facab2e54e4f10 /src/fccache.c | |
parent | d7133f4ed7071c6ac257e8d4de0e438e22ca0254 (diff) | |
download | fontconfig-b01bf646f110cacfaeb5fe097475d3582fa6cd33.tar.gz |
Destroy the alias and UUID tables when all of caches is unloaded
When a cache contains no fonts, it will be unloaded immediately.
Previously the certain alias and UUID entries will be purged at that time though,
this doesn't work when the targeted directory has sub-directories.
To avoid the unnecessary cache creation with the md5-based naming, try to keep them
as far as possible.
Although this way seems not perfectly working if the first directory to look up is like that
Diffstat (limited to 'src/fccache.c')
-rw-r--r-- | src/fccache.c | 63 |
1 files changed, 27 insertions, 36 deletions
diff --git a/src/fccache.c b/src/fccache.c index 6f7722d..067077e 100644 --- a/src/fccache.c +++ b/src/fccache.c @@ -88,28 +88,24 @@ FcCacheUuidAdd (FcUuidHashTable *table, return FcTrue; } -static FcBool -FcCacheUuidRemove (FcUuidHashTable *table, - const FcChar8 *file) +static void +FcCacheUuidDestroy (FcUuidHashTable *table) { - FcUuidBucket **prev, *bucket; - FcChar32 hash = FcStrHashIgnoreCase (file); + int i; - for (prev = &table->buckets[hash % FC_UUID_HASH_SIZE]; - (bucket = *prev); ) + for (i = 0; i < FC_UUID_HASH_SIZE; i++) { - if (FcStrCmp (bucket->file, file) == 0) + FcUuidBucket *bucket = table->buckets[i], *prev; + + while (bucket) { - *prev = bucket->next; FcStrFree (bucket->file); - free (bucket); - - return FcTrue; + prev = bucket; + bucket = bucket->next; + free (prev); } - else - prev = &(bucket->next); + table->buckets[i] = NULL; } - return FcFalse; } static FcBool @@ -269,29 +265,25 @@ FcCacheAliasAdd (FcAliasHashTable *table, return FcTrue; } -static FcBool -FcCacheAliasRemove (FcAliasHashTable *table, - const FcChar8 *orig) +static void +FcCacheAliasDestroy (FcAliasHashTable *table) { - FcAliasBucket **prev, *bucket; - FcChar32 hash = FcStrHashIgnoreCase (orig); + int i; - for (prev = &table->buckets[hash % FC_ALIAS_HASH_SIZE]; - (bucket = *prev); ) + for (i = 0; i < FC_ALIAS_HASH_SIZE; i++) { - if (FcStrCmp (bucket->orig, orig) == 0) + FcAliasBucket *bucket = table->buckets[i], *prev; + + while (bucket) { - *prev = bucket->next; + prev = bucket; FcStrFree (bucket->orig); FcStrFree (bucket->alias); - free (bucket); - - return FcTrue; + bucket = bucket->next; + free (prev); } - else - prev = &(bucket->next); + table->buckets[i] = NULL; } - return FcFalse; } static FcBool @@ -841,13 +833,12 @@ FcCacheObjectDereference (void *object) { if (FcRefDec (&skip->ref) == 1) { - const FcChar8 *d = FcDirCacheFindAliasPath (FcCacheDir (skip->cache)); - - FcCacheUuidRemove (&uuid_table, FcCacheDir (skip->cache)); - if (d) - FcCacheUuidRemove (&uuid_table, d); - FcCacheAliasRemove (&alias_table, FcCacheDir (skip->cache)); FcDirCacheDisposeUnlocked (skip->cache); + if (fcCacheMaxLevel == 0) + { + FcCacheUuidDestroy (&uuid_table); + FcCacheAliasDestroy (&alias_table); + } } } unlock_cache (); |