From ec68b7ee9c9bd1169eecf4e54a8a2aadbb8246e8 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Sat, 22 Feb 2025 11:54:57 +0700 Subject: [PATCH] Shortcut to "isEmpty" in UpgradeContainer to account for most common case --- .../ru/dbotthepony/mc/otm/container/UpgradeContainer.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/container/UpgradeContainer.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/container/UpgradeContainer.kt index e15f0ce64..0c0070806 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/container/UpgradeContainer.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/container/UpgradeContainer.kt @@ -21,12 +21,18 @@ class UpgradeContainer( get() = setOf() private fun positiveDecimals(fn: (IMatteryUpgrade) -> Decimal, reducer: (Decimal, Decimal) -> Decimal): Decimal { + if (isEmpty) + return Decimal.ZERO + return iterator() .map { (it.getCapability(MatteryCapability.UPGRADE)?.let(fn) ?: Decimal.ZERO).moreThanZero() * it.count } .reduce(Decimal.ZERO, reducer) } private fun anyDecimals(fn: (IMatteryUpgrade) -> Decimal, reducer: (Decimal, Decimal) -> Decimal): Decimal { + if (isEmpty) + return Decimal.ZERO + return iterator() .map { (it.getCapability(MatteryCapability.UPGRADE)?.let(fn) ?: Decimal.ZERO) * it.count } .reduce(Decimal.ZERO, reducer)