Skip to content

Commit

Permalink
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -12,6 +12,8 @@
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.utilities.ConditionProfile;

import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.runtime.RubyArguments;
import org.jruby.truffle.runtime.RubyContext;
@@ -21,21 +23,22 @@
*/
public class ReadBlockNode extends RubyNode {

private final Object valueIfNotPresent;
private final ConditionProfile hasBlockProfile = ConditionProfile.createBinaryProfile();
private final Object valueIfAbsent;

public ReadBlockNode(RubyContext context, SourceSection sourceSection, Object valueIfNotPresent) {
public ReadBlockNode(RubyContext context, SourceSection sourceSection, Object valueIfAbsent) {
super(context, sourceSection);
this.valueIfNotPresent = valueIfNotPresent;
this.valueIfAbsent = valueIfAbsent;
}

@Override
public Object execute(VirtualFrame frame) {
final DynamicObject block = RubyArguments.getBlock(frame.getArguments());

if (block == null) {
return valueIfNotPresent;
} else {
if (hasBlockProfile.profile(block != null)) {
return block;
} else {
return valueIfAbsent;
}
}

0 comments on commit 9dd93a3

Please sign in to comment.