Skip to content

Commit

Permalink
Showing 1 changed file with 4 additions and 20 deletions.
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);

This comment has been minimized.

Copy link
@nirvdrum

nirvdrum May 9, 2016

Contributor

This is fine, but looking a bit more, it creates a whole new rope that we then discard. flattenBytes would probably be better. Or just calling Rope#getBytes, which will flatten implicitly. But we can save that for a second pass.

This comment has been minimized.

Copy link
@chrisseaton

chrisseaton May 9, 2016

Author Contributor

I was hoping to have the underlying problem resolve before we need high performance for anything again.


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());
}

0 comments on commit e3d6421

Please sign in to comment.