Skip to content

Commit

Permalink
* hash.c (rb_hash_flatten): performance improvement by not using
Browse files Browse the repository at this point in the history
  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
  • Loading branch information
glass committed Jul 18, 2013
1 parent 852caed commit 6f49bc6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Thu Jul 18 18:14:36 2013 Masaki Matsushita <glass.saga@gmail.com>

* array.c (rb_ary_count): iterate items appropriately.
[Bug #8654]

Thu Jul 18 17:35:41 2013 Masaki Matsushita <glass.saga@gmail.com>

* hash.c (rb_hash_flatten): performance improvement by not using
Expand Down
8 changes: 5 additions & 3 deletions array.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 6f49bc6

Please sign in to comment.