Cleanup: remove unused code from HashMap, remove commented out specialization intrinsics.
This commit is contained in:
@@ -46,76 +46,20 @@ open class HashMap<K, V> : AbstractMap<K, V> {
|
|||||||
override val size: Int get() = this@HashMap.size
|
override val size: Int get() = this@HashMap.size
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
private inner class EntrySetIterator : Iterator<Entry<K, V>> {
|
|
||||||
private val stringMapEntries = stringMap!!.iterator()
|
|
||||||
private var current: MutableIterator<Entry<K, V>> = stringMapEntries
|
|
||||||
private var last: MutableIterator<Entry<K, V>>? = 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<K, V> {
|
|
||||||
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<K, V>
|
private val internalMap: InternalMap<K, V>
|
||||||
|
|
||||||
private val equality: EqualityComparator
|
private val equality: EqualityComparator
|
||||||
|
|
||||||
// /**
|
|
||||||
// * A map of Strings onto values.
|
|
||||||
// */
|
|
||||||
// @Transient private var stringMap: InternalStringMap<K, V>? = null
|
|
||||||
//
|
|
||||||
internal constructor(internalMap: InternalMap<K, V>) : super() {
|
internal constructor(internalMap: InternalMap<K, V>) : super() {
|
||||||
this.internalMap = internalMap
|
this.internalMap = internalMap
|
||||||
this.equality = internalMap.equality
|
this.equality = internalMap.equality
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor() : this(InternalHashCodeMap(EqualityComparator.HashCode))
|
constructor() : this(InternalHashCodeMap(EqualityComparator.HashCode))
|
||||||
// init {
|
|
||||||
// reset()
|
|
||||||
// }
|
|
||||||
|
|
||||||
constructor(initialCapacity: Int, loadFactor: Float = 0f) : this() {
|
constructor(initialCapacity: Int, loadFactor: Float = 0f) : this() {
|
||||||
// This implementation of HashMap has no need of load factors or capacities.
|
// This implementation of HashMap has no need of load factors or capacities.
|
||||||
@@ -129,146 +73,26 @@ open class HashMap<K, V> : AbstractMap<K, V> {
|
|||||||
|
|
||||||
override fun clear() {
|
override fun clear() {
|
||||||
internalMap.clear()
|
internalMap.clear()
|
||||||
// reset()
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private fun reset() {
|
|
||||||
// internalMap = internalMapProvider(this)
|
|
||||||
// stringMap = InternalStringMap<K, V>(this)
|
|
||||||
// structureChanged(this)
|
// structureChanged(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
// @SpecializeMethod(params = { String.class }, target = "hasStringValue")
|
override fun containsKey(key: K): Boolean = internalMap.contains(key)
|
||||||
override fun containsKey(key: K): Boolean {
|
|
||||||
return internalMap.contains(key)
|
|
||||||
// return if (key is String)
|
|
||||||
// hasStringValue(JsUtils.unsafeCastToString(key))
|
|
||||||
// else
|
|
||||||
// hasHashValue(key)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun containsValue(value: V): Boolean {
|
override fun containsValue(value: V): Boolean = containsValue(value, internalMap)
|
||||||
return /*containsValue(value, stringMap) || */ containsValue(value, internalMap)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun containsValue(value: V, entries: Iterable<Entry<K, V>>): Boolean = entries.any { equality.equals(it.value, value) }
|
private fun containsValue(value: V, entries: Iterable<Entry<K, V>>): Boolean = entries.any { equality.equals(it.value, value) }
|
||||||
|
|
||||||
override val entries: MutableSet<MutableMap.MutableEntry<K, V>>
|
override val entries: MutableSet<MutableMap.MutableEntry<K, V>>
|
||||||
get() = EntrySet()
|
get() = EntrySet()
|
||||||
|
|
||||||
// @SpecializeMethod(params = { String.class }, target = "getStringValue")
|
override operator fun get(key: K): V? = internalMap.get(key)
|
||||||
override operator fun get(key: K): V? {
|
|
||||||
return internalMap.get(key)
|
|
||||||
// return if (key is String)
|
|
||||||
// getStringValue(JsUtils.unsafeCastToString(key))
|
|
||||||
// else
|
|
||||||
// getHashValue(key)
|
|
||||||
}
|
|
||||||
|
|
||||||
// @SpecializeMethod(params = { String.class, Object .class }, target = "putStringValue")
|
override fun put(key: K, value: V): V? = internalMap.put(key, value)
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
// @SpecializeMethod(params = { String.class }, target = "removeStringValue")
|
override fun remove(key: K): V? = internalMap.remove(key)
|
||||||
override fun remove(key: K): V? {
|
|
||||||
return internalMap.remove(key)
|
|
||||||
// return if (key is String)
|
|
||||||
// removeStringValue(JsUtils.unsafeCastToString(key))
|
|
||||||
// else
|
|
||||||
// removeHashValue(key)
|
|
||||||
}
|
|
||||||
|
|
||||||
override val size: Int get() {
|
override val size: Int get() = internalMap.size
|
||||||
return internalMap.size /*+ stringMap!!.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)
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
-41
@@ -187,9 +187,6 @@ public final class TopLevelFIF extends CompositeFIF {
|
|||||||
add(pattern("kotlin.collections", "Map", "get").checkOverridden(), NATIVE_MAP_GET);
|
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("kotlin.js", "set").isExtensionOf(FQ_NAMES.mutableMap.asString()), NATIVE_MAP_SET);
|
||||||
|
|
||||||
//add(pattern("java.util", "HashMap", "<init>"), new MapSelectImplementationIntrinsic(false));
|
|
||||||
//add(pattern("java.util", "HashSet", "<init>"), new MapSelectImplementationIntrinsic(true));
|
|
||||||
|
|
||||||
add(pattern("kotlin.js", "Json", "get"), ArrayFIF.GET_INTRINSIC);
|
add(pattern("kotlin.js", "Json", "get"), ArrayFIF.GET_INTRINSIC);
|
||||||
add(pattern("kotlin.js", "Json", "set"), ArrayFIF.SET_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<JsExpression> 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|||||||
-1
@@ -801,7 +801,6 @@
|
|||||||
array.sort(Kotlin.primitiveCompareTo)
|
array.sort(Kotlin.primitiveCompareTo)
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: Find out whether is it referenced
|
|
||||||
Kotlin.copyToArray = function (collection) {
|
Kotlin.copyToArray = function (collection) {
|
||||||
if (typeof collection.toArray !== "undefined") return collection.toArray();
|
if (typeof collection.toArray !== "undefined") return collection.toArray();
|
||||||
return Kotlin.copyToArrayImpl(collection);
|
return Kotlin.copyToArrayImpl(collection);
|
||||||
|
|||||||
Reference in New Issue
Block a user