radare2/libr/util/str_constpool.c
pancake f8a35da205
Dont use != NULL as its implicit in C, even for bool casts ##refactor
$ find binr libr -name "*.c" -exec sed -i -e 's/ != NULL//g' {} \;
2022-03-15 19:54:04 +01:00

33 lines
664 B
C

/* radare - LGPL - Copyright 2019 thestr4ng3r */
#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 = ht_pp_new (NULL, kv_fini, NULL);
return pool->ht;
}
R_API void r_str_constpool_fini(RStrConstPool *pool) {
ht_pp_free (pool->ht);
}
R_API const char *r_str_constpool_get(RStrConstPool *pool, const char *str) {
if (!str) {
return 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;
}