Skip to content

Commit

Permalink
faster Array#count
Browse files Browse the repository at this point in the history
  • Loading branch information
lrz committed Aug 3, 2008
1 parent 0fe44a2 commit 9d8e164
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions array.c
Expand Up @@ -3351,17 +3351,14 @@ rb_ary_count(int argc, VALUE *argv, VALUE ary)
}
else {
VALUE obj;
long i, count = RARRAY_LEN(ary);
long count = RARRAY_LEN(ary);

rb_scan_args(argc, argv, "1", &obj);
if (rb_block_given_p()) {
rb_warn("given block not used");
}
#if WITH_OBJC
for (i = 0; i < count; i++) {
if (rb_equal(RARRAY_AT(ary, i), obj))
n++;
}
n = CFArrayGetCountOfValue((CFArrayRef)ary, CFRangeMake(0, count), RB2OC(obj));
#else
for (p = RARRAY_PTR(ary), pend = p + RARRAY_LEN(ary); p < pend; p++) {
if (rb_equal(*p, obj)) n++;
Expand Down

0 comments on commit 9d8e164

Please sign in to comment.