lua_pop (L, 1);
}
}
- else if (is_array) {
+
+ if (is_array) {
#if LUA_VERSION_NUM >= 502
max = lua_rawlen (L, idx);
#else
UCL_EXTERN bool ucl_object_insert_key_merged (ucl_object_t *top, ucl_object_t *elt,
const char *key, size_t keylen, bool copy_key);
+/**
+ * Reserve space in ucl array or object for `elt` elements
+ * @param obj object to reserve
+ * @param reserved size to reserve in an object
+ */
+UCL_EXTERN void ucl_object_reserve (ucl_object_t *obj, size_t reserved);
+
/**
* Append an element to the end of array object
* @param top destination object (must NOT be NULL)
}
}
}
+
+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
*/
bool ucl_hash_iter_has_next (ucl_hash_t *hashlin, ucl_hash_iter_t iter);
+/**
+ * Reserves space in hash
+ * @param hashlin
+ */
+void ucl_hash_reserve (ucl_hash_t *hashlin, size_t sz);
+
#endif
return new;
}
+void ucl_object_reserve (ucl_object_t *obj, size_t reserved)
+{
+ if (obj->type == UCL_ARRAY) {
+ UCL_ARRAY_GET (vec, obj);
+
+ if (vec->m < reserved) {
+ /* Preallocate some space for arrays */
+ kv_resize (ucl_object_t *, *vec, reserved);
+ }
+ }
+ else if (obj->type == UCL_OBJECT) {
+ ucl_hash_reserve (obj->value.ov, reserved);
+ }
+}
+
ucl_object_t*
ucl_object_new_userdata (ucl_userdata_dtor dtor,
ucl_userdata_emitter emitter,