Fix warnings in Util.kt
There were unreachable code warnings in printMillisec, and indeed the variable assignment was never executed, so the function would always print "0 msec".
This commit is contained in:
@@ -5,20 +5,12 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.util
|
package org.jetbrains.kotlin.util
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.konan.file.File
|
||||||
import kotlin.system.measureTimeMillis
|
import kotlin.system.measureTimeMillis
|
||||||
import org.jetbrains.kotlin.konan.file.*
|
|
||||||
import java.lang.StringBuilder
|
|
||||||
|
|
||||||
fun <T> printMillisec(message: String, body: () -> T): T {
|
private fun printMilliseconds(message: String, body: () -> Unit) {
|
||||||
var msec = 0L
|
val time = measureTimeMillis(body)
|
||||||
try {
|
println("$message: $time ms")
|
||||||
msec = measureTimeMillis {
|
|
||||||
return body()
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
println("$message: $msec msec")
|
|
||||||
}
|
|
||||||
error("shouldn't happens")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun profile(message: String, body: () -> Unit) = profileIf(
|
fun profile(message: String, body: () -> Unit) = profileIf(
|
||||||
@@ -26,8 +18,8 @@ fun profile(message: String, body: () -> Unit) = profileIf(
|
|||||||
message, body
|
message, body
|
||||||
)
|
)
|
||||||
|
|
||||||
fun profileIf(condition: Boolean, message: String, body: () -> Unit) =
|
private fun profileIf(condition: Boolean, message: String, body: () -> Unit) =
|
||||||
if (condition) printMillisec(message, body) else body()
|
if (condition) printMilliseconds(message, body) else body()
|
||||||
|
|
||||||
fun nTabs(amount: Int): String {
|
fun nTabs(amount: Int): String {
|
||||||
return String.format("%1$-${(amount+1)*4}s", "")
|
return String.format("%1$-${(amount+1)*4}s", "")
|
||||||
|
|||||||
Reference in New Issue
Block a user