Calculate filename buffer len lazily in rpmfiFN() as needed
- avoids having to separately calculate in genCpioListAndHeader() - avoids unnecessary fnlen field in rpmfi struct - avoids having to calculate it at all if rpmfiFN() is never called
This commit is contained in:
parent
6bd6677f86
commit
a9169c46ab
|
@ -1039,7 +1039,6 @@ static void genCpioListAndHeader(FileList fl,
|
|||
size_t apathlen = 0;
|
||||
size_t dpathlen = 0;
|
||||
size_t skipLen = 0;
|
||||
size_t fnlen;
|
||||
FileListRec flp;
|
||||
char buf[BUFSIZ];
|
||||
int i;
|
||||
|
@ -1298,9 +1297,6 @@ static void genCpioListAndHeader(FileList fl,
|
|||
continue;
|
||||
}
|
||||
|
||||
if ((fnlen = strlen(flp->diskPath) + 1) > fi->fnlen)
|
||||
fi->fnlen = fnlen;
|
||||
|
||||
/* Create disk directory and base name. */
|
||||
fi->dil[i] = i;
|
||||
/* FIX: artifact of spoofing headerGetEntry */
|
||||
|
|
29
lib/rpmfi.c
29
lib/rpmfi.c
|
@ -117,8 +117,18 @@ const char * rpmfiFN(rpmfi fi)
|
|||
|
||||
if (fi != NULL && fi->i >= 0 && fi->i < fi->fc) {
|
||||
char * t;
|
||||
if (fi->fn == NULL)
|
||||
fi->fn = xmalloc(fi->fnlen);
|
||||
if (fi->fn == NULL) {
|
||||
size_t dnlmax = 0, bnlmax = 0, len;
|
||||
for (int i = 0; i < fi->dc; i++) {
|
||||
if ((len = strlen(fi->dnl[i])) > dnlmax)
|
||||
dnlmax = len;
|
||||
}
|
||||
for (int i = 0; i < fi->fc; i++) {
|
||||
if ((len = strlen(fi->bnl[i])) > bnlmax)
|
||||
bnlmax = len;
|
||||
}
|
||||
fi->fn = xmalloc(dnlmax + bnlmax + 1);
|
||||
}
|
||||
FN = t = fi->fn;
|
||||
*t = '\0';
|
||||
t = stpcpy(t, fi->dnl[fi->dil[fi->i]]);
|
||||
|
@ -1185,15 +1195,12 @@ rpmfi rpmfiNew(const rpmts ts, Header h, rpmTag tagN, rpmfiFlags flags)
|
|||
rpmfi fi = NULL;
|
||||
const char * Type;
|
||||
rpm_loff_t *asize = NULL;
|
||||
int dnlmax, bnlmax;
|
||||
unsigned char * t;
|
||||
struct rpmtd_s fdigests, digalgo;
|
||||
struct rpmtd_s td;
|
||||
headerGetFlags scareFlags = (flags & RPMFI_KEEPHEADER) ?
|
||||
HEADERGET_MINMEM : HEADERGET_ALLOC;
|
||||
headerGetFlags defFlags = HEADERGET_ALLOC;
|
||||
int len;
|
||||
int i;
|
||||
|
||||
if (tagN == RPMTAG_BASENAMES) {
|
||||
Type = "Files";
|
||||
|
@ -1343,17 +1350,7 @@ rpmfi rpmfiNew(const rpmts ts, Header h, rpmTag tagN, rpmfiFlags flags)
|
|||
fi->h = headerFree(fi->h);
|
||||
}
|
||||
|
||||
dnlmax = -1;
|
||||
for (i = 0; i < fi->dc; i++) {
|
||||
if ((len = strlen(fi->dnl[i])) > dnlmax)
|
||||
dnlmax = len;
|
||||
}
|
||||
bnlmax = -1;
|
||||
for (i = 0; i < fi->fc; i++) {
|
||||
if ((len = strlen(fi->bnl[i])) > bnlmax)
|
||||
bnlmax = len;
|
||||
}
|
||||
fi->fnlen = dnlmax + bnlmax + 1;
|
||||
/* lazily alloced from rpmfiFN() */
|
||||
fi->fn = NULL;
|
||||
|
||||
exit:
|
||||
|
|
|
@ -96,7 +96,6 @@ struct rpmfi_s {
|
|||
int transscripts; /*!< pre/posttrans script existence */
|
||||
|
||||
char * fn; /*!< File name buffer. */
|
||||
size_t fnlen; /*!< FIle name buffer length. */
|
||||
|
||||
size_t astriplen;
|
||||
size_t striplen;
|
||||
|
|
Loading…
Reference in New Issue