]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.0524: the recursive parameter in the *_equal functions can be removed v9.1.0524
authorYinzuo Jiang <jiangyinzuo@foxmail.com>
Thu, 4 Jul 2024 15:20:53 +0000 (17:20 +0200)
committerChristian Brabandt <cb@256bit.org>
Thu, 4 Jul 2024 15:20:53 +0000 (17:20 +0200)
Problem:  the recursive parameter in the *_equal functions can be removed
Solution: Remove the recursive parameter in dict_equal(), list_equal()
          object_equal and tv_equal(). Use a comparison of the static
          var recursive_cnt == 0 to determine whether or not tv_equal()
          has been called recursively (Yinzuo Jiang).

closes: #15070

Signed-off-by: Yinzuo Jiang <jiangyinzuo@foxmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
12 files changed:
src/dict.c
src/evalfunc.c
src/list.c
src/proto/dict.pro
src/proto/list.pro
src/proto/typval.pro
src/proto/vim9class.pro
src/testdir/test_listdict.vim
src/testing.c
src/typval.c
src/version.c
src/vim9class.c

index bf45b0b9289e359bdaf9a57a8c8a14e9c75a49f0..d3636f3bc98e1238df37153dd9ac724208056aff 100644 (file)
@@ -1222,8 +1222,7 @@ dict_lookup(hashitem_T *hi)
 dict_equal(
     dict_T     *d1,
     dict_T     *d2,
-    int                ic,         // ignore case for strings
-    int                recursive)  // TRUE when used recursively
+    int                ic)         // ignore case for strings
 {
     hashitem_T *hi;
     dictitem_T *item2;
@@ -1247,7 +1246,7 @@ dict_equal(
            item2 = dict_find(d2, hi->hi_key, -1);
            if (item2 == NULL)
                return FALSE;
-           if (!tv_equal(&HI2DI(hi)->di_tv, &item2->di_tv, ic, recursive))
+           if (!tv_equal(&HI2DI(hi)->di_tv, &item2->di_tv, ic))
                return FALSE;
            --todo;
        }
@@ -1275,7 +1274,7 @@ dict_count(dict_T *d, typval_T *needle, int ic)
        if (!HASHITEM_EMPTY(hi))
        {
            --todo;
-           if (tv_equal(&HI2DI(hi)->di_tv, needle, ic, FALSE))
+           if (tv_equal(&HI2DI(hi)->di_tv, needle, ic))
                ++n;
        }
     }
