Skip to content

Commit ac8584d

Browse files
committed
The BoundedIntStack in flattenBytes() needs at most depth / 2 entries
1 parent db50718 commit ac8584d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/main/java/org/truffleruby/core/rope/RopeOperations.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,9 @@ public static byte[] flattenBytes(Rope rope) {
314314
// need to track each SubstringRope's bounded length and how much that bounded length contributes to the total
315315
// byte[] for any ancestor (e.g., a SubstringRope of a ConcatRope with SubstringRopes for each of its children).
316316
// Because we need to track multiple levels, we can't use a single updated int.
317-
final BoundedIntStack substringLengths = new BoundedIntStack(rope.depth());
317+
// SubstringRope.child is never a SubstringRope, so there are most depth / 2 SubstringRope.
318+
// TODO (eregon, 9 July 2020): maybe we should resize dynamically to avoid a too big array if the depth option is large?
319+
final BoundedIntStack substringLengths = new BoundedIntStack(rope.depth() / 2);
318320

319321
final Deque<Rope> workStack = new ArrayDeque<>();
320322
workStack.push(rope);

0 commit comments

Comments
 (0)