[K/N] Code cleanup from deprecation warnings

No functionality change; just quieting some warnings
This commit is contained in:
Troels Bjerre Lund
2022-06-09 15:38:14 +02:00
committed by Space
parent 71e617a7f5
commit 90754d11c1
5 changed files with 23 additions and 28 deletions
@@ -87,7 +87,7 @@ fun computeMeanVariance(samples: List<Double>): MeanVariance {
} }
val mean = filteredSamples.sum() / filteredSamples.size val mean = filteredSamples.sum() / filteredSamples.size
val variance = samples.indices.sumByDouble { val variance = samples.indices.sumOf {
(samples[it] - mean) * (samples[it] - mean) (samples[it] - mean) * (samples[it] - mean)
} / samples.size } / samples.size
val confidenceInterval = sqrt(variance / samples.size) * zStar val confidenceInterval = sqrt(variance / samples.size) * zStar
@@ -143,5 +143,5 @@ fun collectMeanResults(benchmarks: Map<String, List<BenchmarkResult>>): Benchmar
fun collectBenchmarksDurations(benchmarks: Map<String, List<BenchmarkResult>>): Map<String, Double> = fun collectBenchmarksDurations(benchmarks: Map<String, List<BenchmarkResult>>): Map<String, Double> =
benchmarks.map { (name, resultsSet) -> benchmarks.map { (name, resultsSet) ->
name to resultsSet.sumByDouble { it.runtimeInUs } name to resultsSet.sumOf { it.runtimeInUs }
}.toMap() }.toMap()
@@ -268,12 +268,8 @@ class SummaryBenchmarksReport(val currentReport: BenchmarksReport,
name to benchmarks.filter { it.metric == metric } name to benchmarks.filter { it.metric == metric }
}?.filter { it.second.isNotEmpty() }?.toMap() }?.filter { it.second.isNotEmpty() }?.toMap()
metric to DetailedBenchmarksReport( metric to DetailedBenchmarksReport(
currentReport.benchmarks.map { (name, benchmarks) -> currentBenchmarks,
name to benchmarks.filter { it.metric == metric } previousBenchmarks,
}.filter { it.second.isNotEmpty() }.toMap(),
previousReport?.benchmarks?.map { (name, benchmarks) ->
name to benchmarks.filter { it.metric == metric }
}?.filter { it.second.isNotEmpty() }?.toMap(),
meaningfulChangesValue meaningfulChangesValue
) )
}.toMap() }.toMap()
@@ -84,17 +84,17 @@ internal object EscapeCharMappings {
} }
private fun CharArray.initC2ESC(c: Int, esc: Char) { private fun CharArray.initC2ESC(c: Int, esc: Char) {
this[c] = esc this[c] = esc
if (esc != UNICODE_ESC) ESC2C[esc.toInt()] = c.toChar() if (esc != UNICODE_ESC) ESC2C[esc.code] = c.toChar()
} }
private fun CharArray.initC2ESC(c: Char, esc: Char) = initC2ESC(c.toInt(), esc) private fun CharArray.initC2ESC(c: Char, esc: Char) = initC2ESC(c.code, esc)
} }
private fun ByteArray.initC2TC(c: Int, cl: Byte) { private fun ByteArray.initC2TC(c: Int, cl: Byte) {
this[c] = cl this[c] = cl
} }
private fun ByteArray.initC2TC(c: Char, cl: Byte) { private fun ByteArray.initC2TC(c: Char, cl: Byte) {
initC2TC(c.toInt(), cl) initC2TC(c.code, cl)
} }
internal fun charToTokenClass(c: Char) = if (c.toInt() < CTC_MAX) C2TC[c.toInt()] else TC_OTHER internal fun charToTokenClass(c: Char) = if (c.code < CTC_MAX) C2TC[c.code] else TC_OTHER
internal fun escapeToChar(c: Int): Char = if (c < ESC2C_MAX) ESC2C[c] else INVALID internal fun escapeToChar(c: Int): Char = if (c < ESC2C_MAX) ESC2C[c] else INVALID
// JSON low level parser // JSON low level parser
internal class Parser(val source: String) { internal class Parser(val source: String) {
@@ -226,7 +226,7 @@ internal class Parser(val source: String) {
if (curChar == UNICODE_ESC) { if (curChar == UNICODE_ESC) {
curPos = appendHex(source, curPos) curPos = appendHex(source, curPos)
} else { } else {
val c = escapeToChar(curChar.toInt()) val c = escapeToChar(curChar.code)
require(c != INVALID, curPos) { "Invalid escaped char '$curChar'" } require(c != INVALID, curPos) { "Invalid escaped char '$curChar'" }
append(c) append(c)
} }
@@ -269,9 +269,9 @@ private fun fromHexChar(source: String, curPos: Int): Int {
require(curPos < source.length, curPos) { "Unexpected end in unicode escape" } require(curPos < source.length, curPos) { "Unexpected end in unicode escape" }
val curChar = source[curPos] val curChar = source[curPos]
return when (curChar) { return when (curChar) {
in '0'..'9' -> curChar.toInt() - '0'.toInt() in '0'..'9' -> curChar.code - '0'.code
in 'a'..'f' -> curChar.toInt() - 'a'.toInt() + 10 in 'a'..'f' -> curChar.code - 'a'.code + 10
in 'A'..'F' -> curChar.toInt() - 'A'.toInt() + 10 in 'A'..'F' -> curChar.code - 'A'.code + 10
else -> fail(curPos, "Invalid toHexChar char '$curChar' in unicode escape") else -> fail(curPos, "Invalid toHexChar char '$curChar' in unicode escape")
} }
} }
@@ -18,8 +18,8 @@ package org.jetbrains.report.json
private fun toHexChar(i: Int) : Char { private fun toHexChar(i: Int) : Char {
val d = i and 0xf val d = i and 0xf
return if (d < 10) (d + '0'.toInt()).toChar() return if (d < 10) (d + '0'.code).toChar()
else (d - 10 + 'a'.toInt()).toChar() else (d - 10 + 'a'.code).toChar()
} }
private val ESCAPE_CHARS: Array<String?> = arrayOfNulls<String>(128).apply { private val ESCAPE_CHARS: Array<String?> = arrayOfNulls<String>(128).apply {
@@ -30,12 +30,12 @@ private val ESCAPE_CHARS: Array<String?> = arrayOfNulls<String>(128).apply {
val c4 = toHexChar(c) val c4 = toHexChar(c)
this[c] = "\\u$c1$c2$c3$c4" this[c] = "\\u$c1$c2$c3$c4"
} }
this['"'.toInt()] = "\\\"" this['"'.code] = "\\\""
this['\\'.toInt()] = "\\\\" this['\\'.code] = "\\\\"
this['\t'.toInt()] = "\\t" this['\t'.code] = "\\t"
this['\b'.toInt()] = "\\b" this['\b'.code] = "\\b"
this['\n'.toInt()] = "\\n" this['\n'.code] = "\\n"
this['\r'.toInt()] = "\\r" this['\r'.code] = "\\r"
this[0x0c] = "\\f" this[0x0c] = "\\f"
} }
@@ -44,7 +44,7 @@ internal fun StringBuilder.printQuoted(value: String) {
var lastPos = 0 var lastPos = 0
val length = value.length val length = value.length
for (i in 0 until length) { for (i in 0 until length) {
val c = value[i].toInt() val c = value[i].code
// Do not replace this constant with C2ESC_MAX (which is smaller than ESCAPE_CHARS size), // Do not replace this constant with C2ESC_MAX (which is smaller than ESCAPE_CHARS size),
// otherwise JIT won't eliminate range check and won't vectorize this loop // otherwise JIT won't eliminate range check and won't vectorize this loop
if (c >= ESCAPE_CHARS.size) continue // no need to escape if (c >= ESCAPE_CHARS.size) continue // no need to escape
@@ -175,9 +175,8 @@ fun main(args: Array<String>) {
// Get unstable benchmarks. // Get unstable benchmarks.
val unstableBenchmarks = if (!flatReport) DBServerConnector.getUnstableBenchmarks() else null val unstableBenchmarks = if (!flatReport) DBServerConnector.getUnstableBenchmarks() else null
unstableBenchmarks ?: if (!flatReport && unstableBenchmarks == null)
if (!flatReport) println("Failed to get access to server and get unstable benchmarks list!")
println("Failed to get access to server and get unstable benchmarks list!")
// Read contents of file. // Read contents of file.
val mainBenchsReport = mergeReportsWithDetailedFlags(getBenchmarkReport(mainReport, user)) val mainBenchsReport = mergeReportsWithDetailedFlags(getBenchmarkReport(mainReport, user))