Performance optimization: do not create a new list object on each new option
This commit is contained in:
+10
-2
@@ -35,13 +35,13 @@ interface CommandLineProcessor {
|
|||||||
fun processOption(option: CliOption, value: String, configuration: CompilerConfiguration) {}
|
fun processOption(option: CliOption, value: String, configuration: CompilerConfiguration) {}
|
||||||
|
|
||||||
fun <T> CompilerConfiguration.appendList(option: CompilerConfigurationKey<List<T>>, value: T) {
|
fun <T> CompilerConfiguration.appendList(option: CompilerConfigurationKey<List<T>>, value: T) {
|
||||||
val paths = getList(option).toMutableList()
|
val paths = getList(option).asMutableList()
|
||||||
paths.add(value)
|
paths.add(value)
|
||||||
put(option, paths)
|
put(option, paths)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <T> CompilerConfiguration.appendList(option: CompilerConfigurationKey<List<T>>, values: List<T>) {
|
fun <T> CompilerConfiguration.appendList(option: CompilerConfigurationKey<List<T>>, values: List<T>) {
|
||||||
val paths = getList(option).toMutableList()
|
val paths = getList(option).asMutableList()
|
||||||
paths.addAll(values)
|
paths.addAll(values)
|
||||||
put(option, paths)
|
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()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user