mirror of
https://github.com/radareorg/radare2.git
synced 2025-02-03 20:22:38 +00:00
Use HtPP for RStrConstPool (#15424) ##util
This commit is contained in:
parent
01937fcaf9
commit
af1c9bff71
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user