]> git.wh0rd.org - fontconfig.git/commitdiff
[fcxml] Embed 8 static FcPStack objects in FcConfigParse
authorBehdad Esfahbod <behdad@behdad.org>
Thu, 12 Mar 2009 15:58:04 +0000 (11:58 -0400)
committerBehdad Esfahbod <behdad@behdad.org>
Thu, 12 Mar 2009 17:14:38 +0000 (13:14 -0400)
This reduces the number of mallocs called from FcPStackPush from
over 900 down to zero.

src/fcxml.c

index ccc9c194d4463e6803de95f088a99dfe38a41ec1..e6d16f3d4812b57137ce7be3b3e65b942e4ae155 100644 (file)
@@ -469,6 +469,8 @@ typedef struct _FcConfigParse {
     const FcChar8   *name;
     FcConfig       *config;
     XML_Parser     parser;
+    int             pstack_static_used;
+    FcPStack        pstack_static[8];
 } FcConfigParse;
 
 typedef enum _FcConfigSeverity {
@@ -962,11 +964,18 @@ FcConfigSaveAttr (const XML_Char **attr)
 static FcBool
 FcPStackPush (FcConfigParse *parse, FcElement element, const XML_Char **attr)
 {
-    FcPStack   *new = malloc (sizeof (FcPStack));
+    FcPStack   *new;
+
+    if (parse->pstack_static_used < sizeof (parse->pstack_static) / sizeof (parse->pstack_static[0]))
+       new = &parse->pstack_static[parse->pstack_static_used++];
+    else
+    {
+       new = malloc (sizeof (FcPStack));
+       if (!new)
+           return FcFalse;
+       FcMemAlloc (FC_MEM_PSTACK, sizeof (FcPStack));
+    }
 
-    if (!new)
-       return FcFalse;
-    FcMemAlloc (FC_MEM_PSTACK, sizeof (FcPStack));
     new->prev = parse->pstack;
     new->element = element;
     new->attr = FcConfigSaveAttr (attr);
@@ -994,8 +1003,14 @@ FcPStackPop (FcConfigParse *parse)
        FcMemFree (FC_MEM_ATTR, 1); /* size is to expensive */
        free (old->attr);
     }
-    FcMemFree (FC_MEM_PSTACK, sizeof (FcPStack));
-    free (old);
+
+    if (old == &parse->pstack_static[parse->pstack_static_used - 1])
+       parse->pstack_static_used--;
+    else
+    {
+       FcMemFree (FC_MEM_PSTACK, sizeof (FcPStack));
+       free (old);
+    }
     return FcTrue;
 }
 
@@ -1003,6 +1018,7 @@ static FcBool
 FcConfigInit (FcConfigParse *parse, const FcChar8 *name, FcConfig *config, XML_Parser parser)
 {
     parse->pstack = 0;
+    parse->pstack_static_used = 0;
     parse->vstack = 0;
     parse->error = FcFalse;
     parse->name = name;