summaryrefslogtreecommitdiff
path: root/lib/rpmds.c
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2009-06-16 18:15:31 +0300
committerPanu Matilainen <pmatilai@redhat.com>2009-06-16 18:15:31 +0300
commit7fd95d099f232a54d772379fc9769eb3c2453fed (patch)
tree8b4bb0aa43791d06d6debc7334961d4fb06b0ebd /lib/rpmds.c
parent61acdba023167c73cf0db124f0ae8c09c8f387d6 (diff)
downloadrpm-7fd95d099f232a54d772379fc9769eb3c2453fed.tar.gz
Generate DNEVR string lazily on rpmdsDNEVR() calls
- avoids useless string churning on rpmdsNext() when most paths dont actually use the DNEVR string for anything - make sure DNEVR is freed whenever iterator index changes
Diffstat (limited to 'lib/rpmds.c')
-rw-r--r--lib/rpmds.c28
1 files changed, 13 insertions, 15 deletions
diff --git a/lib/rpmds.c b/lib/rpmds.c
index 05676fdfd..5f3d30312 100644
--- a/lib/rpmds.c
+++ b/lib/rpmds.c
@@ -254,11 +254,6 @@ rpmds rpmdsSingle(rpmTag tagN, const char * N, const char * EVR, rpmsenseFlags F
ds->Flags = xmalloc(sizeof(*ds->Flags));
ds->Flags[0] = Flags;
ds->i = 0;
- { char t[2];
- t[0] = ds->Type[0];
- t[1] = '\0';
- ds->DNEVR = rpmdsNewDNEVR(t, ds);
- }
exit:
return rpmdsLink(ds, (ds ? ds->Type : NULL));
@@ -281,6 +276,7 @@ int rpmdsSetIx(rpmds ds, int ix)
if (ds != NULL) {
i = ds->i;
ds->i = ix;
+ ds->DNEVR = _free(ds->DNEVR);
}
return i;
}
@@ -290,8 +286,11 @@ const char * rpmdsDNEVR(const rpmds ds)
const char * DNEVR = NULL;
if (ds != NULL && ds->i >= 0 && ds->i < ds->Count) {
- if (ds->DNEVR != NULL)
- DNEVR = ds->DNEVR;
+ if (ds->DNEVR == NULL) {
+ char t[2] = { ds->Type[0], '\0' };
+ ds->DNEVR = rpmdsNewDNEVR(t, ds);
+ }
+ DNEVR = ds->DNEVR;
}
return DNEVR;
}
@@ -426,15 +425,17 @@ int32_t rpmdsSetRefs(const rpmds ds, int32_t refs)
void rpmdsNotify(rpmds ds, const char * where, int rc)
{
+ const char *DNEVR;
+
if (!rpmIsDebug())
return;
if (!(ds != NULL && ds->i >= 0 && ds->i < ds->Count))
return;
- if (!(ds->Type != NULL && ds->DNEVR != NULL))
+ if (!(ds->Type != NULL && (DNEVR = rpmdsDNEVR(ds)) != NULL))
return;
rpmlog(RPMLOG_DEBUG, "%9s: %-45s %-s %s\n", ds->Type,
- (!strcmp(ds->DNEVR, "cached") ? ds->DNEVR : ds->DNEVR+2),
+ (!strcmp(DNEVR, "cached") ? DNEVR : DNEVR+2),
(rc ? _("NO ") : _("YES")),
(where != NULL ? where : ""));
}
@@ -445,13 +446,8 @@ int rpmdsNext(rpmds ds)
if (ds != NULL && ++ds->i >= 0) {
if (ds->i < ds->Count) {
- char t[2];
i = ds->i;
ds->DNEVR = _free(ds->DNEVR);
- t[0] = ((ds->Type != NULL) ? ds->Type[0] : '\0');
- t[1] = '\0';
- ds->DNEVR = rpmdsNewDNEVR(t, ds);
-
} else
ds->i = -1;
@@ -465,8 +461,10 @@ fprintf(stderr, "*** ds %p\t%s[%d]: %s\n", ds, (ds->Type ? ds->Type : "?Type?"),
rpmds rpmdsInit(rpmds ds)
{
- if (ds != NULL)
+ if (ds != NULL) {
ds->i = -1;
+ ds->DNEVR = _free(ds->DNEVR);
+ }
return ds;
}