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

Commits on Sep 13, 2016

  1. Copy the full SHA
    37c12b8 View commit details
  2. Copy the full SHA
    a08620f View commit details
  3. Copy the full SHA
    80eda52 View commit details
Original file line number Diff line number Diff line change
@@ -530,31 +530,6 @@ public static int cmp(Rope string, Rope other) {
return size == other.byteLength() ? 0 : size == len ? -1 : 1;
}

@TruffleBoundary
public static Encoding areCompatible(Rope rope, Rope other) {
// Taken from org.jruby.util.StringSupport.areCompatible.

Encoding enc1 = rope.getEncoding();
Encoding enc2 = other.getEncoding();

if (enc1 == enc2) return enc1;

if (other.isEmpty()) return enc1;
if (rope.isEmpty()) {
return (enc1.isAsciiCompatible() && isAsciiOnly(other)) ? enc1 : enc2;
}

if (!enc1.isAsciiCompatible() || !enc2.isAsciiCompatible()) return null;

return RubyEncoding.areCompatible(enc1, rope.getCodeRange().toInt(), enc2, other.getCodeRange().toInt());
}

public static boolean isAsciiOnly(Rope rope) {
// Taken from org.jruby.util.StringSupport.isAsciiOnly.

return rope.getEncoding().isAsciiCompatible() && rope.getCodeRange() == CR_7BIT;
}

public static boolean areComparable(Rope rope, Rope other) {
// Taken from org.jruby.util.StringSupport.areComparable.

Original file line number Diff line number Diff line change
@@ -37,13 +37,6 @@ public static boolean isAsciiCompatible(DynamicObject string) {
return Layouts.STRING.getRope(string).getEncoding().isAsciiCompatible();
}

public static boolean isValidOr7BitEncoding(DynamicObject string) {
assert RubyGuards.isRubyString(string);
final Rope rope = StringOperations.rope(string);

return (rope.getCodeRange() == CodeRange.CR_VALID) || (rope.getCodeRange() == CodeRange.CR_7BIT);
}

public static boolean isFixedWidthEncoding(DynamicObject string) {
assert RubyGuards.isRubyString(string);
return Layouts.STRING.getRope(string).getEncoding().isFixedWidth();
@@ -64,11 +57,6 @@ public static boolean isBrokenCodeRange(DynamicObject string) {
return StringOperations.codeRange(string) == CodeRange.CR_BROKEN;
}

public static boolean isBinaryString(DynamicObject string) {
assert RubyGuards.isRubyString(string);
return StringOperations.encoding(string) == ASCIIEncoding.INSTANCE;
}

public static boolean isRopeBuffer(DynamicObject string) {
assert RubyGuards.isRubyString(string);

Original file line number Diff line number Diff line change
@@ -773,6 +773,13 @@ public int byteSize(DynamicObject string, @Cached("createBinaryProfile()") Condi
})
public abstract static class CaseCmpNode extends CoreMethodNode {

@Child private EncodingNodes.CompatibleQueryNode compatibleQueryNode;

public CaseCmpNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
compatibleQueryNode = EncodingNodesFactory.CompatibleQueryNodeFactory.create(context, sourceSection, new RubyNode[] {});
}

@CreateCast("other") public RubyNode coerceOtherToString(RubyNode other) {
return ToStrNodeGen.create(null, null, other);
}
@@ -782,7 +789,7 @@ public abstract static class CaseCmpNode extends CoreMethodNode {
public Object caseCmpSingleByte(DynamicObject string, DynamicObject other) {
// Taken from org.jruby.RubyString#casecmp19.

if (RopeOperations.areCompatible(rope(string), rope(other)) == null) {
if (compatibleQueryNode.executeCompatibleQuery(string, other) == nil()) {
return nil();
}

@@ -794,13 +801,13 @@ public Object caseCmpSingleByte(DynamicObject string, DynamicObject other) {
public Object caseCmp(DynamicObject string, DynamicObject other) {
// Taken from org.jruby.RubyString#casecmp19 and

final Encoding encoding = RopeOperations.areCompatible(rope(string), rope(other));
final DynamicObject encoding = compatibleQueryNode.executeCompatibleQuery(string, other);

if (encoding == null) {
if (encoding == nil()) {
return nil();
}

return multiByteCasecmp(encoding, StringOperations.getByteListReadOnly(string), StringOperations.getByteListReadOnly(other));
return multiByteCasecmp(Layouts.ENCODING.getEncoding(encoding), StringOperations.getByteListReadOnly(string), StringOperations.getByteListReadOnly(other));
}

@TruffleBoundary
@@ -1116,7 +1123,7 @@ public EachCharNode(RubyContext context, SourceSection sourceSection) {
makeSubstringNode = RopeNodesFactory.MakeSubstringNodeGen.create(null, null, null);
}

@Specialization(guards = "isValidOr7BitEncoding(string)")
@Specialization(guards = "!isBrokenCodeRange(string)")
public DynamicObject eachChar(VirtualFrame frame, DynamicObject string, DynamicObject block) {
final Rope rope = rope(string);
final byte[] ptrBytes = rope.getBytes();
@@ -1134,7 +1141,7 @@ public DynamicObject eachChar(VirtualFrame frame, DynamicObject string, DynamicO
return string;
}

@Specialization(guards = "!isValidOr7BitEncoding(string)")
@Specialization(guards = "isBrokenCodeRange(string)")
public DynamicObject eachCharMultiByteEncoding(VirtualFrame frame, DynamicObject string, DynamicObject block) {
final Rope rope = rope(string);
final byte[] ptrBytes = rope.getBytes();