From 0ab33ab0751b6f62808dd10fdbfcb466dbe7eb5d Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Thu, 26 Nov 2015 15:48:10 +0300 Subject: [PATCH] Final moves: map delegating accessors and timing utils, provide deprecated methods in the old place --- .../src/kotlin/properties/MapAccessors.kt | 39 +++++++++++++++++++ libraries/stdlib/src/kotlin/system/Timing.kt | 1 + libraries/stdlib/src/kotlin/util/SystemJVM.kt | 22 +++++++++++ 3 files changed, 62 insertions(+) create mode 100644 libraries/stdlib/src/kotlin/properties/MapAccessors.kt create mode 100644 libraries/stdlib/src/kotlin/util/SystemJVM.kt diff --git a/libraries/stdlib/src/kotlin/properties/MapAccessors.kt b/libraries/stdlib/src/kotlin/properties/MapAccessors.kt new file mode 100644 index 00000000000..10a6c392e23 --- /dev/null +++ b/libraries/stdlib/src/kotlin/properties/MapAccessors.kt @@ -0,0 +1,39 @@ +@file:kotlin.jvm.JvmName("MapAccessorsKt") +package kotlin.properties + +import kotlin.reflect.KProperty +import kotlin.internal.Exact + +/** + * Returns the value of the property for the given object from this read-only map. + * @param thisRef the object for which the value is requested (not used). + * @param property the metadata for the property, used to get the name of property and lookup the value corresponding to this name in the map. + * @return the property value. + * + * @throws NoSuchElementException when the map doesn't contain value for the property name and doesn't provide an implicit default (see [withDefault]). + */ +@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN) +public operator fun Map.getValue(thisRef: Any?, property: KProperty<*>): V1 = getOrImplicitDefault(property.name) as V1 + +/** + * Returns the value of the property for the given object from this mutable map. + * @param thisRef the object for which the value is requested (not used). + * @param property the metadata for the property, used to get the name of property and lookup the value corresponding to this name in the map. + * @return the property value. + * + * @throws NoSuchElementException when the map doesn't contain value for the property name and doesn't provide an implicit default (see [withDefault]). + */ +@kotlin.jvm.JvmName("getVar") +@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN) +public operator fun MutableMap.getValue(thisRef: Any?, property: KProperty<*>): V = getOrImplicitDefault(property.name) as V + +/** + * Stores the value of the property for the given object in this mutable map. + * @param thisRef the object for which the value is requested (not used). + * @param property the metadata for the property, used to get the name of property and store the value associated with that name in the map. + * @param value the value to set. + */ +@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN) +public operator fun MutableMap.setValue(thisRef: Any?, property: KProperty<*>, value: V) { + this.put(property.name, value) +} diff --git a/libraries/stdlib/src/kotlin/system/Timing.kt b/libraries/stdlib/src/kotlin/system/Timing.kt index ef876241fb5..15256a4cf3c 100644 --- a/libraries/stdlib/src/kotlin/system/Timing.kt +++ b/libraries/stdlib/src/kotlin/system/Timing.kt @@ -1,4 +1,5 @@ @file:kotlin.jvm.JvmName("TimingKt") +@file:kotlin.jvm.JvmVersion package kotlin.system /** diff --git a/libraries/stdlib/src/kotlin/util/SystemJVM.kt b/libraries/stdlib/src/kotlin/util/SystemJVM.kt new file mode 100644 index 00000000000..e4a719d5b81 --- /dev/null +++ b/libraries/stdlib/src/kotlin/util/SystemJVM.kt @@ -0,0 +1,22 @@ +@file:kotlin.jvm.JvmName("TimingUtilsKt") +package kotlin.util + +/** + * Executes the given block and returns elapsed time in milliseconds. + */ +@Deprecated("Use measureTimeMillis from system.timing instead.", ReplaceWith("kotlin.system.measureTimeMillis(block)", "kotlin.system")) +public fun measureTimeMillis(block: () -> Unit) : Long { + val start = System.currentTimeMillis() + block() + return System.currentTimeMillis() - start +} + +/** + * Executes the given block and returns elapsed time in nanoseconds. + */ +@Deprecated("Use measureTimeNano from system.timing instead.", ReplaceWith("kotlin.system.measureTimeNano(block)", "kotlin.system")) +public fun measureTimeNano(block: () -> Unit) : Long { + val start = System.nanoTime() + block() + return System.nanoTime() - start +}