diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2010-12-16 09:31:20 +0200 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2010-12-16 09:31:20 +0200 |
commit | 353a7a81257e2a2a322b211b6ebf11b750ca6e68 (patch) | |
tree | e9bb64630da4b45a5481c9aa52e6b37adf1926d4 /lib/rpmug.c | |
parent | 3296c651b90b1caed216a3c65f024ea741ea13f9 (diff) | |
download | librpm-tizen-353a7a81257e2a2a322b211b6ebf11b750ca6e68.tar.gz librpm-tizen-353a7a81257e2a2a322b211b6ebf11b750ca6e68.tar.bz2 librpm-tizen-353a7a81257e2a2a322b211b6ebf11b750ca6e68.zip |
Add a "unique string cache" to rpmug
- Used for storing unique strings just once
Diffstat (limited to 'lib/rpmug.c')
-rw-r--r-- | lib/rpmug.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/rpmug.c b/lib/rpmug.c index 47aa6ccf5..2bb18e5a3 100644 --- a/lib/rpmug.c +++ b/lib/rpmug.c @@ -5,9 +5,36 @@ #include <rpm/rpmlog.h> #include <rpm/rpmstring.h> +#include "lib/misc.h" #include "lib/rpmug.h" #include "debug.h" +#define HASHTYPE strCache +#define HTKEYTYPE const char * +#include "lib/rpmhash.H" +#include "lib/rpmhash.C" +#undef HASHTYPE +#undef HTKEYTYPE + +static strCache strStash = NULL; + +const char * rpmugStashStr(const char *str) +{ + const char *ret = NULL; + if (str) { + if (strStash == NULL) { + strStash = strCacheCreate(64, hashFunctionString, strcmp, + (strCacheFreeKey)rfree); + } + + if (!strCacheGetEntry(strStash, str, &ret)) { + strCacheAddEntry(strStash, xstrdup(str)); + (void) strCacheGetEntry(strStash, str, &ret); + } + } + return ret; +} + /* * These really ought to use hash tables. I just made the * guess that most files would be owned by root or the same person/group @@ -171,4 +198,5 @@ void rpmugFree(void) rpmugGid(NULL, NULL); rpmugUname(-1); rpmugGname(-1); + strCacheFree(strStash); } |