Skip to content
Permalink
Browse files
[Truffle] - String#reverse and String#reverse! should preserve the st…
…ring encoding.
  • Loading branch information
lucasallan committed Dec 23, 2014
1 parent 226c52d commit 830d58a95bb7f9759f13c66b51e8d29f21ec08a8
Showing 1 changed file with 9 additions and 2 deletions.
@@ -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.