Skip to content

Commit 6c67f87

Browse files
committed
extract code, better profiling
1 parent 1340cb4 commit 6c67f87

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

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

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -432,26 +432,12 @@ public Rope concat(ManagedRope left, ManagedRope right, Encoding encoding,
432432
throw new RaiseException(getContext(), getContext().getCoreExceptions().argumentError("Result of string concatenation exceeds the system maximum string length", this));
433433
}
434434

435-
if (shouldRebalanceProfile.profile(left.depth() >= getContext().getOptions().ROPE_DEPTH_THRESHOLD)) {
436-
if (flattenNode == null) {
437-
CompilerDirectives.transferToInterpreterAndInvalidate();
438-
flattenNode = insert(FlattenNode.create());
439-
}
440-
441-
if (left instanceof ConcatRope) {
442-
left = rebalance((ConcatRope) left, getContext().getOptions().ROPE_DEPTH_THRESHOLD, flattenNode);
443-
}
435+
if (shouldRebalanceProfile.profile(left.depth() >= getContext().getOptions().ROPE_DEPTH_THRESHOLD && left instanceof ConcatRope)) {
436+
left = rebalance((ConcatRope) left, getContext().getOptions().ROPE_DEPTH_THRESHOLD, getFlattenNode());
444437
}
445438

446-
if (shouldRebalanceProfile.profile(right.depth() >= getContext().getOptions().ROPE_DEPTH_THRESHOLD)) {
447-
if (flattenNode == null) {
448-
CompilerDirectives.transferToInterpreterAndInvalidate();
449-
flattenNode = insert(FlattenNode.create());
450-
}
451-
452-
if (right instanceof ConcatRope) {
453-
right = rebalance((ConcatRope) right, getContext().getOptions().ROPE_DEPTH_THRESHOLD, flattenNode);
454-
}
439+
if (shouldRebalanceProfile.profile(right.depth() >= getContext().getOptions().ROPE_DEPTH_THRESHOLD && right instanceof ConcatRope)) {
440+
right = rebalance((ConcatRope) right, getContext().getOptions().ROPE_DEPTH_THRESHOLD, getFlattenNode());
455441
}
456442

457443
int depth = depth(left, right);
@@ -465,6 +451,14 @@ public Rope concat(ManagedRope left, ManagedRope right, Encoding encoding,
465451
depth, isBalanced(left, right));
466452
}
467453

454+
private FlattenNode getFlattenNode() {
455+
if (flattenNode == null) {
456+
CompilerDirectives.transferToInterpreterAndInvalidate();
457+
flattenNode = insert(FlattenNode.create());
458+
}
459+
return flattenNode;
460+
}
461+
468462
private boolean isBalanced(Rope left, Rope right) {
469463
// Our definition of balanced is centered around the notion of rebalancing. We could have a simple structure
470464
// such as ConcatRope(ConcatRope(LeafRope, LeafRope), LeafRope) that is balanced on its own but may contribute

0 commit comments

Comments
 (0)