Skip to content

Commit 0cb5fe3

Browse files
committed
Remove extra RubyProc cast in ReadBlockFromCurrentFrameArgumentsNode
1 parent 2930581 commit 0cb5fe3

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/main/java/org/truffleruby/language/arguments/ReadBlockFromCurrentFrameArgumentsNode.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
*/
1010
package org.truffleruby.language.arguments;
1111

12-
import org.truffleruby.core.proc.RubyProc;
1312
import org.truffleruby.language.RubyContextSourceNode;
1413

1514
import com.oracle.truffle.api.frame.VirtualFrame;
@@ -27,7 +26,7 @@ public ReadBlockFromCurrentFrameArgumentsNode(Object valueIfAbsent) {
2726

2827
@Override
2928
public Object execute(VirtualFrame frame) {
30-
final RubyProc block = RubyArguments.getBlock(frame);
29+
final Object block = RubyArguments.getBlockAssertType(frame);
3130
return nullProfile.profile(block == null) ? valueIfAbsent : block;
3231
}
3332

src/main/java/org/truffleruby/language/arguments/RubyArguments.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,13 @@ public static RubyProc getBlock(Frame frame) {
150150
return (RubyProc) frame.getArguments()[ArgumentIndicies.BLOCK.ordinal()];
151151
}
152152

153+
/** A variant of getBlock() when the return type does not need to be RubyProc and which avoids the extra cast. */
154+
public static Object getBlockAssertType(Frame frame) {
155+
final Object block = frame.getArguments()[ArgumentIndicies.BLOCK.ordinal()];
156+
assert block == null || block instanceof RubyProc : block;
157+
return block;
158+
}
159+
153160
public static int getArgumentsCount(Frame frame) {
154161
return frame.getArguments().length - RUNTIME_ARGUMENT_COUNT;
155162
}

0 commit comments

Comments
 (0)