Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Truffle] Lazily create children in ParserByteListNode since we may v…
Browse files Browse the repository at this point in the history
…ery well not need both for any given ParserByteList.
nirvdrum committed Jan 10, 2017
1 parent 1243b34 commit b5396d4
Showing 1 changed file with 30 additions and 26 deletions.
56 changes: 30 additions & 26 deletions truffle/src/main/java/org/jruby/truffle/parser/ParserByteList.java
Original file line number Diff line number Diff line change
@@ -37,6 +37,7 @@
*/
package org.jruby.truffle.parser;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
import org.jcodings.Encoding;
@@ -54,32 +55,6 @@
import static org.jruby.truffle.core.rope.CodeRange.CR_UNKNOWN;

public class ParserByteList {

private static class ParserByteListNode extends RubyNode {

@Child RopeNodes.MakeSubstringNode makeSubstringNode;
@Child RopeNodes.WithEncodingNode withEncodingNode;

public ParserByteListNode() {
makeSubstringNode = RopeNodes.MakeSubstringNode.create();
withEncodingNode = RopeNodes.WithEncodingNode.create();
adoptChildren();
}

public RopeNodes.MakeSubstringNode getMakeSubstringNode() {
return makeSubstringNode;
}

public RopeNodes.WithEncodingNode getWithEncodingNode() {
return withEncodingNode;
}

@Override
public Object execute(VirtualFrame frame) {
return nil();
}
}

private final Rope rope;
private ParserByteListNode parserByteListNode;

@@ -180,4 +155,33 @@ private ParserByteListNode getParseByteListNode() {
return parserByteListNode;
}

private static class ParserByteListNode extends RubyNode {

@Child RopeNodes.MakeSubstringNode makeSubstringNode;
@Child RopeNodes.WithEncodingNode withEncodingNode;

public RopeNodes.MakeSubstringNode getMakeSubstringNode() {
if (makeSubstringNode == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
makeSubstringNode = insert(RopeNodes.MakeSubstringNode.create());
}

return makeSubstringNode;
}

public RopeNodes.WithEncodingNode getWithEncodingNode() {
if (withEncodingNode == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
withEncodingNode = insert(RopeNodes.WithEncodingNode.create());
}

return withEncodingNode;
}

@Override
public Object execute(VirtualFrame frame) {
return nil();
}

}
}

0 comments on commit b5396d4

Please sign in to comment.