From 532d8a1dbc2baebc2603d091952a640b954b6f71 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 12 Mar 2009 09:27:20 -0400 Subject: [PATCH] [fcxml] Don't allocate attr array if there are no attributes Reduces number of mallocs from FcConfigSaveAttr() in my small test from over 900 down to 157. --- src/fcxml.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/fcxml.c b/src/fcxml.c index f60e248..ccc9c19 100644 --- a/src/fcxml.c +++ b/src/fcxml.c @@ -939,9 +939,14 @@ FcConfigSaveAttr (const XML_Char **attr) slen = 0; for (i = 0; attr[i]; i++) slen += strlen ((char *) attr[i]) + 1; + if (i == 0) + return 0; new = malloc ((i + 1) * sizeof (FcChar8 *) + slen); if (!new) + { + FcConfigMessage (0, FcSevereError, "out of memory"); return 0; + } FcMemAlloc (FC_MEM_ATTR, 1); /* size is too expensive */ s = (FcChar8 *) (new + (i + 1)); for (i = 0; attr[i]; i++) @@ -964,19 +969,7 @@ FcPStackPush (FcConfigParse *parse, FcElement element, const XML_Char **attr) FcMemAlloc (FC_MEM_PSTACK, sizeof (FcPStack)); new->prev = parse->pstack; new->element = element; - if (attr) - { - new->attr = FcConfigSaveAttr (attr); - if (!new->attr) - { - FcConfigMessage (parse, FcSevereError, "out of memory"); - FcMemFree (FC_MEM_PSTACK, sizeof (FcPStack)); - free (new); - return FcFalse; - } - } - else - new->attr = 0; + new->attr = FcConfigSaveAttr (attr); FcStrBufInit (&new->str, 0, 0); parse->pstack = new; return FcTrue; -- 2.39.5