From: Panu Matilainen Date: Thu, 16 Dec 2010 07:31:20 +0000 (+0200) Subject: Add a "unique string cache" to rpmug X-Git-Tag: tznext/4.11.0.1.tizen20130304~1367 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=353a7a81257e2a2a322b211b6ebf11b750ca6e68;p=tools%2Flibrpm-tizen.git Add a "unique string cache" to rpmug - Used for storing unique strings just once --- diff --git a/lib/rpmug.c b/lib/rpmug.c index 47aa6cc..2bb18e5 100644 --- a/lib/rpmug.c +++ b/lib/rpmug.c @@ -5,9 +5,36 @@ #include #include +#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); } diff --git a/lib/rpmug.h b/lib/rpmug.h index 7dbe77d..35e5d63 100644 --- a/lib/rpmug.h +++ b/lib/rpmug.h @@ -3,6 +3,8 @@ #include +const char * rpmugStashStr(const char *str); + int rpmugUid(const char * name, uid_t * uid); int rpmugGid(const char * name, gid_t * gid);