Skip to content

Commit ae0ba4d

Browse files
author
Nicolas Laurent
committed
fix RopeOperations.anyContains to prevent home path being cached & retained in pre-initialized heap
1 parent be112ed commit ae0ba4d

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -686,12 +686,12 @@ public static boolean isInvalid(byte[] bytes, Encoding encoding) {
686686
public static boolean anyChildContains(Rope rope, String value) {
687687
if (rope instanceof SubstringRope) {
688688
return anyChildContains(((SubstringRope) rope).getChild(), value);
689-
} else if (rope instanceof ConcatRope) {
690-
ConcatChildren children = ((ConcatRope) rope).getChildrenOrNull();
691-
if (children != null) {
692-
return anyChildContains(children.left, value) || anyChildContains(children.right, value);
693-
}
694689
}
695-
return rope.byteLength() < value.length() && RopeOperations.decodeRope(rope).contains(value);
690+
// NOTE(norswap, 18 Dec 2020): We do not treat ConcatRopes specially: `decodeRope` will flatten them
691+
// If we just search left and right, we risk missing the case where the value straddles the two children.
692+
//
693+
// Because of the flattening, the references to the children ropes will be nulled, so we do not need
694+
// to worry about the risk of retaining a substring rope whose child contains the value.
695+
return rope.byteLength() >= value.length() && RopeOperations.decodeRope(rope).contains(value);
696696
}
697697
}

0 commit comments

Comments
 (0)