diff options
author | glass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-11-06 01:39:55 +0000 |
---|---|---|
committer | glass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-11-06 01:39:55 +0000 |
commit | e90e8b2ef6df04c1db5d9e94aea1687ceaef02de (patch) | |
tree | e0e53a956772268f38b938c8a727af7d839189f4 /array.c | |
parent | 71b70f3cdf811e2ed9b754062376438057294c9b (diff) | |
download | ruby-e90e8b2ef6df04c1db5d9e94aea1687ceaef02de.tar.gz |
* array.c (rb_ary_and): defer hash creation and some refactoring.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43549 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'array.c')
-rw-r--r-- | array.c | 14 |
1 files changed, 7 insertions, 7 deletions
@@ -4009,20 +4009,20 @@ static VALUE rb_ary_and(VALUE ary1, VALUE ary2) { VALUE hash, ary3, v; + st_table *table; st_data_t vv; long i; ary2 = to_ary(ary2); - ary3 = rb_ary_new2(RARRAY_LEN(ary1) < RARRAY_LEN(ary2) ? - RARRAY_LEN(ary1) : RARRAY_LEN(ary2)); + ary3 = rb_ary_new(); + if (RARRAY_LEN(ary2) == 0) return ary3; hash = ary_make_hash(ary2); - - if (RHASH_EMPTY_P(hash)) - return ary3; + table = rb_hash_tbl_raw(hash); for (i=0; i<RARRAY_LEN(ary1); i++) { - vv = (st_data_t)(v = rb_ary_elt(ary1, i)); - if (st_delete(rb_hash_tbl_raw(hash), &vv, 0)) { + v = RARRAY_AREF(ary1, i); + vv = (st_data_t)v; + if (st_delete(table, &vv, 0)) { rb_ary_push(ary3, v); } } |