diff options
author | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-11-27 02:54:29 +0000 |
---|---|---|
committer | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-11-27 02:54:29 +0000 |
commit | 6e6417c8d38afced7eb7c10781f20f7b19ebbc89 (patch) | |
tree | a0e48c71d1584691383297d9c7f46cdc300ad8a3 /struct.c | |
parent | 9abf98bbe47b65dbc058b8ab752aa81ba8c7754b (diff) |
merges r25010 from trunk into ruby_1_9_1 and adds tests for it.
--
* struct.c (rb_struct_equal, rb_struct_eql): Handle comparison of recursive structures [ruby-core:24759]
* range.c (range_eq, range_eql): ditto for ranges
--
test for r25010
* test/ruby/test_struct.rb (TestStruct#test_comparison_when_recursive):
new test.
* test/ruby/test_range.rb (TestRange#test_comparison_when_recursive):
new test.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_1@25943 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'struct.c')
-rw-r--r-- | struct.c | 38 |
1 files changed, 26 insertions, 12 deletions
@@ -760,6 +760,18 @@ rb_struct_select(int argc, VALUE *argv, VALUE s) return result; } +static VALUE +recursive_equal(VALUE s, VALUE s2, int recur) +{ + long i; + + if (recur) return Qtrue; /* Subtle! */ + for (i=0; i<RSTRUCT_LEN(s); i++) { + if (!rb_equal(RSTRUCT_PTR(s)[i], RSTRUCT_PTR(s2)[i])) return Qfalse; + } + return Qtrue; +} + /* * call-seq: * struct == other_struct => true or false @@ -780,8 +792,6 @@ rb_struct_select(int argc, VALUE *argv, VALUE s) static VALUE rb_struct_equal(VALUE s, VALUE s2) { - long i; - if (s == s2) return Qtrue; if (TYPE(s2) != T_STRUCT) return Qfalse; if (rb_obj_class(s) != rb_obj_class(s2)) return Qfalse; @@ -789,10 +799,7 @@ rb_struct_equal(VALUE s, VALUE s2) rb_bug("inconsistent struct"); /* should never happen */ } - for (i=0; i<RSTRUCT_LEN(s); i++) { - if (!rb_equal(RSTRUCT_PTR(s)[i], RSTRUCT_PTR(s2)[i])) return Qfalse; - } - return Qtrue; + return rb_exec_recursive_paired(recursive_equal, s, s2, s2); } /* @@ -817,6 +824,18 @@ rb_struct_hash(VALUE s) return LONG2FIX(h); } +static VALUE +recursive_eql(VALUE s, VALUE s2, int recur) +{ + long i; + + if (recur) return Qtrue; /* Subtle! */ + for (i=0; i<RSTRUCT_LEN(s); i++) { + if (!rb_eql(RSTRUCT_PTR(s)[i], RSTRUCT_PTR(s2)[i])) return Qfalse; + } + return Qtrue; +} + /* * code-seq: * struct.eql?(other) => true or false @@ -828,8 +847,6 @@ rb_struct_hash(VALUE s) static VALUE rb_struct_eql(VALUE s, VALUE s2) { - long i; - if (s == s2) return Qtrue; if (TYPE(s2) != T_STRUCT) return Qfalse; if (rb_obj_class(s) != rb_obj_class(s2)) return Qfalse; @@ -837,10 +854,7 @@ rb_struct_eql(VALUE s, VALUE s2) rb_bug("inconsistent struct"); /* should never happen */ } - for (i=0; i<RSTRUCT_LEN(s); i++) { - if (!rb_eql(RSTRUCT_PTR(s)[i], RSTRUCT_PTR(s2)[i])) return Qfalse; - } - return Qtrue; + return rb_exec_recursive_paired(recursive_eql, s, s2, s2); } /* |