Project

General

Profile

Bug #1885 ยป struct_comparison.diff

marcandre (Marc-Andre Lafortune), 08/31/2009 04:17 AM

View differences:

struct.c (working copy)
768 768
    return result;
769 769
}
770 770

  
771
static VALUE
772
recursive_equal(VALUE s, VALUE s2, int recur)
773
{
774
    long i;
775

  
776
    if (recur) return Qtrue; /* Subtle! */
777
    for (i=0; i<RSTRUCT_LEN(s); i++) {
778
	if (!rb_eql(RSTRUCT_PTR(s)[i], RSTRUCT_PTR(s2)[i])) return Qfalse;
779
    }
780
    return Qtrue;
781
}
782

  
771 783
/*
772 784
 *  call-seq:
773 785
 *     struct == other_struct     => true or false
......
788 800
static VALUE
789 801
rb_struct_equal(VALUE s, VALUE s2)
790 802
{
791
    long i;
792

  
793 803
    if (s == s2) return Qtrue;
794 804
    if (TYPE(s2) != T_STRUCT) return Qfalse;
795 805
    if (rb_obj_class(s) != rb_obj_class(s2)) return Qfalse;
......
797 807
	rb_bug("inconsistent struct"); /* should never happen */
798 808
    }
799 809

  
800
    for (i=0; i<RSTRUCT_LEN(s); i++) {
801
	if (!rb_equal(RSTRUCT_PTR(s)[i], RSTRUCT_PTR(s2)[i])) return Qfalse;
802
    }
803
    return Qtrue;
810
    return rb_exec_recursive_paired(recursive_equal, s, s2, s2);
804 811
}
805 812

  
806 813
static VALUE
......
835 842
    return rb_exec_recursive(recursive_hash, s, 0);
836 843
}
837 844

  
845
static VALUE
846
recursive_eql(VALUE s, VALUE s2, int recur)
847
{
848
    long i;
849

  
850
    if (recur) return Qtrue; /* Subtle! */
851
    for (i=0; i<RSTRUCT_LEN(s); i++) {
852
	if (!rb_eql(RSTRUCT_PTR(s)[i], RSTRUCT_PTR(s2)[i])) return Qfalse;
853
    }
854
    return Qtrue;
855
}
856

  
838 857
/*
839 858
 * code-seq:
840 859
 *   struct.eql?(other)   => true or false
......
846 865
static VALUE
847 866
rb_struct_eql(VALUE s, VALUE s2)
848 867
{
849
    long i;
850

  
851 868
    if (s == s2) return Qtrue;
852 869
    if (TYPE(s2) != T_STRUCT) return Qfalse;
853 870
    if (rb_obj_class(s) != rb_obj_class(s2)) return Qfalse;
......
855 872
	rb_bug("inconsistent struct"); /* should never happen */
856 873
    }
857 874

  
858
    for (i=0; i<RSTRUCT_LEN(s); i++) {
859
	if (!rb_eql(RSTRUCT_PTR(s)[i], RSTRUCT_PTR(s2)[i])) return Qfalse;
860
    }
861
    return Qtrue;
875
    return rb_exec_recursive_paired(recursive_eql, s, s2, s2);
862 876
}
863 877

  
864 878
/*