From 6e24b563b2c296b6c560f1e82fd562147dc45fe5 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sun, 7 Jul 2024 11:06:20 +0300 Subject: [PATCH] optimize attributes plus --- .../kotlin/space/kscience/attributes/Attributes.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attributes.kt b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attributes.kt index ab6185520..5eb93bfc0 100644 --- a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attributes.kt +++ b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attributes.kt @@ -140,4 +140,8 @@ public fun > Attributes( attribute: A, ): Attributes = MapAttributes(mapOf(attribute to Unit)) -public operator fun Attributes.plus(other: Attributes): Attributes = MapAttributes(content + other.content) \ No newline at end of file +public operator fun Attributes.plus(other: Attributes): Attributes = when{ + isEmpty() -> other + other.isEmpty() -> this + else -> MapAttributes(content + other.content) +} \ No newline at end of file