]> git.wh0rd.org - fontconfig.git/blobdiff - src/fccharset.c
Fix up fc-cache and fc-cat for no global cache changes.
[fontconfig.git] / src / fccharset.c
index e152a5a00684b48cdc8fcadadd31b8012b64b35a..e0a09612859857e4bd557d3ebff890b62f2d8c0f 100644 (file)
@@ -22,8 +22,8 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-#include <stdlib.h>
 #include "fcint.h"
+#include <stdlib.h>
 
 /* #define CHECK */
 
@@ -38,9 +38,9 @@ static int charset_leaf_ptr, charset_leaf_count;
 static int ** leaf_idx = 0;
 static int charset_leaf_idx_ptr, charset_leaf_idx_count;
 
-extern const FcChar16 *langBankNumbers;
-extern const FcCharLeaf        *langBankLeaves;
-extern const int *langBankLeafIdx;
+extern const FcChar16 langBankNumbers[];
+extern const FcCharLeaf        langBankLeaves[];
+extern const int langBankLeafIdx[];
 
 static FcBool
 FcCharSetEnsureBank (int bi);
@@ -48,12 +48,12 @@ FcCharSetEnsureBank (int bi);
 void
 FcLangCharSetPopulate (void)
 {
-    int bi = FcCacheBankToIndex (FC_BANK_LANGS);
+    int bi = FcCacheBankToIndexMTF (FC_BANK_LANGS);
     FcCharSetEnsureBank (bi);
     charsets[bi] = 0;
-    numbers[bi] = (FcChar16 *)&langBankNumbers;
-    leaves[bi] = (FcCharLeaf *)&langBankLeaves;
-    leaf_idx[bi] = (int *)&langBankLeafIdx;
+    numbers[bi] = (FcChar16 *)langBankNumbers;
+    leaves[bi] = (FcCharLeaf *)langBankLeaves;
+    leaf_idx[bi] = (int *)langBankLeafIdx;
 }
 
 FcCharSet *
