aboutsummaryrefslogtreecommitdiffstats
path: root/array.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-12-05 12:53:31 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-12-05 12:53:31 +0000
commit19737494b9f67f935acd5ec141c5137b8d20c3f3 (patch)
tree1ffcd9ea914b058e3634eeb7292c2ba04327f299 /array.c
parent928c99944ba88784a5e921df900472fb32963466 (diff)
downloadruby-19737494b9f67f935acd5ec141c5137b8d20c3f3.tar.gz
array.c: prefer lhs elements
* array.c (rb_ary_or): lhs elements are prefered, so should not replace with rhs elements. * test/ruby/test_array.rb (test_OR_in_order): import the test failed by r43969 from rubyspec/core/array/union_spec.rb. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44015 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'array.c')
-rw-r--r--array.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/array.c b/array.c
index 39144b25f4..9668f17797 100644
--- a/array.c
+++ b/array.c
@@ -4025,6 +4025,14 @@ rb_ary_and(VALUE ary1, VALUE ary2)
return ary3;
}
+static int
+ary_hash_orset(st_data_t *key, st_data_t *value, st_data_t arg, int existing)
+{
+ if (existing) return ST_STOP;
+ *key = *value = (VALUE)arg;
+ return ST_CONTINUE;
+}
+
/*
* call-seq:
* ary | other_ary -> new_ary
@@ -4043,9 +4051,17 @@ static VALUE
rb_ary_or(VALUE ary1, VALUE ary2)
{
VALUE hash, ary3;
+ long i;
ary2 = to_ary(ary2);
- hash = ary_add_hash(ary_make_hash(ary1), ary2);
+ hash = ary_make_hash(ary1);
+
+ for (i=0; i<RARRAY_LEN(ary2); i++) {
+ VALUE elt = RARRAY_AREF(ary2, i);
+ if (!st_update(RHASH_TBL(hash), (st_data_t)elt, ary_hash_orset, (st_data_t)elt)) {
+ OBJ_WRITTEN(hash, Qundef, elt);
+ }
+ }
ary3 = rb_hash_values(hash);
ary_recycle_hash(hash);
return ary3;