From 132f2a5fa8ba58a32b0c58ef2dd5e747d65e0d88 Mon Sep 17 00:00:00 2001 From: Ilya Ryzhenkov Date: Mon, 9 Jun 2014 14:51:05 +0400 Subject: [PATCH] Improve performance for addAll with type check for Collection --- .../stdlib/src/kotlin/collections/MutableCollections.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libraries/stdlib/src/kotlin/collections/MutableCollections.kt b/libraries/stdlib/src/kotlin/collections/MutableCollections.kt index 1a99bebe612..ba221cfd04c 100644 --- a/libraries/stdlib/src/kotlin/collections/MutableCollections.kt +++ b/libraries/stdlib/src/kotlin/collections/MutableCollections.kt @@ -4,7 +4,10 @@ package kotlin * Adds all elements of the given *iterable* to this [[MutableCollection]] */ public fun MutableCollection.addAll(iterable: Iterable): Unit { - for (e in iterable) add(e) + when (iterable) { + is Collection -> addAll(iterable) + else -> for (e in iterable) add(e) + } } public fun MutableCollection.addAll(stream: Stream): Unit {