Skip to content

Commit

Permalink
[Truffle] - String: #downcase, #downcase!, #upcase and #upcase! - all…
Browse files Browse the repository at this point in the history
… specs passing
  • Loading branch information
lucasallan committed Mar 18, 2015
1 parent bc11f01 commit 0eb7937
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
1 change: 0 additions & 1 deletion spec/truffle/tags/core/string/downcase_tags.txt

This file was deleted.

2 changes: 0 additions & 2 deletions spec/truffle/tags/core/string/upcase_tags.txt

This file was deleted.

33 changes: 17 additions & 16 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/StringNodes.java
Expand Up @@ -39,6 +39,7 @@
import org.jcodings.specific.ASCIIEncoding;
import org.joni.Matcher;
import org.joni.Option;
import org.jruby.Ruby;
import org.jruby.runtime.Visibility;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.cast.CmpIntNode;
Expand Down Expand Up @@ -916,7 +917,7 @@ public DowncaseNode(DowncaseNode prev) {
@Specialization
public RubyString downcase(RubyString string) {
notDesignedForCompilation();
ByteList newByteList = StringNodesHelper.downcase(string);
final ByteList newByteList = StringNodesHelper.downcase(getContext().getRuntime(), string.getByteList());

return string.getContext().makeString(string.getLogicalClass(), newByteList);
}
Expand All @@ -937,7 +938,7 @@ public DowncaseBangNode(DowncaseBangNode prev) {
public RubyBasicObject downcase(RubyString string) {
notDesignedForCompilation();

ByteList newByteList = StringNodesHelper.downcase(string);
final ByteList newByteList = StringNodesHelper.downcase(getContext().getRuntime(), string.getByteList());

if (newByteList.equal(string.getBytes())) {
return nil();
Expand Down Expand Up @@ -2087,7 +2088,7 @@ public UpcaseNode(UpcaseNode prev) {
@Specialization
public RubyString upcase(RubyString string) {
notDesignedForCompilation();
final ByteList byteListString = StringNodesHelper.upcase(string);
final ByteList byteListString = StringNodesHelper.upcase(getContext().getRuntime(), string.getByteList());

return string.getContext().makeString(string.getLogicalClass(), byteListString);
}
Expand All @@ -2106,12 +2107,17 @@ public UpcaseBangNode(UpcaseBangNode prev) {
}

@Specialization
public RubyString upcaseBang(RubyString string) {
public RubyBasicObject upcaseBang(RubyString string) {
notDesignedForCompilation();
final ByteList byteListString = StringNodesHelper.upcase(string);
string.set(byteListString);

return string;
final ByteList byteListString = StringNodesHelper.upcase(getContext().getRuntime(), string.getByteList());

if (byteListString.equal(string.getByteList())) {
return nil();
} else {
string.set(byteListString);
return string;
}
}
}

Expand Down Expand Up @@ -2252,18 +2258,13 @@ public static ByteList capitalize(RubyString string) {
}

@TruffleBoundary
public static ByteList upcase(RubyString string) {
ByteList byteListString = ByteList.create(string.toString().toUpperCase(Locale.ENGLISH));
byteListString.setEncoding(string.getBytes().getEncoding());
return byteListString;
public static ByteList upcase(Ruby runtime, ByteList string) {
return runtime.newString(string).upcase(runtime.getCurrentContext()).getByteList();
}

@TruffleBoundary
public static ByteList downcase(RubyString string) {
ByteList newByteList = ByteList.create(string.toString().toLowerCase(Locale.ENGLISH));
newByteList.setEncoding(string.getBytes().getEncoding());

return newByteList;
public static ByteList downcase(Ruby runtime, ByteList string) {
return runtime.newString(string).downcase(runtime.getCurrentContext()).getByteList();
}

@TruffleBoundary
Expand Down

0 comments on commit 0eb7937

Please sign in to comment.