summaryrefslogtreecommitdiff
path: root/src/list.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2017-04-30 20:25:19 +0200
committerBram Moolenaar <Bram@vim.org>2017-04-30 20:25:19 +0200
commit45cf6e910c6d162775ca9d470fac4b6db844001f (patch)
treeb0bec5c61e2b92d5deba1e71fb4f20216d1596fe /src/list.c
parent29ae377ea7039874337bc79ace9ab2b37b9056e5 (diff)
downloadvim-45cf6e910c6d162775ca9d470fac4b6db844001f.zip
patch 8.0.0593: duplication of code for adding a list or dict return value
Problem: Duplication of code for adding a list or dict return value. Solution: Add rettv_dict_set() and rettv_list_set(). (Yegappan Lakshmanan)
Diffstat (limited to 'src/list.c')
-rw-r--r--src/list.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/list.c b/src/list.c
index 50d38ff87..2fccbae76 100644
--- a/src/list.c
+++ b/src/list.c
@@ -97,14 +97,24 @@ rettv_list_alloc(typval_T *rettv)
if (l == NULL)
return FAIL;
- rettv->vval.v_list = l;
- rettv->v_type = VAR_LIST;
rettv->v_lock = 0;
- ++l->lv_refcount;
+ rettv_list_set(rettv, l);
return OK;
}
/*
+ * Set a list as the return value
+ */
+ void
+rettv_list_set(typval_T *rettv, list_T *l)
+{
+ rettv->v_type = VAR_LIST;
+ rettv->vval.v_list = l;
+ if (l != NULL)
+ ++l->lv_refcount;
+}
+
+/*
* Unreference a list: decrement the reference count and free it when it
* becomes zero.
*/
@@ -875,11 +885,7 @@ failret:
*arg = skipwhite(*arg + 1);
if (evaluate)
- {
- rettv->v_type = VAR_LIST;
- rettv->vval.v_list = l;
- ++l->lv_refcount;
- }
+ rettv_list_set(rettv, l);
return OK;
}