@@ -168,6 +168,7 @@ FcCharSetPutLeaf (FcCharSet *fcs,
        return FcFalse;
     if (fcs->bank != FC_BANK_DYNAMIC)
     {
+        /* convert to dynamic */
        int i;
 
        leaves = malloc ((fcs->num + 1) * sizeof (FcCharLeaf *));
@@ -176,13 +177,20 @@ FcCharSetPutLeaf (FcCharSet       *fcs,
        FcMemAlloc (FC_MEM_CHARSET, (fcs->num + 1) * sizeof (FcCharLeaf *));
        numbers = malloc ((fcs->num + 1) * sizeof (FcChar16));
        if (!numbers)
+        {
+           free (leaves);
            return FcFalse;
+        }
        FcMemAlloc (FC_MEM_CHARSET, (fcs->num + 1) * sizeof (FcChar16));
 
        for (i = 0; i < fcs->num; i++)
            leaves[i] = FcCharSetGetLeaf(fcs, i);
        memcpy (numbers, FcCharSetGetNumbers(fcs), 
                fcs->num * sizeof (FcChar16));
+
+       fcs->bank = FC_BANK_DYNAMIC;
+       fcs->u.dyn.leaves = leaves;
+       fcs->u.dyn.numbers = numbers;
     }
     else
     {
@@ -263,7 +271,8 @@ FcCharSetInsertLeaf (FcCharSet *fcs, FcChar32 ucs4, FcCharLeaf *leaf)
        }
        else
        {
-           leaves[fcs->bank][leaf_idx[fcs->bank][fcs->u.stat.leafidx_offset]+pos] = *leaf;
+           int bi = FcCacheBankToIndex(fcs->bank);
+           leaves[bi][leaf_idx[fcs->bank][fcs->u.stat.leafidx_offset]+pos] = *leaf;
        }
        return FcTrue;
     }
@@ -619,7 +628,7 @@ FcCharSetSubtractCount (const FcCharSet *a, const FcCharSet *b)
            int         i = 256/32;
            if (ai.ucs4 == bi.ucs4)
            {
-               FcChar32        *bm = bi.leaf->map;;
+               FcChar32        *bm = bi.leaf->map;
                while (i--)
                    count += FcCharSetPopCount (*am++ & ~*bm++);
            }
@@ -1322,11 +1331,11 @@ FcCharSetNeededBytes (const FcCharSet *c)
 {
     /* yes, there's redundancy */
     charset_count++;
-    charset_leaf_idx_count++;
+    charset_leaf_idx_count += c->num;
     charset_leaf_count += c->num;
     charset_numbers_count += c->num;
     return sizeof (FcCharSet) + 
-       sizeof (int) +                  /* leaf_idx */
+       sizeof (int) * c->num +         /* leaf_idx */
        sizeof (FcCharLeaf) * c->num +  /* leaf */
        sizeof (FcChar16) * c->num;     /* number */
 }
@@ -1334,8 +1343,8 @@ FcCharSetNeededBytes (const FcCharSet *c)
 int
 FcCharSetNeededBytesAlign (void)
 {
-    return __alignof__ (FcCharSet) + __alignof__ (int) + 
-       __alignof__ (FcCharLeaf) + __alignof__ (FcChar16);
+    return fc_alignof (FcCharSet) + fc_alignof (int) + 
+       fc_alignof (FcCharLeaf) + fc_alignof (FcChar16);
 }
 
 static FcBool
@@ -1420,9 +1429,9 @@ FcCharSetSerialize(int bank, FcCharSet *c)
 
     charsets[bi][charset_ptr++] = new;
 
-    leaf_idx[bi][charset_leaf_idx_ptr++] = charset_leaf_ptr;
     for (i = 0; i < c->num; i++)
     {
+       leaf_idx[bi][charset_leaf_idx_ptr++] = charset_leaf_ptr;
        memcpy (&leaves[bi][charset_leaf_ptr++], 
                c->u.dyn.leaves[i], sizeof(FcCharLeaf));
        numbers[bi][charset_numbers_ptr++] = c->u.dyn.numbers[i];
@@ -1432,28 +1441,28 @@ FcCharSetSerialize(int bank, FcCharSet *c)
 }
 
 void *
-FcCharSetUnserialize (FcCache metadata, void *block_ptr)
+FcCharSetUnserialize (FcCache *metadata, void *block_ptr)
 {
-    int bi = FcCacheBankToIndex(metadata.bank);
+    int bi = FcCacheBankToIndex(metadata->bank);
     if (!FcCharSetEnsureBank(bi))
        return 0;
 
     block_ptr = ALIGN (block_ptr, FcCharSet);
     charsets[bi] = (FcCharSet *)block_ptr;
     block_ptr = (void *)((char *)block_ptr + 
-                    (sizeof (FcCharSet) * metadata.charset_count));
+                    (sizeof (FcCharSet) * metadata->charset_count));
     block_ptr = ALIGN (block_ptr, FcChar16);
     numbers[bi] = (FcChar16 *)block_ptr;
     block_ptr = (void *)((char *)block_ptr + 
-                    (sizeof(FcChar16) * metadata.charset_numbers_count));
+                    (sizeof(FcChar16) * metadata->charset_numbers_count));
     block_ptr = ALIGN (block_ptr, FcCharLeaf);
     leaves[bi] = (FcCharLeaf *)block_ptr;
     block_ptr = (void *)((char *)block_ptr +
-                    (sizeof(FcCharLeaf) * metadata.charset_leaf_count));
+                    (sizeof(FcCharLeaf) * metadata->charset_leaf_count));
     block_ptr = ALIGN (block_ptr, int);
     leaf_idx[bi] = (int *)block_ptr;
     block_ptr = (void *)((char *)block_ptr +
-                    (sizeof(int) * metadata.charset_leaf_idx_count));
+                    (sizeof(int) * metadata->charset_leaf_idx_count));
 
     return block_ptr;
 }
@@ -1466,7 +1475,7 @@ FcCharSetGetLeaf(const FcCharSet *c, int i)
        return c->u.dyn.leaves[i];
     bi = FcCacheBankToIndex(c->bank);
 
-    return &leaves[bi][leaf_idx[bi][c->u.stat.leafidx_offset]+i];
+    return &leaves[bi][leaf_idx[bi][c->u.stat.leafidx_offset+i]];
 }
 
 FcChar16 *