From 17a8d24a84707cc031df63b5705c5ff2466ad493 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Fri, 26 Feb 2021 18:52:59 +0100 Subject: [PATCH] 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". --- .../src/org/jetbrains/kotlin/util/Util.kt | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/compiler/util-io/src/org/jetbrains/kotlin/util/Util.kt b/compiler/util-io/src/org/jetbrains/kotlin/util/Util.kt index cafcfd778f8..2a2c4e4d8ab 100644 --- a/compiler/util-io/src/org/jetbrains/kotlin/util/Util.kt +++ b/compiler/util-io/src/org/jetbrains/kotlin/util/Util.kt @@ -5,20 +5,12 @@ package org.jetbrains.kotlin.util +import org.jetbrains.kotlin.konan.file.File import kotlin.system.measureTimeMillis -import org.jetbrains.kotlin.konan.file.* -import java.lang.StringBuilder -fun printMillisec(message: String, body: () -> T): T { - var msec = 0L - try { - msec = measureTimeMillis { - return body() - } - } finally { - println("$message: $msec msec") - } - error("shouldn't happens") +private fun printMilliseconds(message: String, body: () -> Unit) { + val time = measureTimeMillis(body) + println("$message: $time ms") } fun profile(message: String, body: () -> Unit) = profileIf( @@ -26,8 +18,8 @@ fun profile(message: String, body: () -> Unit) = profileIf( message, body ) -fun profileIf(condition: Boolean, message: String, body: () -> Unit) = - if (condition) printMillisec(message, body) else body() +private fun profileIf(condition: Boolean, message: String, body: () -> Unit) = + if (condition) printMilliseconds(message, body) else body() fun nTabs(amount: Int): String { return String.format("%1$-${(amount+1)*4}s", "")