From a2db8f90901dfe9b6e074dd75606d567a2367361 Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Tue, 12 Apr 2016 19:20:29 +0300 Subject: [PATCH] Performance: move the state out of multifile class parts to avoid synchronization. --- libraries/stdlib/src/kotlin/collections/Maps.kt | 5 ++--- libraries/stdlib/src/kotlin/text/StringBuilderJVM.kt | 11 +++++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/libraries/stdlib/src/kotlin/collections/Maps.kt b/libraries/stdlib/src/kotlin/collections/Maps.kt index cc370eae711..95113f22101 100644 --- a/libraries/stdlib/src/kotlin/collections/Maps.kt +++ b/libraries/stdlib/src/kotlin/collections/Maps.kt @@ -80,9 +80,6 @@ public fun linkedMapOf(vararg pairs: Pair): LinkedHashMap * to the Collection constructor for HashSet, (c.size()/.75f) + 1, but provides further optimisations for very small or * very large sizes, allows support non-collection classes, and provides consistency for all map based class construction. */ - -private val INT_MAX_POWER_OF_TWO: Int = Int.MAX_VALUE / 2 + 1 - @kotlin.internal.InlineExposed internal fun mapCapacity(expectedSize: Int): Int { if (expectedSize < 3) { @@ -94,6 +91,8 @@ internal fun mapCapacity(expectedSize: Int): Int { return Int.MAX_VALUE // any large value } +private const val INT_MAX_POWER_OF_TWO: Int = Int.MAX_VALUE / 2 + 1 + /** Returns `true` if this map is not empty. */ @kotlin.internal.InlineOnly public inline fun Map.isNotEmpty(): Boolean = !isEmpty() diff --git a/libraries/stdlib/src/kotlin/text/StringBuilderJVM.kt b/libraries/stdlib/src/kotlin/text/StringBuilderJVM.kt index 35cbb88efbe..50a541dc6bd 100644 --- a/libraries/stdlib/src/kotlin/text/StringBuilderJVM.kt +++ b/libraries/stdlib/src/kotlin/text/StringBuilderJVM.kt @@ -3,11 +3,14 @@ package kotlin.text -/** Line separator for current system. */ -private val LINE_SEPARATOR: String by lazy { System.getProperty("line.separator")!! } +private object SystemProperties { + /** Line separator for current system. */ + @JvmField + val LINE_SEPARATOR = System.getProperty("line.separator")!! +} /** Appends a line separator to this Appendable. */ -public fun Appendable.appendln(): Appendable = append(LINE_SEPARATOR) +public fun Appendable.appendln(): Appendable = append(SystemProperties.LINE_SEPARATOR) /** Appends value to the given Appendable and line separator after it. */ @kotlin.internal.InlineOnly @@ -18,7 +21,7 @@ public inline fun Appendable.appendln(value: CharSequence?): Appendable = append public inline fun Appendable.appendln(value: Char): Appendable = append(value).appendln() /** Appends a line separator to this StringBuilder. */ -public fun StringBuilder.appendln(): StringBuilder = append(LINE_SEPARATOR) +public fun StringBuilder.appendln(): StringBuilder = append(SystemProperties.LINE_SEPARATOR) /** Appends [value] to this [StringBuilder], followed by a line separator. */ @kotlin.internal.InlineOnly