From bf1bb2f4102d161f6eec05e837a14d45df81d210 Mon Sep 17 00:00:00 2001 From: Mitchell Yuwono Date: Mon, 28 Mar 2022 10:43:17 +1100 Subject: [PATCH] remove redundant mutable list allocation (#2904) --- .../kotlin/io/kotest/property/arbitrary/map.kt | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/kotest-property/src/commonMain/kotlin/io/kotest/property/arbitrary/map.kt b/kotest-property/src/commonMain/kotlin/io/kotest/property/arbitrary/map.kt index cb3c6c6116c..fbb96aaf50d 100644 --- a/kotest-property/src/commonMain/kotlin/io/kotest/property/arbitrary/map.kt +++ b/kotest-property/src/commonMain/kotlin/io/kotest/property/arbitrary/map.kt @@ -47,20 +47,18 @@ internal fun Arb.trampoline(next: (Sample) -> Arb): Arb = whe @Suppress("UNCHECKED_CAST") internal class TrampolineArb private constructor( private val first: Arb, - commands: List<(Sample) -> Arb> + private val commands: List<(Sample) -> Arb> ) : Arb() { constructor(first: Arb) : this(first, emptyList()) - private val commandList: MutableList<(Sample) -> Arb> = commands.toMutableList() - fun thunk(fn: (Sample) -> Arb): TrampolineArb = TrampolineArb( first, - commandList.toList() + (fn as (Sample) -> Arb) + commands + (fn as (Sample) -> Arb) ) as TrampolineArb override fun edgecase(rs: RandomSource): A? = - commandList + commands .fold(first as Arb) { currentArb, next -> val currentEdge = currentArb.edgecase(rs) ?: currentArb.sample(rs).value next(Sample(currentEdge)) @@ -68,7 +66,7 @@ internal class TrampolineArb private constructor( .edgecase(rs) as A? override fun sample(rs: RandomSource): Sample = - commandList + commands .fold(first as Arb) { currentArb, next -> next(currentArb.sample(rs)) }