From 3cb5e02f159cfb53e5db585b48c5ae744670f67d Mon Sep 17 00:00:00 2001 From: kyri-petrou <67301607+kyri-petrou@users.noreply.github.com> Date: Sun, 19 Nov 2023 09:51:18 +1100 Subject: [PATCH] Avoid using zipWithIndex in executor (#2013) --- .../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(