summaryrefslogtreecommitdiff
path: root/rpmdb
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2008-04-29 13:17:33 +0300
committerPanu Matilainen <pmatilai@redhat.com>2008-04-29 13:17:33 +0300
commit3be356cb0f583c68069150421a7bdd5a8f65d555 (patch)
tree298d6a11f459f56233f1c5f82fabb99c5ea0b588 /rpmdb
parent69e3540ed0c875221147d9af5ab90089d55e5fa5 (diff)
downloadlibrpm-tizen-3be356cb0f583c68069150421a7bdd5a8f65d555.tar.gz
librpm-tizen-3be356cb0f583c68069150421a7bdd5a8f65d555.tar.bz2
librpm-tizen-3be356cb0f583c68069150421a7bdd5a8f65d555.zip
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
Diffstat (limited to 'rpmdb')
-rw-r--r--rpmdb/header.c15
1 files changed, 7 insertions, 8 deletions
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;