diff options
author | Bram Moolenaar <Bram@vim.org> | 2017-04-30 20:25:19 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2017-04-30 20:25:19 +0200 |
commit | 45cf6e910c6d162775ca9d470fac4b6db844001f (patch) | |
tree | b0bec5c61e2b92d5deba1e71fb4f20216d1596fe /src/dict.c | |
parent | 29ae377ea7039874337bc79ace9ab2b37b9056e5 (diff) |
patch 8.0.0593: duplication of code for adding a list or dict return valuev8.0.0593
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/dict.c')
-rw-r--r-- | src/dict.c | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/src/dict.c b/src/dict.c index a26419b6d1..c13e7a45f5 100644 --- a/src/dict.c +++ b/src/dict.c @@ -59,14 +59,24 @@ rettv_dict_alloc(typval_T *rettv) if (d == NULL) return FAIL; - rettv->vval.v_dict = d; - rettv->v_type = VAR_DICT; + rettv_dict_set(rettv, d); rettv->v_lock = 0; - ++d->dv_refcount; return OK; } /* + * Set a dictionary as the return value + */ + void +rettv_dict_set(typval_T *rettv, dict_T *d) +{ + rettv->v_type = VAR_DICT; + rettv->vval.v_dict = d; + if (d != NULL) + ++d->dv_refcount; +} + +/* * Free a Dictionary, including all non-container items it contains. * Ignores the reference count. */ @@ -646,11 +656,7 @@ failret: *arg = skipwhite(*arg + 1); if (evaluate) - { - rettv->v_type = VAR_DICT; - rettv->vval.v_dict = d; - ++d->dv_refcount; - } + rettv_dict_set(rettv, d); return OK; } |