Mercurial > vim
diff src/list.c @ 11418:162bcd0debd7 v8.0.0593
patch 8.0.0593: duplication of code for adding a list or dict return value
commit https://github.com/vim/vim/commit/45cf6e910c6d162775ca9d470fac4b6db844001f
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Apr 30 20:25:19 2017 +0200
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)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 30 Apr 2017 20:30:04 +0200 |
parents | 055b1633aed7 |
children | aec3df2af27c |
line wrap: on
line diff
--- a/src/list.c +++ b/src/list.c @@ -97,11 +97,21 @@ rettv_list_alloc(typval_T *rettv) if (l == NULL) return FAIL; - rettv->vval.v_list = l; + rettv->v_lock = 0; + 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->v_lock = 0; - ++l->lv_refcount; - return OK; + rettv->vval.v_list = l; + if (l != NULL) + ++l->lv_refcount; } /* @@ -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; }