[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:
parent
532d8a1dbc
commit
1d7b47da9d
28
src/fcxml.c
28
src/fcxml.c
|
@ -469,6 +469,8 @@ typedef struct _FcConfigParse {
|
||||||
const FcChar8 *name;
|
const FcChar8 *name;
|
||||||
FcConfig *config;
|
FcConfig *config;
|
||||||
XML_Parser parser;
|
XML_Parser parser;
|
||||||
|
int pstack_static_used;
|
||||||
|
FcPStack pstack_static[8];
|
||||||
} FcConfigParse;
|
} FcConfigParse;
|
||||||
|
|
||||||
typedef enum _FcConfigSeverity {
|
typedef enum _FcConfigSeverity {
|
||||||
|
@ -962,11 +964,18 @@ FcConfigSaveAttr (const XML_Char **attr)
|
||||||
static FcBool
|
static FcBool
|
||||||
FcPStackPush (FcConfigParse *parse, FcElement element, const XML_Char **attr)
|
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->prev = parse->pstack;
|
||||||
new->element = element;
|
new->element = element;
|
||||||
new->attr = FcConfigSaveAttr (attr);
|
new->attr = FcConfigSaveAttr (attr);
|
||||||
|
@ -994,8 +1003,14 @@ FcPStackPop (FcConfigParse *parse)
|
||||||
FcMemFree (FC_MEM_ATTR, 1); /* size is to expensive */
|
FcMemFree (FC_MEM_ATTR, 1); /* size is to expensive */
|
||||||
free (old->attr);
|
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;
|
return FcTrue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1003,6 +1018,7 @@ static FcBool
|
||||||
FcConfigInit (FcConfigParse *parse, const FcChar8 *name, FcConfig *config, XML_Parser parser)
|
FcConfigInit (FcConfigParse *parse, const FcChar8 *name, FcConfig *config, XML_Parser parser)
|
||||||
{
|
{
|
||||||
parse->pstack = 0;
|
parse->pstack = 0;
|
||||||
|
parse->pstack_static_used = 0;
|
||||||
parse->vstack = 0;
|
parse->vstack = 0;
|
||||||
parse->error = FcFalse;
|
parse->error = FcFalse;
|
||||||
parse->name = name;
|
parse->name = name;
|
||||||
|
|
Loading…
Reference in New Issue