[FIR] Use optimized stdlib version of reversed list
This commit is contained in:
committed by
Space Team
parent
8066f1b7d2
commit
a4c9a4f150
@@ -1,15 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jetbrains.kotlin.fir.util
|
|
||||||
|
|
||||||
private open class FrozenReversedListReadOnly<out T>(
|
|
||||||
private val delegate: List<T>
|
|
||||||
) : AbstractList<T>() {
|
|
||||||
override val size: Int = delegate.size
|
|
||||||
override fun get(index: Int): T = delegate[size - 1 - index]
|
|
||||||
}
|
|
||||||
|
|
||||||
fun <T> List<T>.asReversedFrozen(): List<T> = FrozenReversedListReadOnly(this)
|
|
||||||
+1
-2
@@ -23,7 +23,6 @@ import org.jetbrains.kotlin.fir.scopes.impl.FirWhenSubjectImportingScope
|
|||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol
|
||||||
import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef
|
import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef
|
||||||
import org.jetbrains.kotlin.fir.types.impl.FirImplicitBuiltinTypeRef
|
import org.jetbrains.kotlin.fir.types.impl.FirImplicitBuiltinTypeRef
|
||||||
import org.jetbrains.kotlin.fir.util.asReversedFrozen
|
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind
|
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.HIDES_MEMBERS_NAME_LIST
|
import org.jetbrains.kotlin.resolve.descriptorUtil.HIDES_MEMBERS_NAME_LIST
|
||||||
@@ -32,7 +31,7 @@ internal class TowerDataElementsForName(
|
|||||||
name: Name,
|
name: Name,
|
||||||
towerDataContext: FirTowerDataContext
|
towerDataContext: FirTowerDataContext
|
||||||
) {
|
) {
|
||||||
val nonLocalTowerDataElements = towerDataContext.nonLocalTowerDataElements.asReversedFrozen()
|
val nonLocalTowerDataElements = towerDataContext.nonLocalTowerDataElements.asReversed()
|
||||||
|
|
||||||
val reversedFilteredLocalScopes by lazy(LazyThreadSafetyMode.NONE) {
|
val reversedFilteredLocalScopes by lazy(LazyThreadSafetyMode.NONE) {
|
||||||
buildList {
|
buildList {
|
||||||
|
|||||||
+1
-10
@@ -302,18 +302,9 @@ open class FirTypeResolveTransformer(
|
|||||||
|
|
||||||
override fun transformTypeRef(typeRef: FirTypeRef, data: Any?): FirResolvedTypeRef {
|
override fun transformTypeRef(typeRef: FirTypeRef, data: Any?): FirResolvedTypeRef {
|
||||||
return typeResolverTransformer.withFile(currentFile) {
|
return typeResolverTransformer.withFile(currentFile) {
|
||||||
val scopes = scopes
|
|
||||||
// optimized implementation of reversed Iterable on top of PersistentList
|
|
||||||
val reversedScopes = object : Iterable<FirScope> {
|
|
||||||
override fun iterator() = object : Iterator<FirScope> {
|
|
||||||
private val iter = scopes.listIterator(scopes.size)
|
|
||||||
override fun hasNext() = iter.hasPrevious()
|
|
||||||
override fun next() = iter.previous()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
typeRef.transform(
|
typeRef.transform(
|
||||||
typeResolverTransformer,
|
typeResolverTransformer,
|
||||||
ScopeClassDeclaration(reversedScopes, classDeclarationsStack, containerDeclaration = currentDeclaration)
|
ScopeClassDeclaration(scopes.asReversed(), classDeclarationsStack, containerDeclaration = currentDeclaration)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.fir.resolve.dfa
|
package org.jetbrains.kotlin.fir.resolve.dfa
|
||||||
|
|
||||||
import org.jetbrains.kotlin.fir.util.asReversedFrozen
|
|
||||||
|
|
||||||
abstract class Stack<T> {
|
abstract class Stack<T> {
|
||||||
abstract val size: Int
|
abstract val size: Int
|
||||||
abstract fun top(): T
|
abstract fun top(): T
|
||||||
@@ -41,5 +39,5 @@ private class StackImpl<T>(vararg values: T) : Stack<T>() {
|
|||||||
stack.clear()
|
stack.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun all(): List<T> = stack.asReversedFrozen()
|
override fun all(): List<T> = stack.asReversed()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user