Use HtPP for RStrConstPool (#15424) ##util

This commit is contained in:
Florian Märkl 2019-11-06 21:55:46 +01:00 committed by radare
parent 01937fcaf9
commit af1c9bff71

View File

@ -2,19 +2,31 @@
#include "r_util/r_str_constpool.h"
static void kv_fini(HtPPKv *kv) {
free (kv->key);
}
R_API bool r_str_constpool_init(RStrConstPool *pool) {
pool->ht = sdb_ht_new ();
pool->ht = ht_pp_new (NULL, kv_fini, NULL);
return pool->ht != NULL;
}
R_API void r_str_constpool_fini(RStrConstPool *pool) {
sdb_ht_free (pool->ht);
ht_pp_free (pool->ht);
}
R_API const char *r_str_constpool_get(RStrConstPool *pool, const char *str) {
if (!str) {
return NULL;
}
sdb_ht_insert (pool->ht, str, str);
return sdb_ht_find (pool->ht, str, NULL);
HtPPKv *kv = ht_pp_find_kv (pool->ht, str, NULL);
if (kv) {
return kv->key;
}
ht_pp_insert (pool->ht, str, NULL);
kv = ht_pp_find_kv (pool->ht, str, NULL);
if (kv) {
return kv->key;
}
return NULL;
}