Skip to content

Commit

Permalink
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions core/src/main/java/org/jruby/truffle/nodes/core/StringNodes.java
Original file line number Diff line number Diff line change
@@ -1114,7 +1114,7 @@ public ReverseNode(ReverseNode prev) {
public RubyString reverse(RubyString string) {
notDesignedForCompilation();

return RubyString.fromJavaString(string.getLogicalClass(), new StringBuilder(string.toString()).reverse().toString());
return RubyString.fromByteList(string.getLogicalClass(), StringNodesHelper.reverse(string));
}
}

@@ -1133,7 +1133,7 @@ public ReverseBangNode(ReverseBangNode prev) {
public RubyString reverse(RubyString string) {
notDesignedForCompilation();

string.set(ByteList.create(new StringBuilder(string.toString()).reverse().toString()));
string.set(StringNodesHelper.reverse(string));
return string;
}
}
@@ -1344,6 +1344,13 @@ public static ByteList chompWithString(RubyString string, RubyString stringToCho

return byteList;
}

public static ByteList reverse(RubyString string) {
ByteList byteListString = ByteList.create(new StringBuilder(string.toString()).reverse().toString());
byteListString.setEncoding(string.getBytes().getEncoding());

return byteListString;
}
}

}

0 comments on commit 830d58a

Please sign in to comment.