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

Commits on Apr 16, 2016

  1. Copy the full SHA
    e25eac8 View commit details
  2. Copy the full SHA
    946318a View commit details
Original file line number Diff line number Diff line change
@@ -1771,6 +1771,7 @@ private Object stringSubstringMultitByte(DynamicObject string, int beg, int len)

final Rope rope = rope(string);
final int length = rope.byteLength();
final boolean isMutableRope = rope instanceof RopeBuffer;

final Encoding enc = rope.getEncoding();
int p;
@@ -1792,6 +1793,11 @@ private Object stringSubstringMultitByte(DynamicObject string, int beg, int len)
if (p == -1) {
return nil();
}

if (isMutableRope) {
return makeBuffer(string, p - s, e - p);
}

return makeRope(string, rope, p - s, e - p);
} else {
beg += rope.characterLength();
@@ -1824,6 +1830,10 @@ private Object stringSubstringMultitByte(DynamicObject string, int beg, int len)
len = StringSupport.offset(enc, bytes, p, end, len);
}

if (isMutableRope) {
return makeBuffer(string, p - s, len);
}

return makeRope(string, rope, p - s, len);
}

@@ -1869,11 +1879,6 @@ private DynamicObject makeRope(DynamicObject string, Rope rope, int beg, int len
private DynamicObject makeBuffer(DynamicObject string, int beg, int len) {
assert RubyGuards.isRubyString(string);

if (!StringGuards.isSingleByteOptimizable(string)) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreExceptions().internalError("Taking the substring of MBC rope buffer is not currently supported", this));
}

final RopeBuffer buffer = (RopeBuffer) rope(string);

if (allocateNode == null) {
Original file line number Diff line number Diff line change
@@ -1825,12 +1825,17 @@ public SizeNode(RubyContext context, SourceSection sourceSection) {

@Specialization
public int size(DynamicObject string,
@Cached("createBinaryProfile()") ConditionProfile mutableRopeProfile) {
@Cached("createBinaryProfile()") ConditionProfile ropeBufferProfile,
@Cached("createBinaryProfile()") ConditionProfile isSingleByteOptimizableRopeBufferProfile) {
final Rope rope = rope(string);

if (mutableRopeProfile.profile(rope instanceof RopeBuffer)) {
// TODO (nirvdrum 11-Mar-16): This response is only correct for CR_7BIT. Mutable ropes have not been updated for multi-byte characters.
return ((RopeBuffer) rope).getByteList().realSize();
if (ropeBufferProfile.profile(rope instanceof RopeBuffer)) {
if (isSingleByteOptimizableRopeBufferProfile.profile(rope.isSingleByteOptimizable())) {
return ((RopeBuffer) rope).getByteList().realSize();
} else {
final ByteList byteList = ((RopeBuffer) rope).getByteList();
return RopeOperations.strLength(rope.getEncoding(), byteList.unsafeBytes(), byteList.begin(), byteList.realSize());
}
} else {
return rope.characterLength();
}