Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: d0f7a033169e
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 5ab0852f31d2
Choose a head ref
  • 4 commits
  • 6 files changed
  • 1 contributor

Commits on Jun 18, 2016

  1. Copy the full SHA
    b7deca3 View commit details
  2. Copy the full SHA
    0a484e7 View commit details
  3. Copy the full SHA
    9abe64e View commit details
  4. revisit RubyEnumerable - make all? similar to how any? works

    ...  account for all? a little different since Array does not override
    
    - introduce all_pCommon and make the old version delegate
    
    - deprecated count18
    - prefer to see non 19 versions on the Java-Ruby impl side
    kares committed Jun 18, 2016
    Copy the full SHA
    5ab0852 View commit details
4 changes: 1 addition & 3 deletions core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
@@ -4782,15 +4782,13 @@ public ProfiledMethods getProfiledMethods() {
*
* @param name the name of the method
* @param method
* @deprecated This should be an implementation detail of the ProfilingService and should remove from the Ruby class.
*/
@Deprecated
@SuppressWarnings("deprecation")
void addProfiledMethod(final String name, final DynamicMethod method) {
if (!config.isProfiling()) return;
if (method.isUndefined()) return;

getProfiledMethods().addProfiledMethod( name, method );

}

/**
6 changes: 3 additions & 3 deletions core/src/main/java/org/jruby/RubyArray.java
Original file line number Diff line number Diff line change
@@ -4058,10 +4058,10 @@ public IRubyObject rotate(ThreadContext context, IRubyObject cnt) {
return internalRotate(context, RubyNumeric.fix2int(cnt));
}


// Enumerable direct implementations (non-"each" versions)
// NOTE: not a @JRubyMethod(name = "all?") as there's no Array#all? on MRI
public IRubyObject all_p(ThreadContext context, Block block) {
if (!isBuiltin("each")) return RubyEnumerable.all_pCommon(context, this, block, Arity.OPTIONAL);
if (!isBuiltin("each")) return RubyEnumerable.all_pCommon(context, this, block);
if (!block.isGiven()) return all_pBlockless(context);

for (int i = 0; i < realLength; i++) {
@@ -4082,7 +4082,7 @@ private IRubyObject all_pBlockless(ThreadContext context) {
@JRubyMethod(name = "any?")
public IRubyObject any_p(ThreadContext context, Block block) {
if (isEmpty()) return context.runtime.getFalse();
if (!isBuiltin("each")) return RubyEnumerable.any_pCommon(context, this, block, Arity.OPTIONAL);
if (!isBuiltin("each")) return RubyEnumerable.any_pCommon(context, this, block);
if (!block.isGiven()) return any_pBlockless(context);

for (int i = 0; i < realLength; i++) {
78 changes: 26 additions & 52 deletions core/src/main/java/org/jruby/RubyEnumerable.java
Original file line number Diff line number Diff line change
@@ -174,6 +174,7 @@ public IRubyObject yield(ThreadContext context, IRubyObject[] unusedValue) {
return RubyFixnum.newFixnum(runtime, result[0]);
}

@Deprecated
public static IRubyObject count18(ThreadContext context, IRubyObject self, final IRubyObject methodArg, final Block block) {
return count(context, self, methodArg, block);
}
@@ -190,7 +191,7 @@ public IRubyObject yield(ThreadContext context, IRubyObject[] args) {
IRubyObject packedArg = packEnumValues(context.runtime, args);
if (packedArg.equals(methodArg)) result[0]++;

return runtime.getNil();
return context.nil;
}
});

@@ -432,15 +433,16 @@ public IRubyObject yield(ThreadContext context, IRubyObject[] args) {
return result;
}

@JRubyMethod(name = {"to_a", "entries"})
public static IRubyObject to_a(ThreadContext context, IRubyObject self) {
return to_a19(context, self);
}

@JRubyMethod(name = {"to_a", "entries"}, rest = true)
public static IRubyObject to_a(ThreadContext context, IRubyObject self, IRubyObject[] args) {
return to_a19(context, self, args);
}

@JRubyMethod(name = {"to_a", "entries"})
public static IRubyObject to_a19(ThreadContext context, IRubyObject self) {
Ruby runtime = context.runtime;
RubyArray result = runtime.newArray();
@@ -449,7 +451,6 @@ public static IRubyObject to_a19(ThreadContext context, IRubyObject self) {
return result;
}

@JRubyMethod(name = {"to_a", "entries"}, rest = true)
public static IRubyObject to_a19(ThreadContext context, IRubyObject self, IRubyObject[] args) {
final Ruby runtime = context.runtime;
final RubyArray result = runtime.newArray();
@@ -1365,6 +1366,7 @@ public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {
return runtime.newArrayNoCopy(result);
}

@JRubyMethod(name = "none?")
public static IRubyObject none_p(ThreadContext context, IRubyObject self, final Block block) {
final Ruby runtime = context.runtime;
final ThreadContext localContext = context;
@@ -1396,7 +1398,6 @@ public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {
return runtime.getTrue();
}

@JRubyMethod(name = "none?")
public static IRubyObject none_p19(ThreadContext context, IRubyObject self, final Block block) {
return none_p(context, self, block);
}
@@ -1431,6 +1432,7 @@ public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {
return runtime.getTrue();
}

@JRubyMethod(name = "one?")
public static IRubyObject one_p(ThreadContext context, IRubyObject self, final Block block) {
final Ruby runtime = context.runtime;
final ThreadContext localContext = context;
@@ -1474,7 +1476,6 @@ public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {
return result[0] ? runtime.getTrue() : runtime.getFalse();
}

@JRubyMethod(name = "one?")
public static IRubyObject one_p19(ThreadContext context, IRubyObject self, final Block block) {
return one_p(context, self, block);
}
@@ -1522,73 +1523,46 @@ public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {
return result[0] ? runtime.getTrue() : runtime.getFalse();
}

@JRubyMethod(name = "all?")
public static IRubyObject all_p(ThreadContext context, IRubyObject self, final Block block) {
final Ruby runtime = context.runtime;
final ThreadContext localContext = context;

try {
if (block.isGiven()) {
callEach(runtime, context, self, block.getSignature(), new BlockCallback() {
public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {
checkContext(localContext, ctx, "all?");
IRubyObject larg = packEnumValues(runtime, largs);
if (!block.yield(ctx, larg).isTrue()) {
throw JumpException.SPECIAL_JUMP;
}
return runtime.getNil();
}
});
} else {
callEach(runtime, context, self, Signature.ONE_REQUIRED, new BlockCallback() {
public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {
checkContext(localContext, ctx, "all?");
IRubyObject larg = packEnumValues(runtime, largs);
if (!larg.isTrue()) {
throw JumpException.SPECIAL_JUMP;
}
return runtime.getNil();
}
});
}
} catch (JumpException.SpecialJump sj) {
return runtime.getFalse();
}

return runtime.getTrue();
if (self instanceof RubyArray) return ((RubyArray) self).all_p(context, block);
return all_pCommon(context, self, block);
}

@JRubyMethod(name = "all?")
public static IRubyObject all_p19(ThreadContext context, IRubyObject self, final Block block) {
if (self instanceof RubyArray) return ((RubyArray) self).all_p(context, block);

return all_p(context, self, block);
}

@Deprecated
public static IRubyObject all_pCommon(final ThreadContext context, IRubyObject self, final Block block, Arity callbackArity) {
return all_pCommon(context, self, block);
}

public static IRubyObject all_pCommon(ThreadContext context, IRubyObject self, final Block block) {
final Ruby runtime = context.runtime;
final ThreadContext localContext = context;

try {
if (block.isGiven()) {
callEach(runtime, context, self, callbackArity, new BlockCallback() {
public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {
checkContext(context, ctx, "all?");
IRubyObject larg = packEnumValues(ctx, largs);
if (!block.yield(ctx, larg).isTrue()) {
callEach(runtime, context, self, block.getSignature(), new BlockCallback() {
public IRubyObject call(ThreadContext context, IRubyObject[] largs, Block blk) {
checkContext(localContext, context, "all?");
IRubyObject larg = packEnumValues(runtime, largs);
if (!block.yield(context, larg).isTrue()) {
throw JumpException.SPECIAL_JUMP;
}
return ctx.nil;
return context.nil;
}
});
} else {
callEach(runtime, context, self, Signature.ONE_REQUIRED, new BlockCallback() {
public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {
checkContext(context, ctx, "all?");
IRubyObject larg = packEnumValues(ctx, largs);
public IRubyObject call(ThreadContext context, IRubyObject[] largs, Block blk) {
checkContext(localContext, context, "all?");
IRubyObject larg = packEnumValues(runtime, largs);
if (!larg.isTrue()) {
throw JumpException.SPECIAL_JUMP;
}
return ctx.nil;
return context.nil;
}
});
}
@@ -1618,15 +1592,15 @@ public static IRubyObject any_pCommon(ThreadContext context, IRubyObject self, f
public IRubyObject yield(ThreadContext context, IRubyObject[] args) {
IRubyObject packedArg = packEnumValues(context, args);
if (block.yield(context, packedArg).isTrue()) throw JumpException.SPECIAL_JUMP;
return runtime.getNil();
return context.nil;
}
});
} else {
each(context, self, new JavaInternalBlockBody(runtime, context, "Enumerable#any?", Signature.ONE_REQUIRED) {
public IRubyObject yield(ThreadContext context, IRubyObject[] args) {
IRubyObject packedArg = packEnumValues(context.runtime, args);
if (packedArg.isTrue()) throw JumpException.SPECIAL_JUMP;
return runtime.getNil();
return context.nil;
}
});
}
6 changes: 2 additions & 4 deletions core/src/main/java/org/jruby/runtime/ThreadContext.java
Original file line number Diff line number Diff line change
@@ -1080,10 +1080,8 @@ public int profileEnter(int nextMethod) {
}

public int profileEnter(String name, DynamicMethod nextMethod) {
if (isProfiling()) {
// TODO This can be removed, because the profiled method will be added in the MethodEnhancer if necessary
getRuntime().getProfiledMethods().addProfiledMethod( name, nextMethod );
}
// profiled method is added in the MethodEnhancer (if necessary)
// @see BuiltinProfilingService.DefaultMethodEnhancer
return profileEnter((int) nextMethod.getSerialNumber());
}

Original file line number Diff line number Diff line change
@@ -15,15 +15,15 @@

public abstract class CachingCallSite extends CallSite {
protected CacheEntry cache = CacheEntry.NULL_CACHE;
public static volatile int totalCallSites;
// private AtomicBoolean isPolymorphic = new AtomicBoolean(false);
//public static volatile int totalCallSites;
//private AtomicBoolean isPolymorphic = new AtomicBoolean(false);

public CachingCallSite(String methodName, CallType callType) {
super(methodName, callType);
totalCallSites++;
//totalCallSites++;
}

public CacheEntry getCache() {
public final CacheEntry getCache() {
return cache;
}

@@ -39,7 +39,7 @@ public int getCachedClassIndex() {
return ClassIndex.NO_INDEX.ordinal();
}

public String getMethodName() {
public final String getMethodName() {
return methodName;
}

Original file line number Diff line number Diff line change
@@ -74,6 +74,7 @@ private Ruby getRuntime() {
}

@Override
@SuppressWarnings("deprecation")
public DynamicMethod enhance( String name, DynamicMethod delegate ) {
getRuntime().getProfiledMethods().addProfiledMethod( name, delegate );
return new ProfilingDynamicMethod(delegate);
@@ -95,12 +96,8 @@ public DefaultProfileReporter(ThreadContext context) {
this.context = context;
}

private ThreadContext getThreadContext() {
return context;
}

private Ruby getRuntime() {
return getThreadContext().getRuntime();
return context.runtime;
}

private RubyInstanceConfig getConfig() {