Rename td2pool as rpmtdToPool, export and optimize
- Using rpmtd iteration for this is slow and stupid as we keep pointlessly re-re-re-re-re-validating the tag type and indexes. - Change argument order to source -> destination - Move to rpmtd.c where it belongs and make public with a decent name. Not sure if this is the kind of an API we really want to make public but ... at least for now it'll do.
This commit is contained in:
parent
9929a34aaf
commit
0c76a514f0
16
lib/rpmfi.c
16
lib/rpmfi.c
|
@ -1064,22 +1064,12 @@ rpmfi rpmfiFree(rpmfi fi)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static rpmsid * td2pool(rpmstrPool pool, rpmtd td)
|
||||
{
|
||||
rpmsid *sids = xmalloc(sizeof(*sids) * rpmtdCount(td));
|
||||
const char *str;
|
||||
int i = 0;
|
||||
while ((str = rpmtdNextString(td)))
|
||||
sids[i++] = rpmstrPoolId(pool, str, 1);
|
||||
return sids;
|
||||
}
|
||||
|
||||
static rpmsid * tag2pool(rpmstrPool pool, Header h, rpmTag tag)
|
||||
{
|
||||
rpmsid *sids = NULL;
|
||||
struct rpmtd_s td;
|
||||
if (headerGet(h, tag, &td, HEADERGET_MINMEM)) {
|
||||
sids = td2pool(pool, &td);
|
||||
sids = rpmtdToPool(&td, pool);
|
||||
rpmtdFreeData(&td);
|
||||
}
|
||||
return sids;
|
||||
|
@ -1232,8 +1222,8 @@ rpmfi rpmfiNewPool(rpmstrPool pool, Header h, rpmTagVal tagN, rpmfiFlags flags)
|
|||
/* init the file triplet data */
|
||||
fi->fc = rpmtdCount(&bn);
|
||||
fi->dc = rpmtdCount(&dn);
|
||||
fi->bnid = td2pool(fi->pool, &bn);
|
||||
fi->dnid = td2pool(fi->pool, &dn);
|
||||
fi->bnid = rpmtdToPool(&bn, fi->pool);
|
||||
fi->dnid = rpmtdToPool(&dn, fi->pool);
|
||||
/* steal index data from the td (pooh...) */
|
||||
fi->dil = dx.data;
|
||||
dx.data = NULL;
|
||||
|
|
19
lib/rpmtd.c
19
lib/rpmtd.c
|
@ -3,6 +3,7 @@
|
|||
#include <rpm/rpmtd.h>
|
||||
#include <rpm/rpmstring.h>
|
||||
#include <rpm/rpmpgp.h>
|
||||
#include <rpm/rpmstrpool.h>
|
||||
#include "lib/misc.h" /* format function prototypes */
|
||||
|
||||
#include "debug.h"
|
||||
|
@ -444,3 +445,21 @@ rpmtd rpmtdDup(rpmtd td)
|
|||
|
||||
return newtd;
|
||||
}
|
||||
|
||||
rpmsid * rpmtdToPool(rpmtd td, rpmstrPool pool)
|
||||
{
|
||||
rpmsid *sids = NULL;
|
||||
|
||||
if (pool && td) {
|
||||
const char **strings = td->data;
|
||||
switch (td->type) {
|
||||
case RPM_STRING_ARRAY_TYPE:
|
||||
case RPM_I18NSTRING_TYPE:
|
||||
sids = xmalloc(td->count * sizeof(*sids));
|
||||
for (rpm_count_t i = 0; i < td->count; i++)
|
||||
sids[i] = rpmstrPoolId(pool, strings[i], 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return sids;
|
||||
}
|
||||
|
|
|
@ -356,6 +356,14 @@ int rpmtdFromArgi(rpmtd td, rpmTagVal tag, ARGI_t argi);
|
|||
*/
|
||||
rpmtd rpmtdDup(rpmtd td);
|
||||
|
||||
/* \ingroup rpmtd
|
||||
* Push string array container contents to a string pool, return string ids.
|
||||
* @param td Tag data container
|
||||
* @param pool String pool
|
||||
* @return Array of string id's (malloced)
|
||||
*/
|
||||
rpmsid * rpmtdToPool(rpmtd td, rpmstrPool pool);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue