From 54a640d733c169bc2a52fa9735efa2b41ea40394 Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Tue, 30 Aug 2016 23:11:00 +0300 Subject: [PATCH] Cleanup: remove unused code from HashMap, remove commented out specialization intrinsics. --- .../src/core/collections/HashMap.kt | 190 +----------------- .../functions/factories/TopLevelFIF.java | 41 ---- js/js.translator/testData/kotlin_lib.js | 1 - 3 files changed, 7 insertions(+), 225 deletions(-) diff --git a/js/js.libraries/src/core/collections/HashMap.kt b/js/js.libraries/src/core/collections/HashMap.kt index 605243cf00c..8ba455c1c61 100644 --- a/js/js.libraries/src/core/collections/HashMap.kt +++ b/js/js.libraries/src/core/collections/HashMap.kt @@ -46,76 +46,20 @@ open class HashMap : AbstractMap { override val size: Int get() = this@HashMap.size } - /* - private inner class EntrySetIterator : Iterator> { - private val stringMapEntries = stringMap!!.iterator() - private var current: MutableIterator> = stringMapEntries - private var last: MutableIterator>? = null - private var hasNext = computeHasNext() - - init { - recordLastKnownStructure(this@AbstractHashMap, this) - } - - override fun hasNext(): Boolean { - return hasNext - } - - private fun computeHasNext(): Boolean { - if (current.hasNext()) { - return true - } - if (current !== stringMapEntries) { - return false - } - current = hashCodeMap!!.iterator() - return current.hasNext() - } - - override fun next(): Entry { - checkStructuralChange(this@AbstractHashMap, this) - checkElement(hasNext()) - - last = current - val rv = current.next() - hasNext = computeHasNext() - - return rv - } - - override fun remove() { - checkState(last != null) - checkStructuralChange(this@AbstractHashMap, this) - - last!!.remove() - last = null - hasNext = computeHasNext() - - recordLastKnownStructure(this@AbstractHashMap, this) - } - }*/ /** - * A map of integral hashCodes onto entries. + * Internal implementation of the map: either string-based or hashcode-based. */ private val internalMap: InternalMap private val equality: EqualityComparator -// /** -// * A map of Strings onto values. -// */ -// @Transient private var stringMap: InternalStringMap? = null -// internal constructor(internalMap: InternalMap) : super() { this.internalMap = internalMap this.equality = internalMap.equality } constructor() : this(InternalHashCodeMap(EqualityComparator.HashCode)) -// init { -// reset() -// } constructor(initialCapacity: Int, loadFactor: Float = 0f) : this() { // This implementation of HashMap has no need of load factors or capacities. @@ -129,146 +73,26 @@ open class HashMap : AbstractMap { override fun clear() { internalMap.clear() -// reset() -// } -// -// private fun reset() { -// internalMap = internalMapProvider(this) -// stringMap = InternalStringMap(this) // structureChanged(this) } -// @SpecializeMethod(params = { String.class }, target = "hasStringValue") - override fun containsKey(key: K): Boolean { - return internalMap.contains(key) -// return if (key is String) -// hasStringValue(JsUtils.unsafeCastToString(key)) -// else -// hasHashValue(key) - } + override fun containsKey(key: K): Boolean = internalMap.contains(key) - override fun containsValue(value: V): Boolean { - return /*containsValue(value, stringMap) || */ containsValue(value, internalMap) - } + override fun containsValue(value: V): Boolean = containsValue(value, internalMap) private fun containsValue(value: V, entries: Iterable>): Boolean = entries.any { equality.equals(it.value, value) } override val entries: MutableSet> get() = EntrySet() -// @SpecializeMethod(params = { String.class }, target = "getStringValue") - override operator fun get(key: K): V? { - return internalMap.get(key) -// return if (key is String) -// getStringValue(JsUtils.unsafeCastToString(key)) -// else -// getHashValue(key) - } + override operator fun get(key: K): V? = internalMap.get(key) -// @SpecializeMethod(params = { String.class, Object .class }, target = "putStringValue") - override fun put(key: K, value: V): V? { - return internalMap.put(key, value) -// return if (key is String) -// putStringValue(JsUtils.unsafeCastToString(key), value) -// else -// putHashValue(key, value) - } + override fun put(key: K, value: V): V? = internalMap.put(key, value) -// @SpecializeMethod(params = { String.class }, target = "removeStringValue") - override fun remove(key: K): V? { - return internalMap.remove(key) -// return if (key is String) -// removeStringValue(JsUtils.unsafeCastToString(key)) -// else -// removeHashValue(key) - } + override fun remove(key: K): V? = internalMap.remove(key) - override val size: Int get() { - return internalMap.size /*+ stringMap!!.size()*/ - } + override val size: Int get() = internalMap.size -// /** -// * Subclasses must override to return a whether or not two keys or values are -// * equal. -// */ -// internal abstract fun equals(value1: Any?, value2: Any?): Boolean -// -// /** -// * Subclasses must override to return a hash code for a given key. The key is -// * guaranteed to be non-null and not a String. -// */ -// internal abstract fun getHashCode(key: K): Int -// -// /** -// * Returns the Map.Entry whose key is Object equal to `key`, -// * provided that `key`'s hash code is `hashCode`; -// * or `null` if no such Map.Entry exists at the specified -// * hashCode. -// */ -// private fun getHashValue(key: K): V? { -// return hashCodeMap.getEntry(key)?.value -// } - -// /** -// * Returns the value for the given key in the stringMap. Returns -// * `null` if the specified key does not exist. -// */ -// private fun getStringValue(key: String?): V { -// return if (key == null) getHashValue(null) else stringMap!!.get(key) -// } - -// /** -// * Returns true if the a key exists in the hashCodeMap that is Object equal to -// * `key`, provided that `key`'s hash code is -// * `hashCode`. -// */ -// private fun hasHashValue(key: K): Boolean { -// return hashCodeMap.getEntry(key) != null -// } -// -// /** -// * Returns true if the given key exists in the stringMap. -// */ -// private fun hasStringValue(key: String?): Boolean { -// return if (key == null) hasHashValue(null) else stringMap!!.contains(key) -// } - -// /** -// * Sets the specified key to the specified value in the hashCodeMap. Returns -// * the value previously at that key. Returns `null` if the -// * specified key did not exist. -// */ -// private fun putHashValue(key: K, value: V): V? { -// return hashCodeMap.put(key, value) -// } - -// /** -// * Sets the specified key to the specified value in the stringMap. Returns the -// * value previously at that key. Returns `null` if the specified -// * key did not exist. -// */ -// private fun putStringValue(key: String?, value: V): V { -// return if (key == null) putHashValue(null, value) else stringMap!!.put(key, value) -// } - -// /** -// * Removes the pair whose key is Object equal to `key` from -// * `hashCodeMap`, provided that `key`'s hash code -// * is `hashCode`. Returns the value that was associated with the -// * removed key, or null if no such key existed. -// */ -// private fun removeHashValue(key: K): V? { -// return hashCodeMap.remove(key) -// } - -// /** -// * Removes the specified key from the stringMap and returns the value that was -// * previously there. Returns `null` if the specified key does not -// * exist. -// */ -// private fun removeStringValue(key: String?): V { -// return if (key == null) removeHashValue(null) else stringMap!!.remove(key) -// } } diff --git a/js/js.translator/src/org/jetbrains/kotlin/js/translate/intrinsic/functions/factories/TopLevelFIF.java b/js/js.translator/src/org/jetbrains/kotlin/js/translate/intrinsic/functions/factories/TopLevelFIF.java index c5d4aab3365..f7a53929f06 100644 --- a/js/js.translator/src/org/jetbrains/kotlin/js/translate/intrinsic/functions/factories/TopLevelFIF.java +++ b/js/js.translator/src/org/jetbrains/kotlin/js/translate/intrinsic/functions/factories/TopLevelFIF.java @@ -187,9 +187,6 @@ public final class TopLevelFIF extends CompositeFIF { add(pattern("kotlin.collections", "Map", "get").checkOverridden(), NATIVE_MAP_GET); add(pattern("kotlin.js", "set").isExtensionOf(FQ_NAMES.mutableMap.asString()), NATIVE_MAP_SET); - //add(pattern("java.util", "HashMap", ""), new MapSelectImplementationIntrinsic(false)); - //add(pattern("java.util", "HashSet", ""), new MapSelectImplementationIntrinsic(true)); - add(pattern("kotlin.js", "Json", "get"), ArrayFIF.GET_INTRINSIC); add(pattern("kotlin.js", "Json", "set"), ArrayFIF.SET_INTRINSIC); @@ -245,42 +242,4 @@ public final class TopLevelFIF extends CompositeFIF { } } - /* - private static class MapSelectImplementationIntrinsic extends CallParametersAwareFunctionIntrinsic { - private final boolean isSet; - - private MapSelectImplementationIntrinsic(boolean isSet) { - this.isSet = isSet; - } - - @NotNull - @Override - public JsExpression apply( - @NotNull CallInfo callInfo, - @NotNull List arguments, - @NotNull TranslationContext context - ) { - KotlinType keyType = callInfo.getResolvedCall().getTypeArguments().values().iterator().next(); - Name keyTypeName = DescriptorUtilsKt.getNameIfStandardType(keyType); - String collectionClassName = null; - if (keyTypeName != null) { - if (NamePredicate.PRIMITIVE_NUMBERS.apply(keyTypeName)) { - collectionClassName = isSet ? "PrimitiveNumberHashSet" : "PrimitiveNumberHashMap"; - } - else if (PrimitiveType.BOOLEAN.getTypeName().equals(keyTypeName)) { - collectionClassName = isSet ? "PrimitiveBooleanHashSet" : "PrimitiveBooleanHashMap"; - } - else if (keyTypeName.asString().equals("String")) { - collectionClassName = isSet ? "DefaultPrimitiveHashSet" : "DefaultPrimitiveHashMap"; - } - } - - if (collectionClassName == null ) { - collectionClassName = isSet ? "ComplexHashSet" : "ComplexHashMap"; - } - - return new JsNew(context.namer().kotlin(collectionClassName), arguments); - } - } - */ } diff --git a/js/js.translator/testData/kotlin_lib.js b/js/js.translator/testData/kotlin_lib.js index 74dabdd0b08..4c7f4da47cc 100644 --- a/js/js.translator/testData/kotlin_lib.js +++ b/js/js.translator/testData/kotlin_lib.js @@ -801,7 +801,6 @@ array.sort(Kotlin.primitiveCompareTo) }; - // TODO: Find out whether is it referenced Kotlin.copyToArray = function (collection) { if (typeof collection.toArray !== "undefined") return collection.toArray(); return Kotlin.copyToArrayImpl(collection);