Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix count_spec (1.7.x) #1231

Closed
wants to merge 1 commit into from

3 participants

@dmarcotte

Use the appropriate arity to get Enumerable#count to handle its args correctly. Note that we need to switch from JavaInternalBlockBody to a BlockCallback since JavaInternalBlockBody does not currently get its arguments prepared correctly for the given arity (this is fixed in master).

This does not need to be merged into master since #1230 takes care of it.

@dmarcotte dmarcotte Fix count_spec
Use the appropriate arity to get Enumerable#count to handle its args
correctly.  Note that we need to switch from JavaInternalBlockBody to
a BlockCallback since JavaInternalBlockBody does not currently get its
arguments prepared correctly for the given arity.
c758858
@headius
Owner

There seems to be a conflict on the 1.7 branch with another commit of yours. Can you look into that? It appears that the count18 path is using 1.9 behavior, calling #size if present.

@dmarcotte

The call to #size is actually intended to be 1.8-specific (more details in #979). Was your concerned that it had ended up in the wrong place? Or am I missing something here? (Apologies if I am!)

@headius
Owner

If that's appropriate behavior for 1.8, then there's no problem. See if you can tidy up the PR and we'll pull it in.

@dmarcotte

Okay, now I'm definitely missing something :)

I'm not sure what to tidy... the pull looks correct to me. Can you hit me with a bit more detail on what you're seeing? I'd be glad to fix anything up.

@enebo
Owner

cherry-picked this since this ui implies this was against master and not jruby-1_7.

@enebo enebo closed this
@dmarcotte

Ah! That explains the confusion... my bad for sending this to the wrong branch by accident. Thanks for clearing things up @enebo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 14, 2013
  1. @dmarcotte

    Fix count_spec

    dmarcotte authored
    Use the appropriate arity to get Enumerable#count to handle its args
    correctly.  Note that we need to switch from JavaInternalBlockBody to
    a BlockCallback since JavaInternalBlockBody does not currently get its
    arguments prepared correctly for the given arity.
This page is out of date. Refresh to see the latest.
View
14 core/src/main/java/org/jruby/RubyEnumerable.java
@@ -47,7 +47,6 @@
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
@@ -127,18 +126,23 @@ public static IRubyObject count18(ThreadContext context, IRubyObject self, final
return self.callMethod(context, "size");
}
- return count(context, self, block);
+ return countCommon(context, self, block, Arity.OPTIONAL);
}
@JRubyMethod(name = "count", compat = CompatVersion.RUBY1_9)
public static IRubyObject count(ThreadContext context, IRubyObject self, final Block block) {
+ return countCommon(context, self, block, block.arity());
+ }
+
+ private static IRubyObject countCommon(ThreadContext context, IRubyObject self, final Block block, Arity callbackArity) {
final Ruby runtime = context.runtime;
final int result[] = new int[] { 0 };
if (block.isGiven()) {
- each(context, self, new JavaInternalBlockBody(runtime, context, "Enumerable#count", Arity.OPTIONAL) {
- public IRubyObject yield(ThreadContext context, IRubyObject arg) {
- if (block.yield(context, arg).isTrue()) result[0]++;
+ callEach(runtime, context, self, callbackArity, new BlockCallback() {
+ public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {
+ IRubyObject packedArgs = packEnumValues(ctx.runtime, largs);
+ if (block.yield(ctx, packedArgs).isTrue()) result[0]++;
return runtime.getNil();
}
});
View
1  spec/tags/1.9/ruby/core/enumerable/count_tags.txt
@@ -1 +0,0 @@
-fails:Enumerable#count gathers initial args as elements when each yields multiple
Something went wrong with that request. Please try again.