Skip to content

Commit

Permalink
[Truffle] - String#reverse and String#reverse! should preserve the st…
Browse files Browse the repository at this point in the history
…ring encoding.
  • Loading branch information
lucasallan committed Dec 23, 2014
1 parent 226c52d commit 830d58a
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
Expand Up @@ -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));
}
}

Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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.