From 9f0a4220decbb0adaf8aa63d506cf01c55e3204c Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Wed, 14 Feb 2018 11:42:36 +0000 Subject: [Feature] Allow to reserve elements in libucl --- contrib/libucl/ucl_hash.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'contrib/libucl/ucl_hash.c') diff --git a/contrib/libucl/ucl_hash.c b/contrib/libucl/ucl_hash.c index 0bb8759f6..ce2a4fdb5 100644 --- a/contrib/libucl/ucl_hash.c +++ b/contrib/libucl/ucl_hash.c @@ -395,3 +395,25 @@ ucl_hash_delete (ucl_hash_t* hashlin, const ucl_object_t *obj) } } } + +void ucl_hash_reserve (ucl_hash_t *hashlin, size_t sz) +{ + if (hashlin == NULL) { + return; + } + + if (sz > hashlin->ar.m) { + kv_resize (const ucl_object_t *, hashlin->ar, sz); + + if (hashlin->caseless) { + khash_t(ucl_hash_caseless_node) *h = (khash_t( + ucl_hash_caseless_node) *) + hashlin->hash; + kh_resize (ucl_hash_caseless_node, h, sz); + } else { + khash_t(ucl_hash_node) *h = (khash_t(ucl_hash_node) *) + hashlin->hash; + kh_resize (ucl_hash_node, h, sz); + } + } +} \ No newline at end of file -- cgit v1.2.3