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

Commits on Jan 28, 2016

  1. Copy the full SHA
    2fae91c View commit details
  2. Copy the full SHA
    8e8f7e3 View commit details
  3. Copy the full SHA
    eedb0e8 View commit details
26 changes: 24 additions & 2 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/RopeNodes.java
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.utilities.ConditionProfile;
import org.jcodings.Encoding;
import org.jcodings.specific.ASCIIEncoding;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.rope.AsciiOnlyLeafRope;
@@ -308,7 +309,25 @@ public LeafRope makeInvalidLeafRope(byte[] bytes, Encoding encoding, int codeRan
return new InvalidLeafRope(bytes, encoding);
}

@Specialization(guards = "isUnknown(codeRange)")
@Specialization(guards = { "isUnknown(codeRange)", "isBinaryString(encoding)" })
public LeafRope makeUnknownLeafRopeBinary(byte[] bytes, Encoding encoding, int codeRange,
@Cached("createBinaryProfile()") ConditionProfile discovered7BitProfile) {
int newCodeRange = StringSupport.CR_7BIT;
for (int i = 0; i < bytes.length; i++) {
if (bytes[i] < 0) {
newCodeRange = StringSupport.CR_VALID;
break;
}
}

if (discovered7BitProfile.profile(newCodeRange == StringSupport.CR_7BIT)) {
return new AsciiOnlyLeafRope(bytes, encoding);
}

return new ValidLeafRope(bytes, encoding, bytes.length);
}

@Specialization(guards = { "isUnknown(codeRange)", "!isBinaryString(encoding)" })
public LeafRope makeUnknownLeafRope(byte[] bytes, Encoding encoding, int codeRange,
@Cached("createBinaryProfile()") ConditionProfile discovered7BitProfile,
@Cached("createBinaryProfile()") ConditionProfile discoveredValidProfile) {
@@ -327,7 +346,6 @@ public LeafRope makeUnknownLeafRope(byte[] bytes, Encoding encoding, int codeRan
return new InvalidLeafRope(bytes, encoding);
}


protected static boolean is7Bit(int codeRange) {
return codeRange == StringSupport.CR_7BIT;
}
@@ -343,6 +361,10 @@ protected static boolean isBroken(int codeRange) {
protected static boolean isUnknown(int codeRange) {
return codeRange == StringSupport.CR_UNKNOWN;
}

protected static boolean isBinaryString(Encoding encoding) {
return encoding == ASCIIEncoding.INSTANCE;
}
}

@NodeChildren({
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@
import com.oracle.truffle.api.utilities.BranchProfile;
import com.oracle.truffle.api.utilities.ConditionProfile;
import com.oracle.truffle.api.source.SourceSection;
import org.jcodings.specific.ASCIIEncoding;
import org.jcodings.specific.USASCIIEncoding;
import org.jcodings.specific.UTF8Encoding;
import org.jruby.truffle.format.parser.PackCompiler;
@@ -65,6 +66,7 @@
import org.jruby.truffle.runtime.rope.Rope;
import org.jruby.util.ByteList;
import org.jruby.util.Memo;
import org.jruby.util.StringSupport;

import java.util.Arrays;

@@ -2398,10 +2400,12 @@ public CallTarget getCallTarget() {
@ImportStatic(StringCachingGuards.class)
public abstract static class PackNode extends ArrayCoreMethodNode {

@Child private RopeNodes.MakeLeafRopeNode makeLeafRopeNode;
@Child private TaintNode taintNode;

public PackNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
makeLeafRopeNode = RopeNodesFactory.MakeLeafRopeNodeGen.create(context, sourceSection, null, null, null);
}

@Specialization(guards = {"isRubyString(format)", "ropesEqual(format, cachedFormat)"}, limit = "getCacheLimit()")
@@ -2461,7 +2465,8 @@ private RuntimeException handleException(PackException exception) {
}

private DynamicObject finishPack(int formatLength, PackResult result) {
final DynamicObject string = createString(new ByteList((byte[]) result.getOutput(), 0, result.getOutputLength()));
final Rope rope = makeLeafRopeNode.executeMake(Arrays.copyOfRange((byte[]) result.getOutput(), 0, result.getOutputLength()), ASCIIEncoding.INSTANCE, StringSupport.CR_UNKNOWN);
final DynamicObject string = createString(rope);

if (formatLength == 0) {
StringOperations.forceEncoding(string, USASCIIEncoding.INSTANCE);
Original file line number Diff line number Diff line change
@@ -155,7 +155,6 @@ public static Encoding checkEncoding(DynamicObject string, CodeRangeable other)
}

public static void forceEncoding(DynamicObject string, Encoding encoding) {
modify(string);
final Rope oldRope = Layouts.STRING.getRope(string);
StringOperations.setRope(string, RopeOperations.withEncoding(oldRope, encoding, StringSupport.CR_UNKNOWN));
}
Original file line number Diff line number Diff line change
@@ -119,6 +119,8 @@ public static Encoding STR_ENC_GET(Rope rope) {
public static long calculateCodeRangeAndLength(Encoding encoding, byte[] bytes, int start, int end) {
if (bytes.length == 0) {
return StringSupport.pack(0, encoding.isAsciiCompatible() ? StringSupport.CR_7BIT : StringSupport.CR_VALID);
} else if (encoding == ASCIIEncoding.INSTANCE) {
return strLengthWithCodeRangeBinaryString(bytes, start, end);
} else if (encoding.isAsciiCompatible()) {
return StringSupport.strLengthWithCodeRangeAsciiCompatible(encoding, bytes, start, end);
} else {
@@ -131,6 +133,19 @@ public static int strLength(Encoding enc, byte[] bytes, int p, int end) {
return StringSupport.strLength(enc, bytes, p, end);
}

private static long strLengthWithCodeRangeBinaryString(byte[] bytes, int start, int end) {
int codeRange = StringSupport.CR_7BIT;

for (int i = start; i < end; i++) {
if (bytes[i] < 0) {
codeRange = StringSupport.CR_VALID;
break;
}
}

return StringSupport.pack(end - start, codeRange);
}

public static LeafRope flatten(Rope rope) {
if (rope instanceof LeafRope) {
return (LeafRope) rope;