*: Remove most calls to tv_list_item_alloc

Still left calls in eval/typval.c and test/unit/eval/helpers.lua. Latter is the 
only reason why function did not receive `static` modifier.
This commit is contained in:
ZyX
2017-12-24 01:43:42 +03:00
parent 249bdb07dd
commit 0c533a488f
6 changed files with 179 additions and 116 deletions

View File

@@ -212,19 +212,27 @@ bool nlua_pop_typval(lua_State *lstate, typval_T *ret_tv)
const char *s = lua_tolstring(lstate, -2, &len);
if (cur.special) {
list_T *const kv_pair = tv_list_alloc();
tv_list_append_list(cur.tv->vval.v_list, kv_pair);
listitem_T *const key = tv_list_item_alloc();
*TV_LIST_ITEM_TV(key) = decode_string(s, len, kTrue, false, false);
tv_list_append(kv_pair, key);
if (TV_LIST_ITEM_TV(key)->v_type == VAR_UNKNOWN) {
typval_T s_tv = decode_string(s, len, kTrue, false, false);
if (s_tv.v_type == VAR_UNKNOWN) {
ret = false;
tv_list_unref(kv_pair);
continue;
}
listitem_T *const val = tv_list_item_alloc();
tv_list_append(kv_pair, val);
tv_list_append_owned_tv(kv_pair, s_tv);
// Value: not populated yet, need to create list item to push.
tv_list_append_owned_tv(kv_pair, (typval_T) {
.v_type = VAR_UNKNOWN,
});
kv_push(stack, cur);
cur = (TVPopStackItem) { TV_LIST_ITEM_TV(val), false, false, 0 };
cur = (TVPopStackItem) {
.tv = TV_LIST_ITEM_TV(tv_list_last(kv_pair)),
.container = false,
.special = false,
.idx = 0,
};
} else {
dictitem_T *const di = tv_dict_item_alloc_len(s, len);
if (tv_dict_add(cur.tv->vval.v_dict, di) == FAIL) {
@@ -244,10 +252,18 @@ bool nlua_pop_typval(lua_State *lstate, typval_T *ret_tv)
lua_pop(lstate, 2);
continue;
}
listitem_T *const li = tv_list_item_alloc();
tv_list_append(cur.tv->vval.v_list, li);
// Not populated yet, need to create list item to push.
tv_list_append_owned_tv(cur.tv->vval.v_list, (typval_T) {
.v_type = VAR_UNKNOWN,
});
kv_push(stack, cur);
cur = (TVPopStackItem) { TV_LIST_ITEM_TV(li), false, false, 0 };
// TODO(ZyX-I): Use indexes, here list item *will* be reallocated.
cur = (TVPopStackItem) {
.tv = TV_LIST_ITEM_TV(tv_list_last(cur.tv->vval.v_list)),
.container = false,
.special = false,
.idx = 0,
};
}
}
assert(!cur.container);