Skip to content

Commit a5fedf5

Browse files
committed
[Truffle] Use String coercion in String#each_line.
1 parent 195871e commit a5fedf5

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

truffle/src/main/java/org/jruby/truffle/nodes/core/StringNodes.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -745,31 +745,35 @@ public RubyString eachChar(VirtualFrame frame, RubyString string, RubyProc block
745745
@CoreMethod(names = "each_line", optional = 1)
746746
public abstract static class EachLineNode extends YieldingCoreMethodNode {
747747

748+
@Child private ToStrNode toStrNode;
749+
748750
public EachLineNode(RubyContext context, SourceSection sourceSection) {
749751
super(context, sourceSection);
752+
toStrNode = ToStrNodeFactory.create(context, sourceSection, null);
750753
}
751754

752755
public EachLineNode(EachLineNode prev) {
753756
super(prev);
757+
toStrNode = prev.toStrNode;
754758
}
755759

756760
@Specialization
757-
public RubyArray eachLine(RubyString string, @SuppressWarnings("unused") UndefinedPlaceholder separator) {
761+
public RubyArray eachLine(VirtualFrame frame, RubyString string, @SuppressWarnings("unused") UndefinedPlaceholder separator) {
758762
notDesignedForCompilation();
759763

760764
final RubyBasicObject globals = getContext().getCoreLibrary().getGlobalVariablesObject();
761765
final RubyString recordSeparator = (RubyString) globals.getInstanceVariable("$/");
762-
return eachLine(string, recordSeparator);
766+
return eachLine(frame, string, recordSeparator);
763767
}
764768

765769
@Specialization
766-
public RubyArray eachLine(RubyString string, RubyString separator) {
770+
public RubyArray eachLine(VirtualFrame frame, RubyString string, Object separator) {
767771
notDesignedForCompilation();
768772

769773
final List<Object> lines = new ArrayList<>();
770774

771775
String str = string.toString();
772-
String sep = separator.toString();
776+
String sep = toStrNode.executeRubyString(frame, separator).toString();
773777

774778
int start = 0;
775779

0 commit comments

Comments
 (0)