diff src/dict.c @ 28315:62cc3b60493b v8.2.4683

patch 8.2.4683: verbose check with dict_find() to see if a key is present Commit: https://github.com/vim/vim/commit/4829c1c9e9095a3303caec9af7d02f6547f6df0e Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Mon Apr 4 15:16:54 2022 +0100 patch 8.2.4683: verbose check with dict_find() to see if a key is present Problem: Verbose check with dict_find() to see if a key is present. Solution: Add dict_has_key(). (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/10074)
author Bram Moolenaar <Bram@vim.org>
date Mon, 04 Apr 2022 16:30:04 +0200
parents 2397b18d6f94
children 3626ca6a20ea
line wrap: on
line diff
--- a/src/dict.c
+++ b/src/dict.c
@@ -649,6 +649,15 @@ dict_find(dict_T *d, char_u *key, int le
 }
 
 /*
+ * Returns TRUE if "key" is present in Dictionary "d".
+ */
+    int
+dict_has_key(dict_T *d, char *key)
+{
+    return dict_find(d, (char_u *)key, -1) != NULL;
+}
+
+/*
  * Get a typval_T item from a dictionary and copy it into "rettv".
  * Returns FAIL if the entry doesn't exist or out of memory.
  */
@@ -1582,8 +1591,8 @@ f_has_key(typval_T *argvars, typval_T *r
     if (argvars[0].vval.v_dict == NULL)
 	return;
 
-    rettv->vval.v_number = dict_find(argvars[0].vval.v_dict,
-				      tv_get_string(&argvars[1]), -1) != NULL;
+    rettv->vval.v_number = dict_has_key(argvars[0].vval.v_dict,
+				(char *)tv_get_string(&argvars[1]));
 }
 
 #endif // defined(FEAT_EVAL)