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

Commits on Apr 6, 2016

  1. [Truffle] Replaced the ByteList 'realSize' helpers with direct calls …

    …to byteLength to clean up the API.
    nirvdrum committed Apr 6, 2016
    Copy the full SHA
    62614b4 View commit details
  2. [Truffle] Replaced all usages of Rope#getBegin with Rope#begin.

    These methods do the same thing. They're a legacy of the conversion from ByteList, which  defines both methods but can't delete one as it would break a public API.
    nirvdrum committed Apr 6, 2016
    Copy the full SHA
    d38b7b6 View commit details
Original file line number Diff line number Diff line change
@@ -205,7 +205,7 @@ public Object getIndex(DynamicObject matchData, int index, int length) {
public Object getIndexSymbol(DynamicObject matchData, DynamicObject index, NotProvided length) {
try {
final Rope value = Layouts.SYMBOL.getRope(index);
final int i = Layouts.REGEXP.getRegex(Layouts.MATCH_DATA.getRegexp(matchData)).nameToBackrefNumber(value.getBytes(), value.getBegin(), value.getBegin() + value.getRealSize(), Layouts.MATCH_DATA.getRegion(matchData));
final int i = Layouts.REGEXP.getRegex(Layouts.MATCH_DATA.getRegexp(matchData)).nameToBackrefNumber(value.getBytes(), value.begin(), value.begin() + value.byteLength(), Layouts.MATCH_DATA.getRegion(matchData));

return getIndex(matchData, i, NotProvided.INSTANCE);
} catch (final ValueException e) {
@@ -221,7 +221,7 @@ public Object getIndexSymbol(DynamicObject matchData, DynamicObject index, NotPr
public Object getIndexString(DynamicObject matchData, DynamicObject index, NotProvided length) {
try {
final Rope value = StringOperations.rope(index);
final int i = Layouts.REGEXP.getRegex(Layouts.MATCH_DATA.getRegexp(matchData)).nameToBackrefNumber(value.getBytes(), value.getBegin(), value.getBegin() + value.getRealSize(), Layouts.MATCH_DATA.getRegion(matchData));
final int i = Layouts.REGEXP.getRegex(Layouts.MATCH_DATA.getRegexp(matchData)).nameToBackrefNumber(value.getBytes(), value.begin(), value.begin() + value.byteLength(), Layouts.MATCH_DATA.getRegion(matchData));

return getIndex(matchData, i, NotProvided.INSTANCE);
}
Original file line number Diff line number Diff line change
@@ -86,8 +86,8 @@ public static Object matchCommon(RubyContext context, RopeNodes.MakeSubstringNod
final ByteList preprocessed = RegexpSupport.preprocess(context.getJRubyRuntime(), RopeOperations.getByteListReadOnly(regexpSourceRope), enc, new Encoding[] { null }, RegexpSupport.ErrorMode.RAISE);

final Regex r = new Regex(preprocessed.getUnsafeBytes(), preprocessed.getBegin(), preprocessed.getBegin() + preprocessed.getRealSize(), Layouts.REGEXP.getOptions(regexp).toJoniOptions(), checkEncoding(regexp, sourceRope, true));
final Matcher matcher = r.matcher(sourceRope.getBytes(), sourceRope.begin(), sourceRope.begin() + sourceRope.realSize());
int range = sourceRope.begin() + sourceRope.realSize();
final Matcher matcher = r.matcher(sourceRope.getBytes(), sourceRope.begin(), sourceRope.begin() + sourceRope.byteLength());
int range = sourceRope.begin() + sourceRope.byteLength();

return matchCommon(context, makeSubstringNode, regexp, source, operator, setNamedCaptures, matcher, sourceRope.begin() + startPos, range);
}
13 changes: 0 additions & 13 deletions truffle/src/main/java/org/jruby/truffle/core/rope/Rope.java
Original file line number Diff line number Diff line change
@@ -10,7 +10,6 @@
package org.jruby.truffle.core.rope;

import org.jcodings.Encoding;
import org.jruby.util.ByteList;

import java.util.Arrays;

@@ -89,18 +88,6 @@ public int begin() {
return 0;
}

public int getBegin() {
return begin();
}

public int realSize() {
return byteLength();
}

public int getRealSize() {
return realSize();
}

@Override
public int hashCode() {
if (hashCode == 0) {
Original file line number Diff line number Diff line change
@@ -114,7 +114,7 @@ public static String decodeUTF8(Rope rope) {
@TruffleBoundary
public static String decodeRope(Ruby runtime, Rope value) {
if (value instanceof LeafRope) {
int begin = value.getBegin();
int begin = value.begin();
int length = value.byteLength();

Encoding encoding = value.getEncoding();
@@ -411,8 +411,8 @@ public static int cmp(Rope string, Rope other) {
// Taken from org.jruby.util.ByteList#cmp.

if (string == other) return 0;
final int size = string.realSize();
final int len = Math.min(size, other.realSize());
final int size = string.byteLength();
final int len = Math.min(size, other.byteLength());
int offset = -1;

final byte[] bytes = string.getBytes();
@@ -428,7 +428,7 @@ public static int cmp(Rope string, Rope other) {
if (offset < len) {
return (bytes[string.begin() + offset]&0xFF) > (otherBytes[other.begin() + offset]&0xFF) ? 1 : -1;
}
return size == other.realSize() ? 0 : size == len ? -1 : 1;
return size == other.byteLength() ? 0 : size == len ? -1 : 1;
}

@TruffleBoundary
Original file line number Diff line number Diff line change
@@ -213,11 +213,11 @@ public boolean fnmatch(DynamicObject pattern, DynamicObject path, int flags) {
final Rope pathRope = rope(path);

return Dir.fnmatch(patternRope.getBytes(),
patternRope.getBegin(),
patternRope.getBegin() + patternRope.getRealSize(),
patternRope.begin(),
patternRope.begin() + patternRope.byteLength(),
pathRope.getBytes(),
pathRope.getBegin(),
pathRope.getBegin() + pathRope.getRealSize(),
pathRope.begin(),
pathRope.begin() + pathRope.byteLength(),
flags) != Dir.FNM_NOMATCH;
}

Original file line number Diff line number Diff line change
@@ -145,8 +145,8 @@ public Object searchRegion(DynamicObject regexp, DynamicObject string, int start
final Encoding enc = RegexpNodes.checkEncoding(regexp, stringRope, true);
ByteList preprocessed = RegexpSupport.preprocess(getContext().getJRubyRuntime(), RopeOperations.getByteListReadOnly(regexpSourceRope), enc, new Encoding[]{null}, RegexpSupport.ErrorMode.RAISE);
Rope preprocessedRope = RegexpNodes.shimModifiers(StringOperations.ropeFromByteList(preprocessed));
final Regex r = new Regex(preprocessedRope.getBytes(), preprocessedRope.getBegin(), preprocessedRope.getBegin() + preprocessedRope.getRealSize(), Layouts.REGEXP.getRegex(regexp).getOptions(), RegexpNodes.checkEncoding(regexp, stringRope, true));
final Matcher matcher = r.matcher(stringRope.getBytes(), stringRope.begin(), stringRope.begin() + stringRope.realSize());
final Regex r = new Regex(preprocessedRope.getBytes(), preprocessedRope.begin(), preprocessedRope.begin() + preprocessedRope.byteLength(), Layouts.REGEXP.getRegex(regexp).getOptions(), RegexpNodes.checkEncoding(regexp, stringRope, true));
final Matcher matcher = r.matcher(stringRope.getBytes(), stringRope.begin(), stringRope.begin() + stringRope.byteLength());

if (forward) {
// Search forward through the string.
Original file line number Diff line number Diff line change
@@ -218,9 +218,9 @@ public DynamicObject stringAwkSplit(DynamicObject string, int lim) {
int i = lim > 0 ? 1 : 0;

byte[]bytes = rope.getBytes();
int p = rope.getBegin();
int p = rope.begin();
int ptr = p;
int len = rope.getRealSize();
int len = rope.byteLength();
int end = p + len;
Encoding enc = rope.getEncoding();
boolean skip = true;
@@ -490,8 +490,8 @@ public int stringCompareSubstring(VirtualFrame frame, DynamicObject string, Dyna
final Rope otherRope = StringOperations.rope(other);

// TODO (nirvdrum 21-Jan-16): Reimplement with something more friendly to rope byte[] layout?
return ByteList.memcmp(rope.getBytes(), rope.getBegin(), size,
otherRope.getBytes(), otherRope.getBegin() + start, size);
return ByteList.memcmp(rope.getBytes(), rope.begin(), size,
otherRope.getBytes(), otherRope.begin() + start, size);
}

}
@@ -677,7 +677,7 @@ public Object stringFindCharacter(DynamicObject string, int offset,
}

final Encoding enc = rope.getEncoding();
final int clen = StringSupport.preciseLength(enc, rope.getBytes(), rope.begin(), rope.begin() + rope.realSize());
final int clen = StringSupport.preciseLength(enc, rope.getBytes(), rope.begin(), rope.begin() + rope.byteLength());

final DynamicObject ret;
if (StringSupport.MBCLEN_CHARFOUND_P(clen)) {
@@ -849,18 +849,18 @@ private int index(Rope source, Rope other, int offset, Encoding enc) {

if (sourceLen - offset < otherLen) return -1;
byte[]bytes = source.getBytes();
int p = source.getBegin();
int end = p + source.getRealSize();
int p = source.begin();
int end = p + source.byteLength();
if (offset != 0) {
offset = source.isSingleByteOptimizable() ? offset : StringSupport.offset(enc, bytes, p, end, offset);
p += offset;
}
if (otherLen == 0) return offset;

while (true) {
int pos = indexOf(source, other, p - source.getBegin());
int pos = indexOf(source, other, p - source.begin());
if (pos < 0) return pos;
pos -= (p - source.getBegin());
pos -= (p - source.begin());
int t = enc.rightAdjustCharHead(bytes, p, p + pos, end);
if (t == p + pos) return pos + offset;
if ((sourceLen -= t - p) <= 0) return -1;
@@ -875,10 +875,10 @@ private int indexOf(Rope sourceRope, Rope otherRope, int fromIndex) {

final byte[] source = sourceRope.getBytes();
final int sourceOffset = sourceRope.begin();
final int sourceCount = sourceRope.realSize();
final int sourceCount = sourceRope.byteLength();
final byte[] target = otherRope.getBytes();
final int targetOffset = otherRope.begin();
final int targetCount = otherRope.realSize();
final int targetCount = otherRope.byteLength();

if (fromIndex >= sourceCount) return (targetCount == 0 ? sourceCount : -1);
if (fromIndex < 0) fromIndex = 0;
@@ -1107,8 +1107,8 @@ public Object stringByteIndex(DynamicObject string, int index, int start,

final Rope rope = rope(string);
final Encoding enc = rope.getEncoding();
int p = rope.getBegin();
final int e = p + rope.getRealSize();
int p = rope.begin();
final int e = p + rope.byteLength();

int i, k = index;

@@ -1156,10 +1156,10 @@ public Object stringByteIndex(DynamicObject string, DynamicObject pattern, int o
}

final Encoding encoding = StringOperations.checkEncoding(getContext(), string, pattern, this);
int p = stringRope.getBegin();
final int e = p + stringRope.getRealSize();
int pp = patternRope.getBegin();
final int pe = pp + patternRope.getRealSize();
int p = stringRope.begin();
final int e = p + stringRope.byteLength();
int pp = patternRope.begin();
final int pe = pp + patternRope.byteLength();
int s;
int ss;

@@ -1209,8 +1209,8 @@ public Object stringPreviousByteIndex(DynamicObject string, int index) {
}

final Rope rope = rope(string);
final int p = rope.getBegin();
final int end = p + rope.getRealSize();
final int p = rope.begin();
final int end = p + rope.byteLength();

final int b = rope.getEncoding().prevCharHead(rope.getBytes(), p, p + index, end);

Original file line number Diff line number Diff line change
@@ -1502,8 +1502,8 @@ public Object lstripBangSingleByte(DynamicObject string) {
// Taken from org.jruby.RubyString#lstrip_bang19 and org.jruby.RubyString#singleByteLStrip.

final Rope rope = rope(string);
final int s = rope.getBegin();
final int end = s + rope.getRealSize();
final int s = rope.begin();
final int end = s + rope.byteLength();
final byte[] bytes = rope.getBytes();

int p = s;
@@ -1524,8 +1524,8 @@ public Object lstripBang(DynamicObject string) {

final Rope rope = rope(string);
final Encoding enc = RopeOperations.STR_ENC_GET(rope);
final int s = rope.getBegin();
final int end = s + rope.getRealSize();
final int s = rope.begin();
final int end = s + rope.byteLength();
final byte[] bytes = rope.getBytes();

int p = s;
@@ -1620,7 +1620,7 @@ public int ord(DynamicObject string) {
final Rope rope = rope(string);

try {
return codePoint(rope.getEncoding(), rope.getBytes(), rope.begin(), rope.begin() + rope.realSize());
return codePoint(rope.getEncoding(), rope.getBytes(), rope.begin(), rope.begin() + rope.byteLength());
} catch (IllegalArgumentException e) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(coreLibrary().argumentError(e.getMessage(), this));
@@ -1767,8 +1767,8 @@ public DynamicObject swapcaseSingleByte(DynamicObject string,
return nil();
}

final int s = rope.getBegin();
final int end = s + rope.getRealSize();
final int s = rope.begin();
final int end = s + rope.byteLength();
final byte[] bytes = rope.getBytesCopy();

if (singleByteOptimizableProfile.profile(rope.isSingleByteOptimizable())) {
@@ -2080,8 +2080,8 @@ public Object sum(VirtualFrame frame, DynamicObject string, long bits) {

final Rope rope = rope(string);
final byte[] bytes = rope.getBytes();
int p = rope.getBegin();
final int len = rope.getRealSize();
int p = rope.begin();
final int len = rope.byteLength();
final int end = p + len;

if (bits >= 8 * 8) { // long size * bits in byte