aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/lua/converter.c
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2017-12-31 01:11:50 +0100
committerGitHub <noreply@github.com>2017-12-31 01:11:50 +0100
commit9ad557fb2d4a1ef3101c7894a1038aa2eb932a48 (patch)
tree0664208e25fd4672c05527e4521299452da44961 /src/nvim/lua/converter.c
parent46f432074e739a0eca9bb204e9c7769935669dbd (diff)
parent8ac7c23b7dd7c435fb80315921e3704c8e0a7448 (diff)
downloadrneovim-9ad557fb2d4a1ef3101c7894a1038aa2eb932a48.tar.gz
rneovim-9ad557fb2d4a1ef3101c7894a1038aa2eb932a48.tar.bz2
rneovim-9ad557fb2d4a1ef3101c7894a1038aa2eb932a48.zip
Merge pull request #7762 from ZyX-I/remove-some-listitems
Remove some tv_list_item_…() functions
Diffstat (limited to 'src/nvim/lua/converter.c')
-rw-r--r--src/nvim/lua/converter.c38
1 files changed, 27 insertions, 11 deletions
diff --git a/src/nvim/lua/converter.c b/src/nvim/lua/converter.c
index 8303ecdd37..61cb428923 100644
--- a/src/nvim/lua/converter.c
+++ b/src/nvim/lua/converter.c
@@ -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 };
+ tv_list_append_list(cur.tv->vval.v_list, kv_pair);
+ 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);