[Fontconfig] Re: Structure of cache files

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Josselin Mouette wrote:
> It would indeed solve both problems simultaneously.
> Maybe, for performance, would it be better to
> use /var/cache/fontconfig/$hash.cache files, $hash being generated from
> the original pathname ?

How does the attached patch look?  Is fontconfig supposed to be
responsible for creating /var/cache/fontconfig, or can it rely on the
packager?  Also is hardcoding /var/cache/fontconfig the right thing?

pat
-------------- next part --------------
Index: fontconfig/fontconfig.h
===================================================================
RCS file: /cvs/fontconfig/fontconfig/fontconfig/fontconfig.h,v
retrieving revision 1.69.2.15
diff -u -p -r1.69.2.15 fontconfig.h
--- fontconfig/fontconfig.h	24 Nov 2005 21:40:20 -0000	1.69.2.15
+++ fontconfig/fontconfig.h	7 Dec 2005 04:00:31 -0000
@@ -104,6 +104,8 @@ typedef int		FcBool;
 #define FC_EMBOLDEN	    "embolden"		/* Bool - true if emboldening needed*/
 #define FC_EMBEDDED_BITMAP  "embeddedbitmap"	/* Bool - true to enable embedded bitmaps */
 
+#define FC_VAR_CACHE_DIR	    "/var/cache/fontconfig/"
+#define FC_CACHE_SUFFIX		    ".cache-"FC_CACHE_VERSION
 #define FC_DIR_CACHE_FILE	    "fonts.cache-"FC_CACHE_VERSION
 #define FC_USER_CACHE_FILE	    ".fonts.cache-"FC_CACHE_VERSION
 
Index: src/fccache.c
===================================================================
RCS file: /cvs/fontconfig/fontconfig/src/fccache.c,v
retrieving revision 1.23.4.37
diff -u -p -r1.23.4.37 fccache.c
--- src/fccache.c	29 Nov 2005 14:57:10 -0000	1.23.4.37
+++ src/fccache.c	7 Dec 2005 04:00:31 -0000
@@ -723,6 +723,8 @@ FcBool
 FcDirCacheRead (FcFontSet * set, FcStrSet * dirs, const FcChar8 *dir)
 {
     char *cache_file = (char *)FcStrPlus (dir, (FcChar8 *) "/" FC_DIR_CACHE_FILE);
+    char hash[9];
+    char *cache_hashed;
     int fd;
     char * current_arch_machine_name;
     char candidate_arch_machine_name[9+MACHINE_SIGNATURE_SIZE];
@@ -732,10 +734,17 @@ FcDirCacheRead (FcFontSet * set, FcStrSe
     if (!cache_file)
         goto bail;
 
+    sprintf (hash, "%8x", FcStringHash ((FcChar8 *)cache_file));
+    cache_hashed = (char *)FcStrPlus ((FcChar8 *)FC_VAR_CACHE_DIR, FcStrPlus ((FcChar8 *)hash, (FcChar8 *)FC_CACHE_SUFFIX));
+
     current_arch_machine_name = FcCacheMachineSignature();
-    fd = open(cache_file, O_RDONLY);
+    fd = open(cache_hashed, O_RDONLY);
     if (fd == -1)
-        goto bail;
+    {
+	fd = open (cache_file, O_RDONLY);
+	if (fd == -1)
+	    goto bail;
+    }
 
     current_arch_start = FcCacheSkipToArch(fd, current_arch_machine_name);
     if (current_arch_start < 0)
@@ -845,6 +854,8 @@ FcBool
 FcDirCacheWrite (FcFontSet *set, FcStrSet *dirs, const FcChar8 *dir)
 {
     FcChar8         *cache_file = FcStrPlus (dir, (FcChar8 *) "/" FC_DIR_CACHE_FILE);
+    char 	    hash[9];
+    FcChar8 	    *cache_hashed;
     int 	    fd, fd_orig, i, dirs_count;
     FcAtomic 	    *atomic;
     FcCache 	    metadata;
@@ -856,6 +867,9 @@ FcDirCacheWrite (FcFontSet *set, FcStrSe
     if (!cache_file)
         goto bail;
 
+    sprintf (hash, "%8x", FcStringHash ((FcChar8 *)cache_file));
+    cache_hashed = FcStrPlus ((FcChar8 *)FC_VAR_CACHE_DIR, FcStrPlus ((FcChar8 *)hash, (FcChar8 *)FC_CACHE_SUFFIX));
+
     current_dir_block = FcDirCacheProduce (set, &metadata);
 
     if (metadata.count && !current_dir_block)
@@ -864,9 +878,13 @@ FcDirCacheWrite (FcFontSet *set, FcStrSe
     if (FcDebug () & FC_DBG_CACHE)
         printf ("FcDirCacheWriteDir cache_file \"%s\"\n", cache_file);
 
-    atomic = FcAtomicCreate (cache_file);
+    atomic = FcAtomicCreate (cache_hashed);
     if (!atomic)
-        goto bail0;
+    {
+	atomic = FcAtomicCreate (cache_file);
+	if (!atomic)
+	    goto bail0;
+    }
 
     if (!FcAtomicLock (atomic))
         goto bail1;

[Index of Archives]     [Fedora Fonts]     [Fedora Users]     [Fedora Cloud]     [Kernel]     [Fedora Packaging]     [Fedora Desktop]     [PAM]     [Gimp Graphics Editor]     [Yosemite News]

  Powered by Linux