Skip to content

Commit 8d5452c

Browse files
Speeding up non-reordering reorderOnly case twice
1 parent 2301f9b commit 8d5452c

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoMultiValue.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -541,20 +541,25 @@ public static CastToNode getUncached() {
541541
*/
542542
public final Object findTypeOrNull(
543543
Type type, EnsoMultiValue mv, boolean reorderOnly, boolean allTypes) {
544-
var i = findNode.executeFindIndex(type, mv.dispatch);
544+
var dispatch = mv.dispatch;
545+
var i = findNode.executeFindIndex(type, dispatch);
545546
if (i == -1 && allTypes) {
546547
var extraIndex = findNode.executeFindIndex(type, mv.extra);
547-
i = extraIndex == -1 ? -1 : mv.dispatch.typesLength() + extraIndex;
548+
i = extraIndex == -1 ? -1 : dispatch.typesLength() + extraIndex;
548549
}
549550
if (i != -1) {
550551
if (reorderOnly) {
551-
var copyTypes = allTypesWith.executeAllTypes(mv.dispatch, mv.extra);
552-
var copyValues = mv.values.clone();
553-
copyTypes[0] = copyTypes[i];
554-
copyValues[0] = copyValues[i];
555-
copyTypes[i] = mv.dispatch.firstType();
556-
copyValues[i] = mv.values[0];
557-
return newNode.newValue(copyTypes, 1, copyValues);
552+
var copyTypes = allTypesWith.executeAllTypes(dispatch, mv.extra);
553+
if (i == 0 && dispatch.typesLength() == 1) {
554+
return newNode.newValue(copyTypes, 1, mv.values);
555+
} else {
556+
var copyValues = mv.values.clone();
557+
copyTypes[0] = copyTypes[i];
558+
copyValues[0] = copyValues[i];
559+
copyTypes[i] = dispatch.firstType();
560+
copyValues[i] = mv.values[0];
561+
return newNode.newValue(copyTypes, 1, copyValues);
562+
}
558563
} else {
559564
return mv.values[i];
560565
}

0 commit comments

Comments
 (0)