index d18d50a28405e34d92aff3c9ac446afad3140b8a..c9480f9f64829b4d11dea65cf2a183ca472c396c 100644 (file)
@@ -7535,7 +7535,7 @@ f_index(typval_T *argvars, typval_T *rettv)
        {
            tv.v_type = VAR_NUMBER;
            tv.vval.v_number = blob_get(b, idx);
-           if (tv_equal(&tv, &argvars[1], ic, FALSE))
+           if (tv_equal(&tv, &argvars[1], ic))
            {
                rettv->vval.v_number = idx;
                return;
@@ -7568,7 +7568,7 @@ f_index(typval_T *argvars, typval_T *rettv)
     }
 
     for ( ; item != NULL; item = item->li_next, ++idx)
-       if (tv_equal(&item->li_tv, &argvars[1], ic, FALSE))
+       if (tv_equal(&item->li_tv, &argvars[1], ic))
        {
            rettv->vval.v_number = idx;
            break;
index 9479b4b6abb430ee3168b43cbdbf27b217381446..36ce494df86b4b1a20b95425ac9ad6bc372c2c64 100644 (file)
@@ -365,8 +365,7 @@ list_len(list_T *l)
 list_equal(
     list_T     *l1,
     list_T     *l2,
-    int                ic,     // ignore case for strings
-    int                recursive)  // TRUE when used recursively
+    int                ic)     // ignore case for strings
 {
     listitem_T *item1, *item2;
 
@@ -386,7 +385,7 @@ list_equal(
     for (item1 = l1->lv_first, item2 = l2->lv_first;
            item1 != NULL && item2 != NULL;
                               item1 = item1->li_next, item2 = item2->li_next)
-       if (!tv_equal(&item1->li_tv, &item2->li_tv, ic, recursive))
+       if (!tv_equal(&item1->li_tv, &item2->li_tv, ic))
            return FALSE;
     return item1 == NULL && item2 == NULL;
 }
@@ -2727,7 +2726,7 @@ list_count(list_T *l, typval_T *needle, long idx, int ic)
     }
 
     for ( ; li != NULL; li = li->li_next)
-       if (tv_equal(&li->li_tv, needle, ic, FALSE))
+       if (tv_equal(&li->li_tv, needle, ic))
            ++n;
 
     return n;
index 346e1d5411cf352b9f46495465fdc58fac69311d..b1ceeccd4cdca18ff8f26d2ac9e55a35901e83e7 100644 (file)
@@ -40,7 +40,7 @@ int eval_dict(char_u **arg, typval_T *rettv, evalarg_T *evalarg, int literal);
 int eval_lit_dict(char_u **arg, typval_T *rettv, evalarg_T *evalarg);
 void dict_extend(dict_T *d1, dict_T *d2, char_u *action, char *func_name);
 dictitem_T *dict_lookup(hashitem_T *hi);
-int dict_equal(dict_T *d1, dict_T *d2, int ic, int recursive);
+int dict_equal(dict_T *d1, dict_T *d2, int ic);
 long dict_count(dict_T *d, typval_T *needle, int ic);
 void dict_extend_func(typval_T *argvars, type_T *type, char *func_name, char_u *arg_errmsg, int is_new, typval_T *rettv);
 void dict_filter_map(dict_T *d, filtermap_T filtermap, type_T *argtype, char *func_name, char_u *arg_errmsg, typval_T *expr, typval_T *rettv);
index 1659b8fded23d972f048e0093562ede97102090a..27bea5e8789e908bc5d32694042973c5b3b2ba67 100644 (file)
@@ -16,7 +16,7 @@ listitem_T *listitem_alloc(void);
 void listitem_free(list_T *l, listitem_T *item);
 void listitem_remove(list_T *l, listitem_T *item);
 long list_len(list_T *l);
-int list_equal(list_T *l1, list_T *l2, int ic, int recursive);
+int list_equal(list_T *l1, list_T *l2, int ic);
 listitem_T *list_find(list_T *l, long n);
 long list_find_nr(list_T *l, long idx, int *errorp);
 char_u *list_find_str(list_T *l, long idx);
index b6ea1310fdf748448b26cdc2c5785ccab4c9c93b..c25a949e4a0a654b00c7b5d81a152834a3d9b58b 100644 (file)
@@ -75,7 +75,7 @@ int typval_compare_func(typval_T *tv1, typval_T *tv2, exprtype_T type, int ic, i
 int typval_compare_string(typval_T *tv1, typval_T *tv2, exprtype_T type, int ic, int *res);
 char_u *typval_tostring(typval_T *arg, int quotes);
 int tv_islocked(typval_T *tv);
-int tv_equal(typval_T *tv1, typval_T *tv2, int ic, int recursive);
+int tv_equal(typval_T *tv1, typval_T *tv2, int ic);
 int eval_option(char_u **arg, typval_T *rettv, int evaluate);
 int eval_number(char_u **arg, typval_T *rettv, int evaluate, int want_string);
 int eval_string(char_u **arg, typval_T *rettv, int evaluate, int interpolate);
index 4c733d52354ab5f1e712425817737d92321d7637..c87fffbc8ac3b8ec580bc237dd86a99f09cc39eb 100644 (file)
@@ -40,7 +40,7 @@ int is_class_name(char_u *name, typval_T *rettv);
 void protected_method_access_errmsg(char_u *method_name);
 int object_empty(object_T *obj);
 int object_len(object_T *obj);
-int object_equal(object_T *o1, object_T *o2, int ic, int recursive);
+int object_equal(object_T *o1, object_T *o2, int ic);
 char_u *object2string(object_T *obj, char_u *numbuf, int copyID, int echo_style, int restore_copyID, int composite_val);
 int class_instance_of(class_T *cl, class_T *other_cl);
 void f_instanceof(typval_T *argvars, typval_T *rettv);
index f2d4a3e7534ff408fee0453f7e9ed973d98f6280..0a4f88c4e5571a55bb15526c55818ed384e27aef 100644 (file)
@@ -1147,6 +1147,19 @@ func Test_listdict_compare()
   call assert_fails('echo {} =~ {}', 'E736:')
 endfunc
 
+func Test_recursive_listdict_compare()
+  let l1 = [0, 1]
+  let l1[0] = l1
+  let l2 = [0, 1]
+  let l2[0] = l2
+  call assert_true(l1 == l2)
+  let d1 = {0: 0, 1: 1}
+  let d1[0] = d1
+  let d2 = {0: 0, 1: 1}
+  let d2[0] = d2
+  call assert_true(d1 == d2)
+endfunc
+
   " compare complex recursively linked list and dict
 func Test_listdict_compare_complex()
   let lines =<< trim END
index 3e9e07704b1bedf24156a1b7f0c63a4073bf4b81..18b8e788eb7f262c758d116f1858e38c3ec9f65e 100644 (file)
@@ -187,7 +187,7 @@ fill_assert_error(
                {
                    item2 = dict_find(got_d, hi->hi_key, -1);
                    if (item2 == NULL || !tv_equal(&HI2DI(hi)->di_tv,
-                                                 &item2->di_tv, FALSE, FALSE))
+                                                 &item2->di_tv, FALSE))
                    {
                        // item of exp_d not present in got_d or values differ.
                        dict_add_tv(exp_tv->vval.v_dict,
@@ -262,7 +262,7 @@ assert_equal_common(typval_T *argvars, assert_type_T atype)
 {
     garray_T   ga;
 
-    if (tv_equal(&argvars[0], &argvars[1], FALSE, FALSE)
+    if (tv_equal(&argvars[0], &argvars[1], FALSE)
                                                   != (atype == ASSERT_EQUAL))
     {
        prepare_assert_error(&ga);
index d1fa227d1d40a08fc2b5978f1a41d6afd8d5da6c..164b7a98ba11fab8fbbd73fd82efde99d1b1e215 100644 (file)
@@ -1605,8 +1605,7 @@ typval_compare_list(
     }
     else
     {
-       val = list_equal(tv1->vval.v_list, tv2->vval.v_list,
-                                                       ic, FALSE);
+       val = list_equal(tv1->vval.v_list, tv2->vval.v_list, ic);
        if (type == EXPR_NEQUAL)
            val = !val;
     }
@@ -1750,7 +1749,7 @@ typval_compare_object(
        return OK;
     }
 
-    *res = object_equal(obj1, obj2, ic, FALSE) ? res_match : !res_match;
+    *res = object_equal(obj1, obj2, ic) ? res_match : !res_match;
     return OK;
 }
 
@@ -1787,7 +1786,7 @@ typval_compare_dict(
     }
     else
     {
-       val = dict_equal(tv1->vval.v_dict, tv2->vval.v_dict, ic, FALSE);
+       val = dict_equal(tv1->vval.v_dict, tv2->vval.v_dict, ic);
        if (type == EXPR_NEQUAL)
            val = !val;
     }
@@ -1826,14 +1825,14 @@ typval_compare_func(
        if (tv1->v_type == VAR_FUNC && tv2->v_type == VAR_FUNC)
            // strings are considered the same if their value is
            // the same
-           val = tv_equal(tv1, tv2, ic, FALSE);
+           val = tv_equal(tv1, tv2, ic);
        else if (tv1->v_type == VAR_PARTIAL && tv2->v_type == VAR_PARTIAL)
            val = (tv1->vval.v_partial == tv2->vval.v_partial);
        else
            val = FALSE;
     }
     else
-       val = tv_equal(tv1, tv2, ic, FALSE);
+       val = tv_equal(tv1, tv2, ic);
     if (type == EXPR_NEQUAL || type == EXPR_ISNOT)
        val = !val;
     *res = val;
@@ -1988,7 +1987,7 @@ func_equal(
        if (d1 != d2)
            return FALSE;
     }
-    else if (!dict_equal(d1, d2, ic, TRUE))
+    else if (!dict_equal(d1, d2, ic))
        return FALSE;
 
     // empty list and no list considered the same
@@ -1998,7 +1997,7 @@ func_equal(
        return FALSE;
     for (i = 0; i < a1; ++i)
        if (!tv_equal(tv1->vval.v_partial->pt_argv + i,
-                     tv2->vval.v_partial->pt_argv + i, ic, TRUE))
+                     tv2->vval.v_partial->pt_argv + i, ic))
            return FALSE;
 
     return TRUE;
@@ -2013,8 +2012,7 @@ func_equal(
 tv_equal(
     typval_T *tv1,
     typval_T *tv2,
-    int             ic,            // ignore case
-    int             recursive)     // TRUE when used recursively
+    int             ic)            // ignore case
 {
     char_u     buf1[NUMBUFLEN], buf2[NUMBUFLEN];
     char_u     *s1, *s2;
@@ -2028,7 +2026,7 @@ tv_equal(
     // Reduce the limit every time running into it. That should work fine for
     // deeply linked structures that are not recursively linked and catch
     // recursiveness quickly.
-    if (!recursive)
+    if (recursive_cnt == 0)
        tv_equal_recurse_limit = 1000;
     if (recursive_cnt >= tv_equal_recurse_limit)
     {
@@ -2058,13 +2056,13 @@ tv_equal(
     {
        case VAR_LIST:
            ++recursive_cnt;
-           r = list_equal(tv1->vval.v_list, tv2->vval.v_list, ic, TRUE);
+           r = list_equal(tv1->vval.v_list, tv2->vval.v_list, ic);
            --recursive_cnt;
            return r;
 
        case VAR_DICT:
            ++recursive_cnt;
-           r = dict_equal(tv1->vval.v_dict, tv2->vval.v_dict, ic, TRUE);
+           r = dict_equal(tv1->vval.v_dict, tv2->vval.v_dict, ic);
            --recursive_cnt;
            return r;
 
@@ -2100,7 +2098,7 @@ tv_equal(
 
        case VAR_OBJECT:
            ++recursive_cnt;
-           r = object_equal(tv1->vval.v_object, tv2->vval.v_object, ic, TRUE);
+           r = object_equal(tv1->vval.v_object, tv2->vval.v_object, ic);
            --recursive_cnt;
            return r;
 
index 6588f2f9add0f0b2f52bf6f0d0e16c72c4fcccad..47b60760be4bdd350164ce6254ed82d60d507d9b 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    524,
 /**/
     523,
 /**/
index 78f5ab8ada6d3eda90d155bf8f386becb9395ef5..933708288fb92b0d07ffe943dc54ce1338ff2e24 100644 (file)
@@ -3849,8 +3849,7 @@ object_len(object_T *obj)
 object_equal(
        object_T *o1,
        object_T *o2,
-       int             ic,     // ignore case for strings
-       int             recursive)  // TRUE when used recursively
+       int     ic)     // ignore case for strings
 {
     class_T *cl1, *cl2;
 
@@ -3866,7 +3865,7 @@ object_equal(
        return FALSE;
 
     for (int i = 0; i < cl1->class_obj_member_count; ++i)
-       if (!tv_equal((typval_T *)(o1 + 1) + i, (typval_T *)(o2 + 1) + i, ic, recursive))
+       if (!tv_equal((typval_T *)(o1 + 1) + i, (typval_T *)(o2 + 1) + i, ic))
            return FALSE;
 
     return TRUE;