From 3be356cb0f583c68069150421a7bdd5a8f65d555 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Tue, 29 Apr 2008 13:17:33 +0300 Subject: Avoid alloca() in findTag() - instead of putting RPMTAG_ into strings where it's not present, do it the other way around - avoids a string copy and redundant string comparisons on the RPMTAG_ part --- rpmdb/header.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'rpmdb') diff --git a/rpmdb/header.c b/rpmdb/header.c index 13202a86e..66e12044f 100644 --- a/rpmdb/header.c +++ b/rpmdb/header.c @@ -1970,7 +1970,7 @@ static const char * myTagName(headerTagTableEntry tbl, int val) static int myTagValue(headerTagTableEntry tbl, const char * name) { for (; tbl->name != NULL; tbl++) { - if (!rstrcasecmp(tbl->name, name)) + if (!rstrcasecmp(tbl->name + sizeof("RPMTAG"), name)) return tbl->val; } return 0; @@ -1985,6 +1985,7 @@ static int myTagValue(headerTagTableEntry tbl, const char * name) */ static int findTag(headerSprintfArgs hsa, sprintfToken token, const char * name) { + const char *tagname = name; headerSprintfExtension ext; sprintfTag stag = (token->type == PTOK_COND ? &token->u.cond.tag : &token->u.tag); @@ -1994,15 +1995,13 @@ static int findTag(headerSprintfArgs hsa, sprintfToken token, const char * name) stag->extNum = 0; stag->tag = -1; - if (!strcmp(name, "*")) { + if (!strcmp(tagname, "*")) { stag->tag = -2; goto bingo; } - if (strncmp("RPMTAG_", name, sizeof("RPMTAG_")-1)) { - char * t = alloca(strlen(name) + sizeof("RPMTAG_")); - (void) stpcpy( stpcpy(t, "RPMTAG_"), name); - name = t; + if (strncmp("RPMTAG_", tagname, sizeof("RPMTAG_")-1) == 0) { + tagname += sizeof("RPMTAG"); } /* Search extensions for specific tag override. */ @@ -2011,7 +2010,7 @@ static int findTag(headerSprintfArgs hsa, sprintfToken token, const char * name) { if (ext->name == NULL || ext->type != HEADER_EXT_TAG) continue; - if (!rstrcasecmp(ext->name, name)) { + if (!rstrcasecmp(ext->name + sizeof("RPMTAG"), tagname)) { stag->ext = ext->u.tagFunction; stag->extNum = ext - hsa->exts; goto bingo; @@ -2019,7 +2018,7 @@ static int findTag(headerSprintfArgs hsa, sprintfToken token, const char * name) } /* Search tag names. */ - stag->tag = myTagValue(hsa->tags, name); + stag->tag = myTagValue(hsa->tags, tagname); if (stag->tag != 0) goto bingo; -- cgit v1.2.3