Mercurial > vim
comparison src/dict.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 | a54985a73ab2 |
children | 6e81a68d63a1 |
comparison
equal
deleted
inserted
replaced
11417:47bfa931b0e7 | 11418:162bcd0debd7 |
---|---|
57 dict_T *d = dict_alloc(); | 57 dict_T *d = dict_alloc(); |
58 | 58 |
59 if (d == NULL) | 59 if (d == NULL) |
60 return FAIL; | 60 return FAIL; |
61 | 61 |
62 rettv_dict_set(rettv, d); | |
63 rettv->v_lock = 0; | |
64 return OK; | |
65 } | |
66 | |
67 /* | |
68 * Set a dictionary as the return value | |
69 */ | |
70 void | |
71 rettv_dict_set(typval_T *rettv, dict_T *d) | |
72 { | |
73 rettv->v_type = VAR_DICT; | |
62 rettv->vval.v_dict = d; | 74 rettv->vval.v_dict = d; |
63 rettv->v_type = VAR_DICT; | 75 if (d != NULL) |
64 rettv->v_lock = 0; | 76 ++d->dv_refcount; |
65 ++d->dv_refcount; | |
66 return OK; | |
67 } | 77 } |
68 | 78 |
69 /* | 79 /* |
70 * Free a Dictionary, including all non-container items it contains. | 80 * Free a Dictionary, including all non-container items it contains. |
71 * Ignores the reference count. | 81 * Ignores the reference count. |
644 return FAIL; | 654 return FAIL; |
645 } | 655 } |
646 | 656 |
647 *arg = skipwhite(*arg + 1); | 657 *arg = skipwhite(*arg + 1); |
648 if (evaluate) | 658 if (evaluate) |
649 { | 659 rettv_dict_set(rettv, d); |
650 rettv->v_type = VAR_DICT; | |
651 rettv->vval.v_dict = d; | |
652 ++d->dv_refcount; | |
653 } | |
654 | 660 |
655 return OK; | 661 return OK; |
656 } | 662 } |
657 | 663 |
658 /* | 664 /* |