aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2014-05-22 16:59:41 -0400
committerJustin M. Keyes <justinkz@gmail.com>2014-05-22 17:00:55 -0400
commitf1e52c496ddb89f830cdbc4f23d756131106b97f (patch)
treed40c798a5e386a455df9c10937d20261241b039b /src
parente2e47803bdfd5fb40e3dbc9cdf798bb27d306c72 (diff)
parentc57c3633d4c1667aa2c61a3b086041a989fd480c (diff)
downloadrneovim-f1e52c496ddb89f830cdbc4f23d756131106b97f.tar.gz
rneovim-f1e52c496ddb89f830cdbc4f23d756131106b97f.tar.bz2
rneovim-f1e52c496ddb89f830cdbc4f23d756131106b97f.zip
Merge #739 'Remove OOM error handling in khash.h'
Diffstat (limited to 'src')
-rw-r--r--src/nvim/lib/khash.h18
1 files changed, 6 insertions, 12 deletions
diff --git a/src/nvim/lib/khash.h b/src/nvim/lib/khash.h
index ce2862a1f1..51a666733b 100644
--- a/src/nvim/lib/khash.h
+++ b/src/nvim/lib/khash.h
@@ -197,7 +197,7 @@ static const double __ac_HASH_UPPER = 0.77;
extern void kh_destroy_##name(kh_##name##_t *h); \
extern void kh_clear_##name(kh_##name##_t *h); \
extern khint_t kh_get_##name(const kh_##name##_t *h, khkey_t key); \
- extern int kh_resize_##name(kh_##name##_t *h, khint_t new_n_buckets); \
+ extern void kh_resize_##name(kh_##name##_t *h, khint_t new_n_buckets); \
extern khint_t kh_put_##name(kh_##name##_t *h, khkey_t key, int *ret); \
extern void kh_del_##name(kh_##name##_t *h, khint_t x);
@@ -240,9 +240,9 @@ static const double __ac_HASH_UPPER = 0.77;
return __ac_iseither(h->flags, i)? h->n_buckets : i; \
} else return 0; \
} \
- SCOPE int kh_resize_##name(kh_##name##_t *h, khint_t new_n_buckets) \
+ SCOPE void kh_resize_##name(kh_##name##_t *h, khint_t new_n_buckets) \
FUNC_ATTR_UNUSED; \
- SCOPE int kh_resize_##name(kh_##name##_t *h, khint_t new_n_buckets) \
+ SCOPE void kh_resize_##name(kh_##name##_t *h, khint_t new_n_buckets) \
{ /* This function uses 0.25*n_buckets bytes of working space instead of [sizeof(key_t+val_t)+.25]*n_buckets. */ \
khint32_t *new_flags = 0; \
khint_t j = 1; \
@@ -252,15 +252,12 @@ static const double __ac_HASH_UPPER = 0.77;
if (h->size >= (khint_t)(new_n_buckets * __ac_HASH_UPPER + 0.5)) j = 0; /* requested size is too small */ \
else { /* hash table size to be changed (shrink or expand); rehash */ \
new_flags = (khint32_t*)kmalloc(__ac_fsize(new_n_buckets) * sizeof(khint32_t)); \
- if (!new_flags) return -1; \
memset(new_flags, 0xaa, __ac_fsize(new_n_buckets) * sizeof(khint32_t)); \
if (h->n_buckets < new_n_buckets) { /* expand */ \
khkey_t *new_keys = (khkey_t*)krealloc((void *)h->keys, new_n_buckets * sizeof(khkey_t)); \
- if (!new_keys) return -1; \
h->keys = new_keys; \
if (kh_is_map) { \
khval_t *new_vals = (khval_t*)krealloc((void *)h->vals, new_n_buckets * sizeof(khval_t)); \
- if (!new_vals) return -1; \
h->vals = new_vals; \
} \
} /* otherwise shrink */ \
@@ -303,7 +300,6 @@ static const double __ac_HASH_UPPER = 0.77;
h->n_occupied = h->size; \
h->upper_bound = (khint_t)(h->n_buckets * __ac_HASH_UPPER + 0.5); \
} \
- return 0; \
} \
SCOPE khint_t kh_put_##name(kh_##name##_t *h, khkey_t key, int *ret) \
FUNC_ATTR_UNUSED; \
@@ -312,11 +308,9 @@ static const double __ac_HASH_UPPER = 0.77;
khint_t x; \
if (h->n_occupied >= h->upper_bound) { /* update the hash table */ \
if (h->n_buckets > (h->size<<1)) { \
- if (kh_resize_##name(h, h->n_buckets - 1) < 0) { /* clear "deleted" elements */ \
- *ret = -1; return h->n_buckets; \
- } \
- } else if (kh_resize_##name(h, h->n_buckets + 1) < 0) { /* expand the hash table */ \
- *ret = -1; return h->n_buckets; \
+ kh_resize_##name(h, h->n_buckets - 1); /* clear "deleted" elements */ \
+ } else { \
+ kh_resize_##name(h, h->n_buckets + 1); /* expand the hash table */ \
} \
} /* TODO: to implement automatically shrinking; resize() already support shrinking */ \
{ \