Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 37486b915862
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 82a62275015a
Choose a head ref
  • 2 commits
  • 3 files changed
  • 1 contributor

Commits on Apr 3, 2015

  1. Copy the full SHA
    396fbc4 View commit details
  2. Copy the full SHA
    82a6227 View commit details
1 change: 0 additions & 1 deletion spec/truffle/tags/core/string/capitalize_tags.txt

This file was deleted.

Binary file removed spec/truffle/tags/core/string/lstrip_tags.txt
Binary file not shown.
80 changes: 50 additions & 30 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/StringNodes.java
Original file line number Diff line number Diff line change
@@ -2399,6 +2399,8 @@ public boolean validEncodingQuery(RubyString string) {
@CoreMethod(names = "capitalize!", raiseIfFrozenSelf = true)
public abstract static class CapitalizeBangNode extends CoreMethodNode {

private final ConditionProfile dummyEncodingProfile = ConditionProfile.createBinaryProfile();

public CapitalizeBangNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}
@@ -2408,48 +2410,76 @@ public CapitalizeBangNode(CapitalizeBangNode prev) {
}

@Specialization
@TruffleBoundary
public RubyBasicObject capitalizeBang(RubyString string) {
notDesignedForCompilation();
// Taken from org.jruby.RubyString#capitalize_bang19.

final ByteList value = string.getByteList();
final Encoding enc = value.getEncoding();

String javaString = string.toString();
if (dummyEncodingProfile.profile(enc.isDummy())) {
CompilerDirectives.transferToInterpreter();

if (javaString.isEmpty()) {
throw new RaiseException(
getContext().getCoreLibrary().encodingCompatibilityError(
String.format("incompatible encoding with this operation: %s", enc), this));
}

if (value.getRealSize() == 0) {
return nil();
} else {
final ByteList byteListString = StringNodesHelper.capitalize(string);

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

string.modifyAndKeepCodeRange();

int s = value.getBegin();
int end = s + value.getRealSize();
byte[]bytes = value.getUnsafeBytes();
boolean modify = false;

int c = StringSupport.codePoint(getContext().getRuntime(), enc, bytes, s, end);
if (enc.isLower(c)) {
enc.codeToMbc(StringSupport.toUpper(enc, c), bytes, s);
modify = true;
}

s += StringSupport.codeLength(enc, c);
while (s < end) {
c = StringSupport.codePoint(getContext().getRuntime(), enc, bytes, s, end);
if (enc.isUpper(c)) {
enc.codeToMbc(StringSupport.toLower(enc, c), bytes, s);
modify = true;
}
s += StringSupport.codeLength(enc, c);
}

return modify ? string : nil();
}
}

@CoreMethod(names = "capitalize", taintFromSelf = true)
public abstract static class CapitalizeNode extends CoreMethodNode {

@Child CallDispatchHeadNode capitalizeBangNode;
@Child CallDispatchHeadNode dupNode;

public CapitalizeNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
capitalizeBangNode = DispatchHeadNodeFactory.createMethodCall(context);
dupNode = DispatchHeadNodeFactory.createMethodCall(context);
}

public CapitalizeNode(CapitalizeNode prev) {
super(prev);
capitalizeBangNode = prev.capitalizeBangNode;
dupNode = prev.dupNode;
}

@Specialization
public RubyString capitalize(RubyString string) {
notDesignedForCompilation();
String javaString = string.toString();
public Object capitalize(VirtualFrame frame, RubyString string) {
final Object duped = dupNode.call(frame, string, "dup", null);
capitalizeBangNode.call(frame, duped, "capitalize!", null);

if (javaString.isEmpty()) {
return string;
} else {
final ByteList byteListString = StringNodesHelper.capitalize(string);
return string.getContext().makeString(string.getLogicalClass(), byteListString);
}
return duped;
}

}
@@ -2478,16 +2508,6 @@ public RubyString clear(RubyString string) {

public static class StringNodesHelper {

@TruffleBoundary
public static ByteList capitalize(RubyString string) {
String javaString = string.toString();
String head = javaString.substring(0, 1).toUpperCase(Locale.ENGLISH);
String tail = javaString.substring(1, javaString.length()).toLowerCase(Locale.ENGLISH);
ByteList byteListString = ByteList.create(head + tail);
byteListString.setEncoding(string.getBytes().getEncoding());
return byteListString;
}

@TruffleBoundary
public static ByteList upcase(Ruby runtime, ByteList string) {
return runtime.newString(string).upcase(runtime.getCurrentContext()).getByteList();