]> git.wh0rd.org - fontconfig.git/blobdiff - src/fccharset.c
Added new FcFini function for cleaning up all memory. Fixed a few memory
[fontconfig.git] / src / fccharset.c
index d87a720a5f4b31efd6bfd81efc503145377599f1..a1c8f890fbb480076ed26c44434e5341f1eb5f3d 100644 (file)
@@ -845,6 +845,8 @@ struct _FcCharLeafEnt {
 };
 
 #define FC_CHAR_LEAF_BLOCK     (4096 / sizeof (FcCharLeafEnt))
+static FcCharLeafEnt **FcCharLeafBlocks;
+static int FcCharLeafBlockCount;
 
 static FcCharLeafEnt *
 FcCharLeafEntCreate (void)
@@ -854,7 +856,14 @@ FcCharLeafEntCreate (void)
 
     if (!remain)
     {
-       block = malloc (FC_CHAR_LEAF_BLOCK * sizeof (FcCharLeafEnt));
+       FcCharLeafEnt **newBlocks;
+
+       FcCharLeafBlockCount++;
+       newBlocks = realloc (FcCharLeafBlocks, FcCharLeafBlockCount * sizeof (FcCharLeafEnt *));
+       if (!newBlocks)
+           return 0;
+       FcCharLeafBlocks = newBlocks;
+       block = FcCharLeafBlocks[FcCharLeafBlockCount-1] = malloc (FC_CHAR_LEAF_BLOCK * sizeof (FcCharLeafEnt));
        if (!block)
            return 0;
        FcMemAlloc (FC_MEM_CHARLEAF, FC_CHAR_LEAF_BLOCK * sizeof (FcCharLeafEnt));
@@ -880,12 +889,13 @@ FcCharLeafHash (FcCharLeaf *leaf)
 static int     FcCharLeafTotal;
 static int     FcCharLeafUsed;
 
+static FcCharLeafEnt   *FcCharLeafHashTable[FC_CHAR_LEAF_HASH_SIZE];
+
 static FcCharLeaf *
 FcCharSetFreezeLeaf (FcCharLeaf *leaf)
 {
-    static FcCharLeafEnt       *hashTable[FC_CHAR_LEAF_HASH_SIZE];
     FcChar32                   hash = FcCharLeafHash (leaf);
-    FcCharLeafEnt              **bucket = &hashTable[hash % FC_CHAR_LEAF_HASH_SIZE];
+    FcCharLeafEnt              **bucket = &FcCharLeafHashTable[hash % FC_CHAR_LEAF_HASH_SIZE];
     FcCharLeafEnt              *ent;
     
     FcCharLeafTotal++;
@@ -906,6 +916,25 @@ FcCharSetFreezeLeaf (FcCharLeaf *leaf)
     return &ent->leaf;
 }
 
+static void
+FcCharSetThawAllLeaf (void)
+{
+    int i;
+
+    for (i = 0; i < FC_CHAR_LEAF_HASH_SIZE; i++)
+       FcCharLeafHashTable[i] = 0;
+
+    FcCharLeafTotal = 0;
+    FcCharLeafUsed = 0;
+
+    for (i = 0; i < FcCharLeafBlockCount; i++)
+       free (FcCharLeafBlocks[i]);
+
+    free (FcCharLeafBlocks);
+    FcCharLeafBlocks = 0;
+    FcCharLeafBlockCount = 0;
+}
+
 typedef struct _FcCharSetEnt FcCharSetEnt;
 
 struct _FcCharSetEnt {
@@ -937,12 +966,13 @@ static int        FcCharSetTotal;
 static int     FcCharSetUsed;
 static int     FcCharSetTotalEnts, FcCharSetUsedEnts;
 
+static FcCharSetEnt    *FcCharSetHashTable[FC_CHAR_SET_HASH_SIZE];
+
 static FcCharSet *
 FcCharSetFreezeBase (FcCharSet *fcs)
 {
-    static FcCharSetEnt        *hashTable[FC_CHAR_SET_HASH_SIZE];
     FcChar32           hash = FcCharSetHash (fcs);
-    FcCharSetEnt       **bucket = &hashTable[hash % FC_CHAR_SET_HASH_SIZE];
+    FcCharSetEnt       **bucket = &FcCharSetHashTable[hash % FC_CHAR_SET_HASH_SIZE];
     FcCharSetEnt       *ent;
     int                        size;
 
@@ -992,6 +1022,30 @@ FcCharSetFreezeBase (FcCharSet *fcs)
     return &ent->set;
 }
 
+void
+FcCharSetThawAll (void)
+{
+    int i;
+    FcCharSetEnt       *ent, *next;
+
+    for (i = 0; i < FC_CHAR_SET_HASH_SIZE; i++)
+    {
+       for (ent = FcCharSetHashTable[i]; ent; ent = next)
+       {
+           next = ent->next;
+           free (ent);
+       }
+       FcCharSetHashTable[i] = 0;
+    }
+
+    FcCharSetTotal = 0;
+    FcCharSetTotalEnts = 0;
+    FcCharSetUsed = 0;
+    FcCharSetUsedEnts = 0;
+
+    FcCharSetThawAllLeaf ();
+}
+
 FcCharSet *
 FcCharSetFreeze (FcCharSet *fcs)
 {