From 0c90036fd14fd5aef136afccfb38e42c4d3c01e3 Mon Sep 17 00:00:00 2001 From: matz Date: Mon, 3 Feb 2003 05:34:16 +0000 Subject: * re.c (rb_memsearch): algolithm body of String#index. * error.c (Init_Exception): "to_str" removed. * eval.c (eval): should not rely on Exception#to_str * eval.c (compile_error): ditto. * error.c (err_append): ditto. * hash.c (rb_hash_merge): Hash#merge, non destructive "update". now there's also Hash#merge! which is an alias to "update". git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- array.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'array.c') diff --git a/array.c b/array.c index 8151925b7e..7e039abf6a 100644 --- a/array.c +++ b/array.c @@ -1648,23 +1648,6 @@ rb_ary_cmp(ary1, ary2) return INT2FIX(-1); } -static VALUE -rb_ary_diff(ary1, ary2) - VALUE ary1, ary2; -{ - VALUE ary3; - long i; - - ary2 = to_ary(ary2); - ary3 = rb_ary_new(); - for (i=0; ilen; i++) { - if (rb_ary_includes(ary2, RARRAY(ary1)->ptr[i])) continue; - if (rb_ary_includes(ary3, RARRAY(ary1)->ptr[i])) continue; - rb_ary_push(ary3, RARRAY(ary1)->ptr[i]); - } - return ary3; -} - static VALUE ary_make_hash(ary1, ary2) VALUE ary1, ary2; @@ -1683,6 +1666,23 @@ ary_make_hash(ary1, ary2) return hash; } +static VALUE +rb_ary_diff(ary1, ary2) + VALUE ary1, ary2; +{ + VALUE ary3, hash; + long i; + + hash = ary_make_hash(to_ary(ary2), 0); + ary3 = rb_ary_new(); + + for (i=0; ilen; i++) { + if (st_lookup(RHASH(hash)->tbl, RARRAY(ary1)->ptr[i], 0)) continue; + rb_ary_push(ary3, RARRAY(ary1)->ptr[i]); + } + return ary3; +} + static VALUE rb_ary_and(ary1, ary2) VALUE ary1, ary2; -- cgit v1.2.3