Skip to content

Commit 50843a3

Browse files
eregonandrykonchin
authored andcommitted
Use Prism Nodes.Source#computeLineOffsets()
* This avoids creating the TextMap early and is likely faster.
1 parent 5e3b726 commit 50843a3

File tree

2 files changed

+4
-15
lines changed

2 files changed

+4
-15
lines changed

src/main/java/org/truffleruby/debug/TruffleDebugNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ Object parse(Object code,
285285

286286
byte[] serialized = Parser.parseAndSerialize(source);
287287

288-
var yarpSource = YARPTranslatorDriver.createYARPSource(source, YARPTranslatorDriver.createRubySource(code));
288+
var yarpSource = YARPTranslatorDriver.createYARPSource(source);
289289
var parseResult = Loader.load(serialized, yarpSource);
290290
var ast = parseResult.value;
291291

src/main/java/org/truffleruby/parser/YARPTranslatorDriver.java

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public YARPTranslatorDriver(RubyContext context) {
109109

110110
public RootCallTarget parse(RubySource rubySource, ParserContext parserContext, String[] argumentNames,
111111
MaterializedFrame parentFrame, LexicalScope staticLexicalScope, Node currentNode) {
112-
Nodes.Source yarpSource = createYARPSource(rubySource.getBytes(), rubySource);
112+
Nodes.Source yarpSource = createYARPSource(rubySource.getBytes());
113113
this.parseEnvironment = new ParseEnvironment(language, rubySource, yarpSource, parserContext, currentNode);
114114

115115
assert rubySource.isEval() == parserContext.isEval();
@@ -565,19 +565,8 @@ public static RubySource createRubySource(Object code) {
565565
return new RubySource(source, source.getName(), sourceTString);
566566
}
567567

568-
public static Nodes.Source createYARPSource(byte[] sourceBytes, RubySource rubySource) {
569-
Source source = rubySource.getSource();
570-
int[] lineOffsets = new int[source.getLineCount()];
571-
for (int line = 1; line <= source.getLineCount(); line++) {
572-
lineOffsets[line - 1] = source.getLineStartOffset(line);
573-
}
574-
575-
// Nodes.Source expects at least one line, but there are no any line in empty Ruby source file
576-
if (lineOffsets.length == 0) {
577-
lineOffsets = new int[]{ 0 };
578-
}
579-
580-
return new Nodes.Source(sourceBytes, 1, lineOffsets);
568+
public static Nodes.Source createYARPSource(byte[] sourceBytes) {
569+
return new Nodes.Source(sourceBytes);
581570
}
582571

583572
private TranslatorEnvironment environmentForFrame(RubyContext context, MaterializedFrame frame, int blockDepth) {

0 commit comments

Comments
 (0)