summaryrefslogtreecommitdiff
path: root/lib/rpmfi.c
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2012-09-07 11:31:12 +0300
committerPanu Matilainen <pmatilai@redhat.com>2012-09-07 13:34:42 +0300
commit8909eed1a83712b54e39dd559ef0661aaf29fb48 (patch)
tree85c60441b269dd07dbd0263795d2b363b348e548 /lib/rpmfi.c
parent4606460e54a1a151f74557712355ffc5d32da7c4 (diff)
downloadlibrpm-tizen-8909eed1a83712b54e39dd559ef0661aaf29fb48.tar.gz
librpm-tizen-8909eed1a83712b54e39dd559ef0661aaf29fb48.tar.bz2
librpm-tizen-8909eed1a83712b54e39dd559ef0661aaf29fb48.zip
Replace user- and groupname + file lang caches with a global stringpool
- With the string pool we dont have to worry about overflowing the indexes so we can lump all this relatively static data into one pool. Because rpmsid's are larger than the previous cache indexes, we'll loose some of the memory savings, but then the pool is faster on insertion, and we'll only need one of them so... - The misc. pool is never freed, flushed or frozen so it'll "waste" memory throughout the lifetime of a process (similarly to the previous caches) but its not huge so .. ignoring that for now.
Diffstat (limited to 'lib/rpmfi.c')
-rw-r--r--lib/rpmfi.c41
1 files changed, 30 insertions, 11 deletions
diff --git a/lib/rpmfi.c b/lib/rpmfi.c
index 9ef372548..83b5f9714 100644
--- a/lib/rpmfi.c
+++ b/lib/rpmfi.c
@@ -18,6 +18,9 @@
#include "debug.h"
+/* pool for widely common, "static" stuff like langs and user/group names */
+static rpmstrPool miscpool = NULL;
+
/*
* Simple and stupid string "cache."
* Store each unique string just once, retrieve by index value.
@@ -30,11 +33,6 @@ struct strcache_s {
scidx_t num;
};
-static struct strcache_s _ugcache = { NULL, 0 };
-static strcache ugcache = &_ugcache;
-static struct strcache_s _langcache = { NULL, 0 };
-static strcache langcache = &_langcache;
-
static scidx_t strcachePut(strcache cache, const char *str)
{
int found = 0;
@@ -412,7 +410,7 @@ const char * rpmfiFUserIndex(rpmfi fi, int ix)
if (fi != NULL && ix >= 0 && ix < fi->fc) {
if (fi->fuser != NULL)
- fuser = strcacheGet(ugcache, fi->fuser[ix]);
+ fuser = rpmstrPoolStr(miscpool, fi->fuser[ix]);
}
return fuser;
}
@@ -423,7 +421,7 @@ const char * rpmfiFGroupIndex(rpmfi fi, int ix)
if (fi != NULL && ix >= 0 && ix < fi->fc) {
if (fi->fgroup != NULL)
- fgroup = strcacheGet(ugcache, fi->fgroup[ix]);
+ fgroup = rpmstrPoolStr(miscpool, fi->fgroup[ix]);
}
return fgroup;
}
@@ -441,7 +439,7 @@ const char * rpmfiFLangsIndex(rpmfi fi, int ix)
{
const char *flangs = NULL;
if (fi != NULL && fi->flangs != NULL && ix >= 0 && ix < fi->fc) {
- flangs = strcacheGet(langcache, fi->flangs[ix]);
+ flangs = rpmstrPoolStr(miscpool, fi->flangs[ix]);
}
return flangs;
}
@@ -1143,6 +1141,23 @@ static scidx_t *cacheTag(strcache cache, Header h, rpmTag tag)
return idx;
}
+static rpmsid * tag2pool(rpmstrPool pool, Header h, rpmTag tag)
+{
+ rpmsid *sids = NULL;
+ struct rpmtd_s td;
+ if (headerGet(h, tag, &td, HEADERGET_MINMEM)) {
+ int i = 0;
+ const char *str;
+
+ sids = xmalloc(sizeof(*sids) * rpmtdCount(&td));
+ while ((str = rpmtdNextString(&td))) {
+ sids[i++] = rpmstrPoolId(pool, str, 1);
+ }
+ rpmtdFreeData(&td);
+ }
+ return sids;
+}
+
#define _hgfi(_h, _tag, _td, _flags, _data) \
if (headerGet((_h), (_tag), (_td), (_flags))) \
_data = (td.data)
@@ -1181,6 +1196,10 @@ rpmfi rpmfiNew(const rpmts ts, Header h, rpmTagVal tagN, rpmfiFlags flags)
goto errxit;
}
+ /* XXX: ensure the global misc. pool exists */
+ if (miscpool == NULL)
+ miscpool = rpmstrPoolCreate();
+
/* XXX TODO: all these should be sanity checked, ugh... */
if (!(flags & RPMFI_NOFILEMODES))
_hgfi(h, RPMTAG_FILEMODES, &td, scareFlags, fi->fmodes);
@@ -1218,7 +1237,7 @@ rpmfi rpmfiNew(const rpmts ts, Header h, rpmTagVal tagN, rpmfiFlags flags)
}
/* FILELANGS are only interesting when installing */
if ((headerGetInstance(h) == 0) && !(flags & RPMFI_NOFILELANGS))
- fi->flangs = cacheTag(langcache, h, RPMTAG_FILELANGS);
+ fi->flangs = tag2pool(miscpool, h, RPMTAG_FILELANGS);
/* See if the package has non-md5 file digests */
fi->digestalgo = PGPHASHALGO_MD5;
@@ -1259,9 +1278,9 @@ rpmfi rpmfiNew(const rpmts ts, Header h, rpmTagVal tagN, rpmfiFlags flags)
_hgfi(h, RPMTAG_FILEINODES, &td, scareFlags, fi->finodes);
if (!(flags & RPMFI_NOFILEUSER))
- fi->fuser = cacheTag(ugcache, h, RPMTAG_FILEUSERNAME);
+ fi->fuser = tag2pool(miscpool, h, RPMTAG_FILEUSERNAME);
if (!(flags & RPMFI_NOFILEGROUP))
- fi->fgroup = cacheTag(ugcache, h, RPMTAG_FILEGROUPNAME);
+ fi->fgroup = tag2pool(miscpool, h, RPMTAG_FILEGROUPNAME);
/* lazily alloced from rpmfiFN() */
fi->fn = NULL;