Skip to content

Commit

Permalink
[Truffle] Use String coercion in String#each_line.
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvdrum committed Feb 7, 2015
1 parent 195871e commit a5fedf5
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -745,31 +745,35 @@ public RubyString eachChar(VirtualFrame frame, RubyString string, RubyProc block
@CoreMethod(names = "each_line", optional = 1)
public abstract static class EachLineNode extends YieldingCoreMethodNode {

@Child private ToStrNode toStrNode;

public EachLineNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
toStrNode = ToStrNodeFactory.create(context, sourceSection, null);
}

public EachLineNode(EachLineNode prev) {
super(prev);
toStrNode = prev.toStrNode;
}

@Specialization
public RubyArray eachLine(RubyString string, @SuppressWarnings("unused") UndefinedPlaceholder separator) {
public RubyArray eachLine(VirtualFrame frame, RubyString string, @SuppressWarnings("unused") UndefinedPlaceholder separator) {
notDesignedForCompilation();

final RubyBasicObject globals = getContext().getCoreLibrary().getGlobalVariablesObject();
final RubyString recordSeparator = (RubyString) globals.getInstanceVariable("$/");
return eachLine(string, recordSeparator);
return eachLine(frame, string, recordSeparator);
}

@Specialization
public RubyArray eachLine(RubyString string, RubyString separator) {
public RubyArray eachLine(VirtualFrame frame, RubyString string, Object separator) {
notDesignedForCompilation();

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

String str = string.toString();
String sep = separator.toString();
String sep = toStrNode.executeRubyString(frame, separator).toString();

int start = 0;

Expand Down

0 comments on commit a5fedf5

Please sign in to comment.