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: d91dea5b7fbe
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 495c65c26d55
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Apr 12, 2016

  1. Copy the full SHA
    822d9b9 View commit details
  2. [Truffle] Model String#clear as a substring operation of len == 0.

    This allows for better code re-use through the substring operation's special handling of len == 0.
    nirvdrum committed Apr 12, 2016
    Copy the full SHA
    495c65c View commit details
Showing with 8 additions and 22 deletions.
  1. +3 −2 truffle/src/main/java/org/jruby/truffle/core/rope/RopeNodes.java
  2. +5 −20 truffle/src/main/java/org/jruby/truffle/core/string/StringNodes.java
Original file line number Diff line number Diff line change
@@ -66,7 +66,8 @@ public MakeSubstringNode(RubyContext context, SourceSection sourceSection) {
public Rope substringZeroBytes(Rope base, int offset, int byteLength,
@Cached("createBinaryProfile()") ConditionProfile isUTF8,
@Cached("createBinaryProfile()") ConditionProfile isUSAscii,
@Cached("createBinaryProfile()") ConditionProfile isAscii8Bit) {
@Cached("createBinaryProfile()") ConditionProfile isAscii8Bit,
@Cached("create(getContext(), getSourceSection())") WithEncodingNode withEncodingNode) {
if (isUTF8.profile(base.getEncoding() == UTF8Encoding.INSTANCE)) {
return RopeConstants.EMPTY_UTF8_ROPE;
}
@@ -79,7 +80,7 @@ public Rope substringZeroBytes(Rope base, int offset, int byteLength,
return RopeConstants.EMPTY_ASCII_8BIT_ROPE;
}

return RopeOperations.withEncodingVerySlow(RopeConstants.EMPTY_UTF8_ROPE, base.getEncoding());
return withEncodingNode.executeWithEncoding(RopeConstants.EMPTY_ASCII_8BIT_ROPE, base.getEncoding(), CR_7BIT);
}

@Specialization(guards = "byteLength == 1")
Original file line number Diff line number Diff line change
@@ -77,6 +77,7 @@
import org.jruby.truffle.core.rope.RopeNodes.MakeRepeatingNode;
import org.jruby.truffle.core.rope.RopeNodesFactory;
import org.jruby.truffle.core.rope.RopeOperations;
import org.jruby.truffle.core.rope.SubstringRope;
import org.jruby.truffle.core.rubinius.StringPrimitiveNodes;
import org.jruby.truffle.core.rubinius.StringPrimitiveNodesFactory;
import org.jruby.truffle.language.NotProvided;
@@ -2490,32 +2491,16 @@ public DynamicObject capitalizeBang(DynamicObject string) {
@CoreMethod(names = "clear", raiseIfFrozenSelf = true)
public abstract static class ClearNode extends CoreMethodArrayArgumentsNode {

@Child private RopeNodes.WithEncodingNode withEncodingNode;
@Child private RopeNodes.MakeSubstringNode makeSubstringNode;

public ClearNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
withEncodingNode = RopeNodes.WithEncodingNode.create(context, sourceSection);
makeSubstringNode = RopeNodes.MakeSubstringNode.create(context, sourceSection);
}

@Specialization
public DynamicObject clear(DynamicObject string,
@Cached("createBinaryProfile()") ConditionProfile isUTF8,
@Cached("createBinaryProfile()") ConditionProfile isUSAscii,
@Cached("createBinaryProfile()") ConditionProfile isAscii8Bit) {
final Rope rope = rope(string);
final Rope emptyRope;

if (isUTF8.profile(rope.getEncoding() == UTF8Encoding.INSTANCE)) {
emptyRope = RopeConstants.EMPTY_UTF8_ROPE;
} else if (isUSAscii.profile(rope.getEncoding() == USASCIIEncoding.INSTANCE)) {
emptyRope = RopeConstants.EMPTY_US_ASCII_ROPE;
} else if (isAscii8Bit.profile(rope.getEncoding() == ASCIIEncoding.INSTANCE)) {
emptyRope = RopeConstants.EMPTY_ASCII_8BIT_ROPE;
} else {
emptyRope = withEncodingNode.executeWithEncoding(RopeConstants.EMPTY_ASCII_8BIT_ROPE, rope.getEncoding(), CodeRange.CR_7BIT);
}

StringOperations.setRope(string, emptyRope);
public DynamicObject clear(DynamicObject string) {
StringOperations.setRope(string, makeSubstringNode.executeMake(rope(string), 0, 0));

return string;
}