Skip to content

Commit

Permalink
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions core/src/main/java/org/jruby/truffle/nodes/core/ModuleNodes.java
Original file line number Diff line number Diff line change
@@ -85,12 +85,10 @@ public abstract static class CompareNode extends CoreMethodNode {

public CompareNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
booleanCastNode = BooleanCastNodeFactory.create(context, sourceSection, null);
}

public CompareNode(CompareNode prev) {
super(prev);
booleanCastNode = prev.booleanCastNode;
}

private Object isSubclass(VirtualFrame frame, RubyModule self, RubyModule other) {
@@ -101,6 +99,14 @@ private Object isSubclass(VirtualFrame frame, RubyModule self, RubyModule other)
return subclassNode.executeIsSubclassOf(frame, self, other);
}

private boolean booleanCast(VirtualFrame frame, Object value) {
if (booleanCastNode == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
booleanCastNode = insert(BooleanCastNodeFactory.create(getContext(), getSourceSection(), null));
}
return booleanCastNode.executeBoolean(frame, value);
}

@Specialization
public Object compare(VirtualFrame frame, RubyModule self, RubyModule other) {
notDesignedForCompilation();
@@ -113,7 +119,7 @@ public Object compare(VirtualFrame frame, RubyModule self, RubyModule other) {

if (isSubclass instanceof RubyNilClass) {
return getContext().getCoreLibrary().getNilObject();
} else if (booleanCastNode.executeBoolean(frame, isSubclass)) {
} else if (booleanCast(frame, isSubclass)) {
return -1;
}
return 1;

0 comments on commit 108afd1

Please sign in to comment.