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

Commits on Jan 22, 2016

  1. Copy the full SHA
    7c6b98c View commit details
  2. Copy the full SHA
    d366b36 View commit details
  3. Copy the full SHA
    bb00f74 View commit details
Original file line number Diff line number Diff line change
@@ -123,7 +123,7 @@ public DynamicObject add(DynamicObject string, DynamicObject other) {
final Rope left = rope(string);
final Rope right = rope(other);

final Encoding enc = StringOperations.checkEncoding(getContext(), string, StringOperations.getCodeRangeableReadOnly(other), this);
final Encoding enc = StringOperations.checkEncoding(getContext(), string, other, this);

final Rope concatRope = RopeOperations.concat(left, right, enc);

@@ -800,7 +800,7 @@ private int countSlow(DynamicObject string, DynamicObject... otherStrings) {

assert RubyGuards.isRubyString(otherStr);

enc = StringOperations.checkEncoding(getContext(), string, StringOperations.getCodeRangeableReadOnly(otherStr), this);
enc = StringOperations.checkEncoding(getContext(), string, otherStr, this);
tables = StringSupport.trSetupTable(StringOperations.getByteListReadOnly(otherStr), getContext().getRuntime(), table, tables, false, enc);
}

@@ -924,7 +924,7 @@ private Object deleteBangSlow(DynamicObject string, DynamicObject... otherString
assert RubyGuards.isRubyString(string);

DynamicObject otherString = otherStrings[0];
Encoding enc = StringOperations.checkEncoding(getContext(), string, StringOperations.getCodeRangeableReadOnly(otherString), this);
Encoding enc = StringOperations.checkEncoding(getContext(), string, otherString, this);

boolean[] squeeze = new boolean[StringSupport.TRANS_SIZE + 1];
StringSupport.TrTables tables = StringSupport.trSetupTable(StringOperations.getByteListReadOnly(otherString),
@@ -934,7 +934,7 @@ private Object deleteBangSlow(DynamicObject string, DynamicObject... otherString
for (int i = 1; i < otherStrings.length; i++) {
assert RubyGuards.isRubyString(otherStrings[i]);

enc = StringOperations.checkEncoding(getContext(), string, StringOperations.getCodeRangeableReadOnly(otherStrings[i]), this);
enc = StringOperations.checkEncoding(getContext(), string, otherStrings[i], this);
tables = StringSupport.trSetupTable(StringOperations.getByteListReadOnly(otherStrings[i]), getContext().getRuntime(), squeeze, tables, false, enc);
}

@@ -1866,7 +1866,7 @@ private Object performSqueezeBang(DynamicObject string, DynamicObject[] otherStr

DynamicObject otherStr = otherStrings[0];
Rope otherRope = rope(otherStr);
Encoding enc = StringOperations.checkEncoding(getContext(), string, StringOperations.getCodeRangeableReadOnly(otherStr), this);
Encoding enc = StringOperations.checkEncoding(getContext(), string, otherStr, this);
final boolean squeeze[] = new boolean[StringSupport.TRANS_SIZE + 1];
StringSupport.TrTables tables = StringSupport.trSetupTable(otherRope.getUnsafeByteList(), getContext().getRuntime(), squeeze, null, true, enc);

@@ -1875,7 +1875,7 @@ private Object performSqueezeBang(DynamicObject string, DynamicObject[] otherStr
for (int i = 1; i < otherStrings.length; i++) {
otherStr = otherStrings[i];
otherRope = rope(otherStr);
enc = StringOperations.checkEncoding(getContext(), string, StringOperations.getCodeRangeableReadOnly(otherStr), this);
enc = StringOperations.checkEncoding(getContext(), string, otherStr, this);
singlebyte = singlebyte && otherRope.isSingleByteOptimizable();
tables = StringSupport.trSetupTable(otherRope.getUnsafeByteList(), getContext().getRuntime(), squeeze, tables, false, enc);
}
Original file line number Diff line number Diff line change
@@ -1061,7 +1061,7 @@ public Object stringByteIndex(DynamicObject string, DynamicObject pattern, int o
return nil();
}

final Encoding encoding = StringOperations.checkEncoding(getContext(), string, StringOperations.getCodeRangeableReadOnly(pattern), this);
final Encoding encoding = StringOperations.checkEncoding(getContext(), string, pattern, this);
int p = stringRope.getBegin();
final int e = p + stringRope.getRealSize();
int pp = patternRope.getBegin();
Original file line number Diff line number Diff line change
@@ -199,14 +199,13 @@ public static int clampExclusiveIndex(DynamicObject string, int index) {
return ArrayOperations.clampExclusiveIndex(StringOperations.rope(string).byteLength(), index);
}

@CompilerDirectives.TruffleBoundary
public static Encoding checkEncoding(RubyContext context, DynamicObject string, CodeRangeable other, Node node) {
final Encoding encoding = StringSupport.areCompatible(getCodeRangeableReadOnly(string), other);
public static Encoding checkEncoding(RubyContext context, DynamicObject string, DynamicObject other, Node node) {
final Encoding encoding = EncodingNodes.CompatibleQueryNode.compatibleEncodingForStrings(string, other);

if (encoding == null) {
throw new RaiseException(context.getCoreLibrary().encodingCompatibilityErrorIncompatible(
Layouts.STRING.getRope(string).getEncoding().toString(),
other.getByteList().getEncoding().toString(),
rope(string).getEncoding().toString(),
rope(other).getEncoding().toString(),
node));
}

Original file line number Diff line number Diff line change
@@ -137,26 +137,38 @@ public static String decodeUTF8(Rope rope) {

@TruffleBoundary
public static String decodeRope(Ruby runtime, Rope value) {
int begin = value.getBegin();
int length = value.byteLength();
if (value instanceof LeafRope) {
int begin = value.getBegin();
int length = value.byteLength();

Encoding encoding = value.getEncoding();
Encoding encoding = value.getEncoding();

if (encoding == UTF8Encoding.INSTANCE) {
return RubyEncoding.decodeUTF8(value.getBytes(), begin, length);
}
if (encoding == UTF8Encoding.INSTANCE) {
return RubyEncoding.decodeUTF8(value.getBytes(), begin, length);
}

Charset charset = runtime.getEncodingService().charsetForEncoding(encoding);
Charset charset = runtime.getEncodingService().charsetForEncoding(encoding);

if (charset == null) {
try {
return new String(value.getBytes(), begin, length, encoding.toString());
} catch (UnsupportedEncodingException uee) {
return value.toString();
if (charset == null) {
try {
return new String(value.getBytes(), begin, length, encoding.toString());
} catch (UnsupportedEncodingException uee) {
return value.toString();
}
}
}

return RubyEncoding.decode(value.getBytes(), begin, length, charset);
return RubyEncoding.decode(value.getBytes(), begin, length, charset);
} else if (value instanceof SubstringRope) {
final SubstringRope substringRope = (SubstringRope) value;

return decodeRope(runtime, substringRope.getChild()).substring(substringRope.getOffset(), substringRope.getOffset() + substringRope.characterLength());
} else if (value instanceof ConcatRope) {
final ConcatRope concatRope = (ConcatRope) value;

return decodeRope(runtime, concatRope.getLeft()) + decodeRope(runtime, concatRope.getRight());
} else {
throw new RuntimeException("Decoding to String is not supported for rope of type: " + value.getClass().getName());
}
}

// MRI: get_actual_encoding