2019-10-20 10:31:45 +00:00
|
|
|
/* radare - LGPL - Copyright 2019 thestr4ng3r */
|
|
|
|
|
|
|
|
#include "r_util/r_str_constpool.h"
|
|
|
|
|
2019-11-06 20:55:46 +00:00
|
|
|
static void kv_fini(HtPPKv *kv) {
|
|
|
|
free (kv->key);
|
|
|
|
}
|
|
|
|
|
2019-10-20 10:31:45 +00:00
|
|
|
R_API bool r_str_constpool_init(RStrConstPool *pool) {
|
2019-11-06 20:55:46 +00:00
|
|
|
pool->ht = ht_pp_new (NULL, kv_fini, NULL);
|
2022-03-15 18:54:04 +00:00
|
|
|
return pool->ht;
|
2019-10-20 10:31:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
R_API void r_str_constpool_fini(RStrConstPool *pool) {
|
2019-11-06 20:55:46 +00:00
|
|
|
ht_pp_free (pool->ht);
|
2019-10-20 10:31:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
R_API const char *r_str_constpool_get(RStrConstPool *pool, const char *str) {
|
|
|
|
if (!str) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2019-11-06 20:55:46 +00:00
|
|
|
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;
|
2019-10-20 10:31:45 +00:00
|
|
|
}
|