summaryrefslogtreecommitdiff
path: root/array.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-19 01:08:52 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-19 01:08:52 (GMT)
commit0d09ee1e73d0cf0daed28acd75deeb12f09f42b6 (patch)
treefdb0fd2ff94f20d5f915cff050b9b14a34636f72 /array.c
parent5c3f9641c0475b6ec2e26c8e6df921abf47856ca (diff)
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.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/array.c b/array.c
index b533e81..e7f96f7 100644
--- a/array.c
+++ b/array.c
@@ -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;