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

Commits on May 9, 2016

  1. Copy the full SHA
    b8bb12f View commit details
  2. [Truffle] Remove visitBytes for now - implement just as a flatten, as…

    … the recursive nature is problematic.
    chrisseaton committed May 9, 2016
    Copy the full SHA
    186aabf View commit details
  3. 2
    Copy the full SHA
    e3d6421 View commit details
Showing with 13 additions and 91 deletions.
  1. +6 −90 truffle/src/main/java/org/jruby/truffle/core/rope/RopeOperations.java
  2. +7 −1 truffle/src/main/java/org/jruby/truffle/stdlib/CoverageManager.java
Original file line number Diff line number Diff line change
@@ -120,6 +120,10 @@ public static String decodeUTF8(Rope rope) {

@TruffleBoundary
public static String decodeRope(Ruby runtime, Rope value) {
// TODO CS 9-May-16 having recursive problems with this, so flatten up front for now

value = flatten(value);

if (value instanceof LeafRope) {
int begin = 0;
int length = value.byteLength();
@@ -146,26 +150,6 @@ public static String decodeRope(Ruby runtime, Rope value) {
}

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 if (value instanceof RepeatingRope) {
final RepeatingRope repeatingRope = (RepeatingRope) value;

final String childString = decodeRope(runtime, repeatingRope.getChild());
final StringBuilder builder = new StringBuilder(childString.length() * repeatingRope.getTimes());
for (int i = 0; i < repeatingRope.getTimes(); i++) {
builder.append(childString);
}

return builder.toString();
} else if (value instanceof LazyIntRope) {
return Integer.toString(((LazyIntRope) value).getValue());
} else {
throw new RuntimeException("Decoding to String is not supported for rope of type: " + value.getClass().getName());
}
@@ -222,77 +206,9 @@ public static void visitBytes(Rope rope, BytesVisitor visitor) {

@TruffleBoundary
public static void visitBytes(Rope rope, BytesVisitor visitor, int offset, int length) {
/*
* TODO: CS-7-Apr-16 rewrite this to be iterative as flattenBytes is, but with new logic for offset and length
* creating a range, then write flattenBytes in terms of visitBytes.
*/

assert length <= rope.byteLength();

if (rope.getRawBytes() != null) {
visitor.accept(rope.getRawBytes(), offset, length);
} else if (rope instanceof ConcatRope) {
final ConcatRope concat = (ConcatRope) rope;

final int leftLength = concat.getLeft().byteLength();

if (offset < leftLength) {
/*
* The left branch might not be large enough to extract the full byte range we want. In that case,
* we'll extract what we can and extract the difference from the right side.
*/

final int leftUsed;

if (offset + length > leftLength) {
leftUsed = leftLength - offset;
} else {
leftUsed = length;
}

visitBytes(concat.getLeft(), visitor, offset, leftUsed);
// TODO CS 9-May-16 make this the primitive, and have flatten use it

if (leftUsed < length) {
visitBytes(concat.getRight(), visitor, 0, length - leftUsed);
}
} else {
visitBytes(concat.getRight(), visitor, offset - leftLength, length);
}
} else if (rope instanceof SubstringRope) {
final SubstringRope substring = (SubstringRope) rope;

visitBytes(substring.getChild(), visitor, substring.getOffset() + offset, length);
} else if (rope instanceof RepeatingRope) {
final RepeatingRope repeating = (RepeatingRope) rope;
final Rope child = repeating.getChild();

final int start = offset % child.byteLength();
final int firstPartLength = Math.min(child.byteLength() - start, length);

visitBytes(child, visitor, start, firstPartLength);

final int lengthMinusFirstPart = length - firstPartLength;
final int remainingEnd = lengthMinusFirstPart % child.byteLength();

if (lengthMinusFirstPart >= child.byteLength()) {
final byte[] secondPart = child.getBytes();

final int repeatPartCount = lengthMinusFirstPart / child.byteLength();
for (int i = 0; i < repeatPartCount; i++) {
visitBytes(child, visitor, 0, secondPart.length);
}

if (remainingEnd > 0) {
visitBytes(child, visitor, 0, remainingEnd);
}
} else if (remainingEnd > 0) {
visitBytes(child, visitor, 0, remainingEnd);
}
} else if (rope instanceof LazyRope) {
visitor.accept(rope.getBytes(), offset, length);
} else {
throw new UnsupportedOperationException("Don't know how to visit rope of type: " + rope.getClass().getName());
}
visitor.accept(flattenBytes(rope), offset, length);
}

@TruffleBoundary
Original file line number Diff line number Diff line change
@@ -89,7 +89,9 @@ protected void onEnter(VirtualFrame frame) {
lineNumber = sourceSection.getStartLine() - 1;
}

counters.incrementAndGet(lineNumber);
if (counters != null) {
counters.incrementAndGet(lineNumber);
}
}

};
@@ -101,6 +103,10 @@ protected void onEnter(VirtualFrame frame) {
}

private synchronized AtomicLongArray getCounters(Source source) {
if (source.getPath() == null) {
return null;
}

AtomicLongArray c = counters.get(source);

if (c == null) {