From 2e56feed73b38a5441ed1aa3e099ed549b5fe4a7 Mon Sep 17 00:00:00 2001 From: Yan Zhulanow Date: Mon, 29 Oct 2018 10:08:08 +0900 Subject: [PATCH] Performance optimization: do not create a new list object on each new option --- .../kotlin/compiler/plugin/CommandLineProcessor.kt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/compiler/plugin-api/src/org/jetbrains/kotlin/compiler/plugin/CommandLineProcessor.kt b/compiler/plugin-api/src/org/jetbrains/kotlin/compiler/plugin/CommandLineProcessor.kt index 82bd2f02474..b1bb3b94b7a 100644 --- a/compiler/plugin-api/src/org/jetbrains/kotlin/compiler/plugin/CommandLineProcessor.kt +++ b/compiler/plugin-api/src/org/jetbrains/kotlin/compiler/plugin/CommandLineProcessor.kt @@ -35,13 +35,13 @@ interface CommandLineProcessor { fun processOption(option: CliOption, value: String, configuration: CompilerConfiguration) {} fun CompilerConfiguration.appendList(option: CompilerConfigurationKey>, value: T) { - val paths = getList(option).toMutableList() + val paths = getList(option).asMutableList() paths.add(value) put(option, paths) } fun CompilerConfiguration.appendList(option: CompilerConfigurationKey>, values: List) { - val paths = getList(option).toMutableList() + val paths = getList(option).asMutableList() paths.addAll(values) put(option, paths) } @@ -55,4 +55,12 @@ interface CommandLineProcessor { } } } + + private fun List.asMutableList(): MutableList { + if (this is ArrayList) { + return this + } + + return this.toMutableList() + } } \ No newline at end of file