From 6f49bc635bd6b0f049d4dacc2b9e46ff82d24866 Mon Sep 17 00:00:00 2001 From: glass Date: Thu, 18 Jul 2013 09:18:50 +0000 Subject: * hash.c (rb_hash_flatten): performance improvement by not using rb_hash_to_a() to avoid array creation with rb_assoc_new(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42040 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- array.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'array.c') diff --git a/array.c b/array.c index 6e071e6f17..ef9007ae0d 100644 --- a/array.c +++ b/array.c @@ -4177,13 +4177,15 @@ rb_ary_count(int argc, VALUE *argv, VALUE ary) long n = 0; if (argc == 0) { - VALUE *p, *pend; + long i; + VALUE v; if (!rb_block_given_p()) return LONG2NUM(RARRAY_LEN(ary)); - for (p = RARRAY_PTR(ary), pend = p + RARRAY_LEN(ary); p < pend; p++) { - if (RTEST(rb_yield(*p))) n++; + for (i = 0; i < RARRAY_LEN(ary); i++) { + v = RARRAY_AREF(ary, i); + if (RTEST(rb_yield(v))) n++; } } else { -- cgit v1.2.3