aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/api/private/helpers.c
diff options
context:
space:
mode:
authorBjörn Linse <bjorn.linse@gmail.com>2016-09-15 20:41:16 +0200
committerGitHub <noreply@github.com>2016-09-15 20:41:16 +0200
commitc4199d1866f4159fc14aff85d5e896d240c5ca3d (patch)
treea581b0162b847d20f142706c9085bcf405cc0697 /src/nvim/api/private/helpers.c
parentfee961c8ddda9de00db19895e189a174896d6534 (diff)
parentcd08e6cf72b52fb23aa4556889f35759062c5bf9 (diff)
downloadrneovim-c4199d1866f4159fc14aff85d5e896d240c5ca3d.tar.gz
rneovim-c4199d1866f4159fc14aff85d5e896d240c5ca3d.tar.bz2
rneovim-c4199d1866f4159fc14aff85d5e896d240c5ca3d.zip
Merge pull request #5336 from bfredl/del_var
make del_var and set_var not return the old value.
Diffstat (limited to 'src/nvim/api/private/helpers.c')
-rw-r--r--src/nvim/api/private/helpers.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c
index 3735139a07..fc114bae16 100644
--- a/src/nvim/api/private/helpers.c
+++ b/src/nvim/api/private/helpers.c
@@ -104,10 +104,11 @@ Object dict_get_value(dict_T *dict, String key, Error *err)
/// @param value The new value
/// @param del Delete key in place of setting it. Argument `value` is ignored in
/// this case.
+/// @param retval If true the old value will be converted and returned.
/// @param[out] err Details of an error that may have occurred
-/// @return the old value, if any
+/// @return The old value if `retval` is true and the key was present, else NIL
Object dict_set_value(dict_T *dict, String key, Object value, bool del,
- Error *err)
+ bool retval, Error *err)
{
Object rv = OBJECT_INIT;
@@ -135,7 +136,9 @@ Object dict_set_value(dict_T *dict, String key, Object value, bool del,
api_set_error(err, Validation, _("Key \"%s\" doesn't exist"), key.data);
} else {
// Return the old value
- rv = vim_to_object(&di->di_tv);
+ if (retval) {
+ rv = vim_to_object(&di->di_tv);
+ }
// Delete the entry
hashitem_T *hi = hash_find(&dict->dv_hashtab, di->di_key);
hash_remove(&dict->dv_hashtab, hi);
@@ -156,7 +159,9 @@ Object dict_set_value(dict_T *dict, String key, Object value, bool del,
dict_add(dict, di);
} else {
// Return the old value
- rv = vim_to_object(&di->di_tv);
+ if (retval) {
+ rv = vim_to_object(&di->di_tv);
+ }
clear_tv(&di->di_tv);
}