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);
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);
return OK;
}
- class_T *cl1 = tv1->vval.v_object->obj_class;
- class_T *cl2 = tv2->vval.v_object->obj_class;
- if (cl1 != cl2 || cl1 == NULL || cl2 == NULL)
- {
- *res = !res_match;
- return OK;
- }
-
object_T *obj1 = tv1->vval.v_object;
object_T *obj2 = tv2->vval.v_object;
if (type == EXPR_IS || type == EXPR_ISNOT)
return OK;
}
- for (int i = 0; i < cl1->class_obj_member_count; ++i)
- if (!tv_equal((typval_T *)(obj1 + 1) + i,
- (typval_T *)(obj2 + 1) + i, ic, TRUE))
- {
- *res = !res_match;
- return OK;
- }
- *res = res_match;
+ *res = object_equal(obj1, obj2, ic, FALSE) ? res_match : !res_match;
return OK;
}
case VAR_OBJECT:
++recursive_cnt;
- (void)typval_compare_object(tv1, tv2, EXPR_EQUAL, ic, &r);
+ r = object_equal(tv1->vval.v_object, tv2->vval.v_object, ic, TRUE);
--recursive_cnt;
return r;
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 514,
/**/
513,
/**/
return tv_to_number(&rettv);
}
+/*
+ * Return TRUE when two objects have exactly the same values.
+ */
+ int
+object_equal(
+ object_T *o1,
+ object_T *o2,
+ int ic, // ignore case for strings
+ int recursive) // TRUE when used recursively
+{
+ class_T *cl1, *cl2;
+
+ if (o1 == o2)
+ return TRUE;
+
+ cl1 = o1->obj_class;
+ cl2 = o2->obj_class;
+
+ if (cl1 != cl2 || cl1 == NULL || cl2 == NULL)
+ 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))
+ return FALSE;
+
+ return TRUE;
+}
+
/*
* Return a textual representation of object "obj"
*/