From 7ce982662a22659954d28169eae771ae04555b32 Mon Sep 17 00:00:00 2001 From: Kyri Petrou Date: Sat, 18 Nov 2023 21:58:20 +1100 Subject: [PATCH] Avoid using zipWithIndex in executor --- .../main/scala/caliban/execution/Executor.scala | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/core/src/main/scala/caliban/execution/Executor.scala b/core/src/main/scala/caliban/execution/Executor.scala index 48f7abb0c1..e71880e676 100644 --- a/core/src/main/scala/caliban/execution/Executor.scala +++ b/core/src/main/scala/caliban/execution/Executor.scala @@ -107,12 +107,15 @@ object Executor { ) ) case ListStep(steps) => - reduceList( - steps.zipWithIndex.map { case (step, i) => - reduceStep(step, currentField, arguments, Right(i) :: path) - }, - Types.listOf(currentField.fieldType).fold(false)(_.isNullable) - ) + var i = 0 + val lb = List.newBuilder[ReducedStep[R]] + var remaining = steps + while (!remaining.isEmpty) { + lb += reduceStep(remaining.head, currentField, arguments, Right(i) :: path) + i += 1 + remaining = remaining.tail + } + reduceList(lb.result(), Types.listOf(currentField.fieldType).fold(false)(_.isNullable)) case StreamStep(stream) => if (request.operationType == OperationType.Subscription) { ReducedStep.StreamStep(