diff options
author | glass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-11-02 07:04:39 +0000 |
---|---|---|
committer | glass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-11-02 07:04:39 +0000 |
commit | da9f6cdcb774ae8ee052f9d05b0554a44dde2af4 (patch) | |
tree | 63c3e0ca00f88662344d5bf13d8e2afe5e8af830 /array.c | |
parent | fb4e75c1fb5b36a55ac3ff6614601ca59fb2c2ac (diff) | |
download | ruby-da9f6cdcb774ae8ee052f9d05b0554a44dde2af4.tar.gz |
* array.c (recursive_equal): performance improvement.
[ruby-dev:45412] [Feature #6177]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37420 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'array.c')
-rw-r--r-- | array.c | 22 |
1 files changed, 19 insertions, 3 deletions
@@ -3270,11 +3270,27 @@ static VALUE recursive_equal(VALUE ary1, VALUE ary2, int recur) { long i; + VALUE *p1, *p2; if (recur) return Qtrue; /* Subtle! */ - for (i=0; i<RARRAY_LEN(ary1); i++) { - if (!rb_equal(rb_ary_elt(ary1, i), rb_ary_elt(ary2, i))) - return Qfalse; + + p1 = RARRAY_PTR(ary1); + p2 = RARRAY_PTR(ary2); + + for (i = 0; i < RARRAY_LEN(ary1); i++) { + if (*p1 != *p2) { + if (rb_equal(*p1, *p2)) { + if (RARRAY_LEN(ary1) != RARRAY_LEN(ary2)) + return Qfalse; + p1 = RARRAY_PTR(ary1) + i; + p2 = RARRAY_PTR(ary2) + i; + } + else { + return Qfalse; + } + } + p1++; + p2++; } return Qtrue; } |