diff options
author | Jan Edmund Lazo <jan.lazo@mail.utoronto.ca> | 2018-06-30 08:16:10 -0400 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2018-06-30 14:16:10 +0200 |
commit | 70626e6a1eb9c82a5eb4e3b55abfd474908ef501 (patch) | |
tree | 53e3e5d7939ce195a86daf9c55a8b28dd5d4f5ed /src/nvim/eval/typval.h | |
parent | d088331ea3a6e91d5c3ef8c4cff7280805515819 (diff) | |
download | rneovim-70626e6a1eb9c82a5eb4e3b55abfd474908ef501.tar.gz rneovim-70626e6a1eb9c82a5eb4e3b55abfd474908ef501.tar.bz2 rneovim-70626e6a1eb9c82a5eb4e3b55abfd474908ef501.zip |
vim-patch:8.0.0593: DRY: setting list/dict return value (#8639)
Problem: Duplication of code for adding a list or dict return value.
Solution: Add rettv_dict_set() and rettv_list_set(). (Yegappan Lakshmanan)
https://github.com/vim/vim/commit/45cf6e910c6d162775ca9d470fac4b6db844001f
Diffstat (limited to 'src/nvim/eval/typval.h')
-rw-r--r-- | src/nvim/eval/typval.h | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/src/nvim/eval/typval.h b/src/nvim/eval/typval.h index 33e2aa6b61..664bf7332c 100644 --- a/src/nvim/eval/typval.h +++ b/src/nvim/eval/typval.h @@ -413,11 +413,14 @@ static inline void list_log(const list_T *const l, #define TV_DICT_HI2DI(hi) \ ((dictitem_T *)((hi)->hi_key - offsetof(dictitem_T, di_key))) +static inline void tv_list_ref(list_T *const l) + REAL_FATTR_ALWAYS_INLINE; + /// Increase reference count for a given list /// /// Does nothing for NULL lists. /// -/// @param[in] l List to modify. +/// @param[in,out] l List to modify. static inline void tv_list_ref(list_T *const l) { if (l == NULL) { @@ -426,6 +429,20 @@ static inline void tv_list_ref(list_T *const l) l->lv_refcount++; } +static inline void tv_list_set_ret(typval_T *const tv, list_T *const l) + REAL_FATTR_ALWAYS_INLINE REAL_FATTR_NONNULL_ARG(1); + +/// Set a list as the return value +/// +/// @param[out] tv Object to receive the list +/// @param[in,out] l List to pass to the object +static inline void tv_list_set_ret(typval_T *const tv, list_T *const l) +{ + tv->v_type = VAR_LIST; + tv->vval.v_list = l; + tv_list_ref(l); +} + static inline VarLockStatus tv_list_locked(const list_T *const l) REAL_FATTR_PURE REAL_FATTR_WARN_UNUSED_RESULT; @@ -588,6 +605,22 @@ static inline listitem_T *tv_list_last(const list_T *const l) return l->lv_last; } +static inline void tv_dict_set_ret(typval_T *const tv, dict_T *const d) + REAL_FATTR_ALWAYS_INLINE REAL_FATTR_NONNULL_ARG(1); + +/// Set a dictionary as the return value +/// +/// @param[out] tv Object to receive the dictionary +/// @param[in,out] d Dictionary to pass to the object +static inline void tv_dict_set_ret(typval_T *const tv, dict_T *const d) +{ + tv->v_type = VAR_DICT; + tv->vval.v_dict = d; + if (d != NULL) { + d->dv_refcount++; + } +} + static inline long tv_dict_len(const dict_T *const d) REAL_FATTR_PURE REAL_FATTR_WARN_UNUSED_RESULT; |