Skip to content

Commit cbb4d72

Browse files
author
Nicolas Laurent
committed
[GR-20459] Add upper bound to ExplodedLoop use in ConcatNodes, and merge node calls.
PullRequest: truffleruby/1251
2 parents c35dcbe + 75d523e commit cbb4d72

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

src/main/java/org/truffleruby/core/array/ArrayNodes.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,11 @@ protected DynamicObject concatOne(DynamicObject array, DynamicObject first, Obje
429429
}
430430

431431
@ExplodeLoop
432-
@Specialization(guards = { "wasProvided(first)", "rest.length > 0", "rest.length == cachedLength" })
432+
@Specialization(guards = {
433+
"wasProvided(first)",
434+
"rest.length > 0",
435+
"rest.length == cachedLength",
436+
"cachedLength <= 8" })
433437
protected Object concatMany(DynamicObject array, DynamicObject first, Object[] rest,
434438
@Cached("rest.length") int cachedLength,
435439
@Cached("createInternal()") ToAryNode toAryNode,
@@ -442,11 +446,10 @@ protected Object concatMany(DynamicObject array, DynamicObject first, Object[] r
442446
DynamicObject copy = createArray(store, size);
443447
DynamicObject result = appendManyNode.executeAppendMany(array, toAryNode.executeToAry(first));
444448
for (int i = 0; i < cachedLength; ++i) {
445-
if (selfArgProfile.profile(rest[i] == array)) {
446-
result = appendManyNode.executeAppendMany(array, copy);
447-
} else {
448-
result = appendManyNode.executeAppendMany(array, toAryNode.executeToAry(rest[i]));
449-
}
449+
final DynamicObject argOrCopy = selfArgProfile.profile(rest[i] == array)
450+
? copy
451+
: toAryNode.executeToAry(rest[i]);
452+
result = appendManyNode.executeAppendMany(array, argOrCopy);
450453
}
451454
return result;
452455
}

src/main/java/org/truffleruby/core/string/StringNodes.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -478,20 +478,19 @@ protected Object concatGeneric(DynamicObject string, Object first, Object[] rest
478478
}
479479

480480
@ExplodeLoop
481-
@Specialization(guards = { "wasProvided(first)", "rest.length > 0", "rest.length == cachedLength" })
481+
@Specialization(guards = { "wasProvided(first)", "rest.length > 0", "rest.length == " +
482+
"cachedLength", "cachedLength <= 8" })
482483
protected Object concatMany(DynamicObject string, Object first, Object[] rest,
483484
@Cached("rest.length") int cachedLength,
484485
@Cached ConcatNode argConcatNode,
485486
@Cached("createBinaryProfile()") ConditionProfile selfArgProfile) {
486487
Rope rope = StringOperations.rope(string);
487488
Object result = argConcatNode.executeConcat(string, first, EMPTY_ARGUMENTS);
488489
for (int i = 0; i < cachedLength; ++i) {
489-
if (selfArgProfile.profile(rest[i] == string)) {
490-
Object copy = createString(getContext(), rope);
491-
result = argConcatNode.executeConcat(string, copy, EMPTY_ARGUMENTS);
492-
} else {
493-
result = argConcatNode.executeConcat(string, rest[i], EMPTY_ARGUMENTS);
494-
}
490+
final Object argOrCopy = selfArgProfile.profile(rest[i] == string)
491+
? createString(getContext(), rope)
492+
: rest[i];
493+
result = argConcatNode.executeConcat(string, argOrCopy, EMPTY_ARGUMENTS);
495494
}
496495
return result;
497496
}

0 commit comments

Comments
 (0)