Skip to content

Commit aa8f330

Browse files
author
Nicolas Laurent
committed
stop tracking whether ConcatRopes are balanced
1 parent 25d182f commit aa8f330

File tree

2 files changed

+6
-40
lines changed

2 files changed

+6
-40
lines changed

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

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,13 @@ public class ConcatRope extends ManagedRope {
1616

1717
private final ManagedRope left;
1818
private final ManagedRope right;
19-
private final boolean balanced;
2019

2120
public ConcatRope(
2221
ManagedRope left,
2322
ManagedRope right,
2423
Encoding encoding,
25-
CodeRange codeRange,
26-
boolean balanced) {
27-
this(left, right, encoding, codeRange, left.characterLength() + right.characterLength(), null, balanced);
24+
CodeRange codeRange) {
25+
this(left, right, encoding, codeRange, left.characterLength() + right.characterLength(), null);
2826
}
2927

3028
private ConcatRope(
@@ -33,8 +31,7 @@ private ConcatRope(
3331
Encoding encoding,
3432
CodeRange codeRange,
3533
int characterLength,
36-
byte[] bytes,
37-
boolean balanced) {
34+
byte[] bytes) {
3835
super(
3936
encoding,
4037
codeRange,
@@ -43,7 +40,6 @@ private ConcatRope(
4340
bytes);
4441
this.left = left;
4542
this.right = right;
46-
this.balanced = balanced;
4743
}
4844

4945
@Override
@@ -55,8 +51,7 @@ Rope withEncoding7bit(Encoding newEncoding) {
5551
newEncoding,
5652
CodeRange.CR_7BIT,
5753
characterLength(),
58-
getRawBytes(),
59-
balanced);
54+
getRawBytes());
6055
}
6156

6257
@Override
@@ -68,8 +63,7 @@ Rope withBinaryEncoding() {
6863
ASCIIEncoding.INSTANCE,
6964
CodeRange.CR_VALID,
7065
byteLength(),
71-
getRawBytes(),
72-
balanced);
66+
getRawBytes());
7367
}
7468

7569
public ManagedRope getLeft() {
@@ -79,9 +73,4 @@ public ManagedRope getLeft() {
7973
public ManagedRope getRight() {
8074
return right;
8175
}
82-
83-
public boolean isBalanced() {
84-
return balanced;
85-
}
86-
8776
}

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

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -480,32 +480,9 @@ protected Rope concat(ManagedRope left, ManagedRope right, Encoding encoding,
480480
left.getCodeRange(),
481481
right.getCodeRange(),
482482
sameCodeRangeProfile,
483-
brokenCodeRangeProfile),
484-
isBalanced(left, right));
485-
}
486-
487-
private boolean isBalanced(Rope left, Rope right) {
488-
// Our definition of balanced is centered around the notion of rebalancing. We could have a simple structure
489-
// such as ConcatRope(ConcatRope(LeafRope, LeafRope), LeafRope) that is balanced on its own but may contribute
490-
// to an unbalanced rope when combined with another rope of similar structure. To keep things simple, we only
491-
// consider ConcatRopes that consist of two non-ConcatRopes balanced as the base case and ConcatRopes that
492-
// have balanced ConcatRopes for both children are balanced by induction.
493-
if (left instanceof ConcatRope) {
494-
if (right instanceof ConcatRope) {
495-
return ((ConcatRope) left).isBalanced() && ((ConcatRope) right).isBalanced();
496-
}
497-
498-
return false;
499-
} else {
500-
// We treat the concatenation of two non-ConcatRopes as balanced, even if their children not balanced.
501-
// E.g., a SubstringRope whose child is an unbalanced ConcatRope arguable isn't balanced. However,
502-
// the code is much simpler by handling it this way. Balanced ConcatRopes will never rebalance, but
503-
// if they become part of a larger subtree that exceeds the depth threshold, they may be flattened.
504-
return !(right instanceof ConcatRope);
505-
}
483+
brokenCodeRangeProfile));
506484
}
507485

508-
509486
@SuppressFBWarnings("RV")
510487
@Specialization(guards = { "!left.isEmpty()", "!right.isEmpty()", "isCodeRangeBroken(left, right)" })
511488
protected Rope concatCrBroken(ManagedRope left, ManagedRope right, Encoding encoding,

0 commit comments

Comments
 (0)