diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-12-19 01:08:52 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-12-19 01:08:52 +0000 |
commit | 0d09ee1e73d0cf0daed28acd75deeb12f09f42b6 (patch) | |
tree | fdb0fd2ff94f20d5f915cff050b9b14a34636f72 /array.c | |
parent | 5c3f9641c0475b6ec2e26c8e6df921abf47856ca (diff) | |
download | ruby-0d09ee1e73d0cf0daed28acd75deeb12f09f42b6.tar.gz |
Improve Array#- efficiency [Fixes GH-1756]
When doing the difference of a small array with a big one it is not
efficient in both time and memory to convert the second one to a hash.
From: Ana María Martínez Gómez <ammartinez@suse.de>
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61330 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'array.c')
-rw-r--r-- | array.c | 2 |
1 files changed, 1 insertions, 1 deletions
@@ -4163,7 +4163,7 @@ rb_ary_diff(VALUE ary1, VALUE ary2) ary2 = to_ary(ary2); ary3 = rb_ary_new(); - if (RARRAY_LEN(ary2) <= SMALL_ARRAY_LEN) { + if (RARRAY_LEN(ary1) <= SMALL_ARRAY_LEN || RARRAY_LEN(ary2) <= SMALL_ARRAY_LEN) { for (i=0; i<RARRAY_LEN(ary1); i++) { VALUE elt = rb_ary_elt(ary1, i); if (rb_ary_includes_by_eql(ary2, elt)) continue; |