Minor. Use ArrayList instead of LinkedHashSet
Looks like there's no duplicates anyway
This commit is contained in:
+5
-5
@@ -30,7 +30,7 @@ import org.jetbrains.kotlin.serialization.ProtoBuf
|
|||||||
import org.jetbrains.kotlin.serialization.deserialization.DeserializationContext
|
import org.jetbrains.kotlin.serialization.deserialization.DeserializationContext
|
||||||
import org.jetbrains.kotlin.storage.getValue
|
import org.jetbrains.kotlin.storage.getValue
|
||||||
import org.jetbrains.kotlin.utils.Printer
|
import org.jetbrains.kotlin.utils.Printer
|
||||||
import org.jetbrains.kotlin.utils.toReadOnlyList
|
import org.jetbrains.kotlin.utils.compactIfPossible
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
abstract class DeserializedMemberScope protected constructor(
|
abstract class DeserializedMemberScope protected constructor(
|
||||||
@@ -84,10 +84,10 @@ abstract class DeserializedMemberScope protected constructor(
|
|||||||
): Collection<D> {
|
): Collection<D> {
|
||||||
val protos = protosByName[name].orEmpty()
|
val protos = protosByName[name].orEmpty()
|
||||||
|
|
||||||
val descriptors = protos.mapTo(linkedSetOf(), factory)
|
val descriptors = protos.mapTo(arrayListOf(), factory)
|
||||||
|
|
||||||
computeNonDeclared(descriptors)
|
computeNonDeclared(descriptors)
|
||||||
return descriptors.toReadOnlyList()
|
return descriptors.compactIfPossible()
|
||||||
}
|
}
|
||||||
|
|
||||||
protected open fun computeNonDeclaredFunctions(name: Name, functions: MutableCollection<SimpleFunctionDescriptor>) {
|
protected open fun computeNonDeclaredFunctions(name: Name, functions: MutableCollection<SimpleFunctionDescriptor>) {
|
||||||
@@ -126,7 +126,7 @@ abstract class DeserializedMemberScope protected constructor(
|
|||||||
): Collection<DeclarationDescriptor> {
|
): Collection<DeclarationDescriptor> {
|
||||||
//NOTE: descriptors should be in the same order they were serialized in
|
//NOTE: descriptors should be in the same order they were serialized in
|
||||||
// see MemberComparator
|
// see MemberComparator
|
||||||
val result = LinkedHashSet<DeclarationDescriptor>(0)
|
val result = ArrayList<DeclarationDescriptor>(0)
|
||||||
|
|
||||||
if (kindFilter.acceptsKinds(DescriptorKindFilter.SINGLETON_CLASSIFIERS_MASK)) {
|
if (kindFilter.acceptsKinds(DescriptorKindFilter.SINGLETON_CLASSIFIERS_MASK)) {
|
||||||
addEnumEntryDescriptors(result, nameFilter)
|
addEnumEntryDescriptors(result, nameFilter)
|
||||||
@@ -140,7 +140,7 @@ abstract class DeserializedMemberScope protected constructor(
|
|||||||
addClassifierDescriptors(result, nameFilter)
|
addClassifierDescriptors(result, nameFilter)
|
||||||
}
|
}
|
||||||
|
|
||||||
return result.toReadOnlyList()
|
return result.compactIfPossible()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addFunctionsAndProperties(
|
private fun addFunctionsAndProperties(
|
||||||
|
|||||||
@@ -84,6 +84,13 @@ fun <T> Collection<T>.toReadOnlyList(): List<T> =
|
|||||||
else -> ArrayList(this)
|
else -> ArrayList(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun <T> ArrayList<T>.compactIfPossible(): List<T> =
|
||||||
|
when (size) {
|
||||||
|
0 -> emptyList()
|
||||||
|
1 -> listOf(first())
|
||||||
|
else -> apply(ArrayList<T>::trimToSize)
|
||||||
|
}
|
||||||
|
|
||||||
fun <T: Any> T?.singletonOrEmptyList(): List<T> =
|
fun <T: Any> T?.singletonOrEmptyList(): List<T> =
|
||||||
if (this != null) listOf(this) else emptyList()
|
if (this != null) listOf(this) else emptyList()
|
||||||
|
|
||||||
@@ -92,4 +99,4 @@ fun <T> List<T>.indexOfFirst(startFrom: Int, predicate: (T) -> Boolean): Int {
|
|||||||
if (predicate(this[index])) return index
|
if (predicate(this[index])) return index
|
||||||
}
|
}
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user