[fcxml] Embed 8 static FcPStack objects in FcConfigParse

This reduces the number of mallocs called from FcPStackPush from
over 900 down to zero.
This commit is contained in:
Behdad Esfahbod 2009-03-12 11:58:04 -04:00
parent 532d8a1dbc
commit 1d7b47da9d
1 changed files with 22 additions and 6 deletions

View 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;