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

Commits on Mar 10, 2016

  1. Copy the full SHA
    7ff4055 View commit details
  2. Copy the full SHA
    d4882b5 View commit details
Original file line number Diff line number Diff line change
@@ -26,6 +26,8 @@ public static Encoding getEncoding(DynamicObject rubyEncoding) {
Encoding encoding = Layouts.ENCODING.getEncoding(rubyEncoding);

if (encoding == null) {
CompilerDirectives.transferToInterpreter();

final ByteList name = Layouts.ENCODING.getName(rubyEncoding);
encoding = loadEncoding(name);
Layouts.ENCODING.setEncoding(rubyEncoding, encoding);
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@

package org.jruby.truffle.core.rope;

import com.oracle.truffle.api.CompilerDirectives;
import org.jcodings.Encoding;

public class AsciiOnlyLeafRope extends LeafRope {
@@ -18,4 +19,13 @@ public AsciiOnlyLeafRope(byte[] bytes, Encoding encoding) {
super(bytes, encoding, CodeRange.CR_7BIT, true, bytes.length);
}

@Override
public Rope withEncoding(Encoding newEncoding, CodeRange newCodeRange) {
if (newCodeRange != getCodeRange()) {
CompilerDirectives.transferToInterpreter();
throw new UnsupportedOperationException("Cannot fast-path updating encoding with different code range.");
}

return new AsciiOnlyLeafRope(getRawBytes(), newEncoding);
}
}
15 changes: 15 additions & 0 deletions truffle/src/main/java/org/jruby/truffle/core/rope/ConcatRope.java
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@
*/
package org.jruby.truffle.core.rope;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import org.jcodings.Encoding;

@@ -18,6 +19,10 @@ public class ConcatRope extends Rope {
private final Rope right;

public ConcatRope(Rope left, Rope right, Encoding encoding, CodeRange codeRange, boolean singleByteOptimizable, int depth) {
this(left, right, encoding, codeRange, singleByteOptimizable, depth, null);
}

private ConcatRope(Rope left, Rope right, Encoding encoding, CodeRange codeRange, boolean singleByteOptimizable, int depth, byte[] bytes) {
super(encoding,
codeRange,
singleByteOptimizable,
@@ -30,6 +35,16 @@ public ConcatRope(Rope left, Rope right, Encoding encoding, CodeRange codeRange,
this.right = right;
}

@Override
public Rope withEncoding(Encoding newEncoding, CodeRange newCodeRange) {
if (newCodeRange != getCodeRange()) {
CompilerDirectives.transferToInterpreter();
throw new UnsupportedOperationException("Cannot fast-path updating encoding with different code range.");
}

return new ConcatRope(getLeft(), getRight(), newEncoding, newCodeRange, isSingleByteOptimizable(), depth(), getRawBytes());
}

@Override
@TruffleBoundary
public byte getByteSlow(int index) {
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@

package org.jruby.truffle.core.rope;

import com.oracle.truffle.api.CompilerDirectives;
import org.jcodings.Encoding;

public class InvalidLeafRope extends LeafRope {
@@ -18,4 +19,13 @@ public InvalidLeafRope(byte[] bytes, Encoding encoding) {
super(bytes, encoding, CodeRange.CR_BROKEN, false, bytes.length);
}

@Override
public Rope withEncoding(Encoding newEncoding, CodeRange newCodeRange) {
if (newCodeRange != getCodeRange()) {
CompilerDirectives.transferToInterpreter();
throw new UnsupportedOperationException("Cannot fast-path updating encoding with different code range.");
}

return new InvalidLeafRope(getRawBytes(), newEncoding);
}
}
2 changes: 2 additions & 0 deletions truffle/src/main/java/org/jruby/truffle/core/rope/Rope.java
Original file line number Diff line number Diff line change
@@ -36,6 +36,8 @@ protected Rope(Encoding encoding, CodeRange codeRange, boolean singleByteOptimiz
this.bytes = bytes;
}

public abstract Rope withEncoding(Encoding newEncoding, CodeRange newCodeRange);

public final int characterLength() {
return characterLength;
}
Original file line number Diff line number Diff line change
@@ -82,6 +82,14 @@ public static Rope withEncoding(Rope originalRope, Encoding newEncoding, CodeRan
return originalRope;
}

if (originalRope.getCodeRange() == newCodeRange) {
return originalRope.withEncoding(newEncoding, newCodeRange);
}

if ((originalRope.getCodeRange() == CR_7BIT) && newEncoding.isAsciiCompatible()) {
return originalRope.withEncoding(newEncoding, CR_7BIT);
}

return create(originalRope.getBytes(), newEncoding, newCodeRange);
}

Original file line number Diff line number Diff line change
@@ -10,18 +10,36 @@

package org.jruby.truffle.core.rope;

import com.oracle.truffle.api.CompilerDirectives;
import org.jcodings.Encoding;

public class SubstringRope extends Rope {

private final Rope child;
private final int offset;

public SubstringRope(Rope child, int offset, int byteLength, int characterLength, CodeRange codeRange) {
// TODO (nirvdrum 07-Jan-16) Verify that this rope is only used for character substrings and not arbitrary byte slices. The former should always have the child's code range while the latter may not.
super(child.getEncoding(), codeRange, child.isSingleByteOptimizable(), byteLength, characterLength, child.depth() + 1, null);
this(child, child.getEncoding(), offset, byteLength, characterLength, codeRange);
}

private SubstringRope(Rope child, Encoding encoding, int offset, int byteLength, int characterLength, CodeRange codeRange) {
// TODO (nirvdrum 07-Jan-16) Verify that this rope is only used for character substrings and not arbitrary byte slices. The former should always have the child's code range while the latter may not.
super(encoding, codeRange, child.isSingleByteOptimizable(), byteLength, characterLength, child.depth() + 1, null);
this.child = child;
this.offset = offset;
}

@Override
public Rope withEncoding(Encoding newEncoding, CodeRange newCodeRange) {
if (newCodeRange != getCodeRange()) {
CompilerDirectives.transferToInterpreter();
throw new UnsupportedOperationException("Cannot fast-path updating encoding with different code range.");
}

return new SubstringRope(getChild(), newEncoding, getOffset(), byteLength(), characterLength(), newCodeRange);
}

@Override
public byte getByteSlow(int index) {
return child.getByteSlow(index + offset);
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@

package org.jruby.truffle.core.rope;

import com.oracle.truffle.api.CompilerDirectives;
import org.jcodings.Encoding;

public class ValidLeafRope extends LeafRope {
@@ -18,4 +19,14 @@ public ValidLeafRope(byte[] bytes, Encoding encoding, int characterLength) {
super(bytes, encoding, CodeRange.CR_VALID, encoding.isSingleByte(), characterLength);
}

@Override
public Rope withEncoding(Encoding newEncoding, CodeRange newCodeRange) {
if (newCodeRange != getCodeRange()) {
CompilerDirectives.transferToInterpreter();
throw new UnsupportedOperationException("Cannot fast-path updating encoding with different code range.");
}

// TODO (nirvdrum 08-Mar-16): This should recalculate the character length since the new encoding may treat the bytes differently.
return new ValidLeafRope(getRawBytes(), newEncoding, characterLength());
}
}