Add a "unique string cache" to rpmug

- Used for storing unique strings just once
This commit is contained in:
Panu Matilainen 2010-12-16 09:31:20 +02:00
parent 3296c651b9
commit 353a7a8125
2 changed files with 30 additions and 0 deletions

View File

@ -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);
}

View File

@ -3,6 +3,8 @@
#include <sys/types.h>
const char * rpmugStashStr(const char *str);
int rpmugUid(const char * name, uid_t * uid);
int rpmugGid(const char * name, gid_t * gid);