diff --git a/ChangeLog b/ChangeLog index ab67c8a78c..ed5850d975 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Thu Jul 18 18:14:36 2013 Masaki Matsushita + + * array.c (rb_ary_count): iterate items appropriately. + [Bug #8654] + Thu Jul 18 17:35:41 2013 Masaki Matsushita * hash.c (rb_hash_flatten): performance improvement by not using 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 {