-
-
Notifications
You must be signed in to change notification settings - Fork 925
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Truffle] Flatten ropes before decoding.
- 9.4.12.0
- 9.4.11.0
- 9.4.10.0
- 9.4.9.0
- 9.4.8.0
- 9.4.7.0
- 9.4.6.0
- 9.4.5.0
- 9.4.4.0
- 9.4.3.0
- 9.4.2.0
- 9.4.1.0
- 9.4.0.0
- 9.3.15.0
- 9.3.14.0
- 9.3.13.0
- 9.3.12.0
- 9.3.11.0
- 9.3.10.0
- 9.3.9.0
- 9.3.8.0
- 9.3.7.0
- 9.3.6.0
- 9.3.5.0
- 9.3.4.0
- 9.3.3.0
- 9.3.2.0
- 9.3.1.0
- 9.3.0.0
- 9.2.21.0
- 9.2.20.1
- 9.2.20.0
- 9.2.19.0
- 9.2.18.0
- 9.2.17.0
- 9.2.16.0
- 9.2.15.0
- 9.2.14.0
- 9.2.13.0
- 9.2.12.0
- 9.2.11.1
- 9.2.11.0
- 9.2.10.0
- 9.2.9.0
- 9.2.8.0
- 9.2.7.0
- 9.2.6.0
- 9.2.5.0
- 9.2.4.1
- 9.2.4.0
- 9.2.3.0
- 9.2.2.0
- 9.2.1.0
- 9.2.0.0
- 9.1.17.0
- 9.1.16.0
- 9.1.15.0
- 9.1.14.0
- 9.1.13.0
- 9.1.12.0
- 9.1.11.0
- 9.1.10.0
- 9.1.9.0
- 9.1.8.0
- 9.1.7.0
- 9.1.6.0
- 9.1.5.0
- 9.1.4.0
- 9.1.3.0
- 9.1.2.0
- 9.1.1.0
1 parent
186aabf
commit e3d6421
Showing
1 changed file
with
4 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
chrisseaton
Author
Contributor
|
||
|
||
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()); | ||
} | ||
|
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 callingRope#getBytes
, which will flatten implicitly. But we can save that for a second pass.