Performance optimization: do not create a new list object on each new option

This commit is contained in:
Yan Zhulanow
2018-10-29 10:08:08 +09:00
parent b6aecf3933
commit 2e56feed73
@@ -35,13 +35,13 @@ interface CommandLineProcessor {
fun processOption(option: CliOption, value: String, configuration: CompilerConfiguration) {}
fun <T> CompilerConfiguration.appendList(option: CompilerConfigurationKey<List<T>>, value: T) {
val paths = getList(option).toMutableList()
val paths = getList(option).asMutableList()
paths.add(value)
put(option, paths)
}
fun <T> CompilerConfiguration.appendList(option: CompilerConfigurationKey<List<T>>, values: List<T>) {
val paths = getList(option).toMutableList()
val paths = getList(option).asMutableList()
paths.addAll(values)
put(option, paths)
}
@@ -55,4 +55,12 @@ interface CommandLineProcessor {
}
}
}
private fun <T> List<T>.asMutableList(): MutableList<T> {
if (this is ArrayList<T>) {
return this
}
return this.toMutableList()
}
}