aboutsummaryrefslogtreecommitdiff
path: root/lib/cbit
diff options
context:
space:
mode:
authorcomex2015-01-29 01:48:09 -0500
committercomex2015-01-29 01:48:17 -0500
commit5d7d4cdf531234390055540dc4ccc478268b0588 (patch)
tree4bda0d50e2284986d730efe7ce9db77a28f51b3f /lib/cbit
parentport some old code (diff)
downloadsubstitute-5d7d4cdf531234390055540dc4ccc478268b0588.tar.gz
get rid of the unnecessary CoreFoundation dependency
Diffstat (limited to 'lib/cbit')
-rw-r--r--lib/cbit/htab.h19
1 files changed, 14 insertions, 5 deletions
diff --git a/lib/cbit/htab.h b/lib/cbit/htab.h
index 861a9be..5c9b993 100644
--- a/lib/cbit/htab.h
+++ b/lib/cbit/htab.h
@@ -95,7 +95,6 @@ struct htab_internal {
key_ty *bucket = (void *) (buckets + i * entry_size); \
if (null_func(bucket)) { \
if (add) { \
- *bucket = *key; \
hi->length++; \
return bucket; \
} else { \
@@ -213,15 +212,25 @@ struct htab_internal {
} \
UNUSED_STATIC_INLINE \
bucket_ty *htab_setbucket_##name(htab_ty *restrict ht, \
- const key_ty *restrict key) { \
+ const key_ty *restrict key) { \
return __htab_key_lookup_##key_name(&ht->hi, key, sizeof(bucket_ty), \
true, true); \
} \
UNUSED_STATIC_INLINE \
value_ty *htab_setp_##name(const htab_ty *restrict ht, \
- const key_ty *restrict key) { \
+ const key_ty *restrict key, \
+ bool *new_p) { \
bucket_ty *bucket = htab_setbucket_##name((void *) ht, key); \
- return bucket ? &bucket->value : NULL; \
+ bool new = false; \
+ if (__htab_key_is_null_##key_name(&bucket->key)) { \
+ bucket->key = *key; \
+ new = true; \
+ } else { \
+ new = false; \
+ } \
+ if (new_p) \
+ *new_p = new; \
+ return &bucket->value; \
} \
UNUSED_STATIC_INLINE \
bool htab_remove_##name(htab_ty *restrict ht, const key_ty *restrict key) { \
@@ -240,7 +249,7 @@ struct htab_internal {
return __htab_key_resize_##key_name(&ht->hi, size, sizeof(bucket_ty)); \
} \
UNUSED_STATIC_INLINE \
- void htab_free_##name(htab_ty *ht) { \
+ void htab_free_storage_##name(htab_ty *ht) { \
if (ht->base != ht->storage) \
free(ht->base); \
}