Skip to content

Commit

Permalink
[PSI] KtCommonFile: optimize search for importList
Browse files Browse the repository at this point in the history
There is no need to search for more than one list

^KT-73687
  • Loading branch information
dimonchik0036 authored and qodana-bot committed Dec 9, 2024
1 parent 754f157 commit ec425d4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
19 changes: 6 additions & 13 deletions compiler/psi/src/org/jetbrains/kotlin/psi/KtCodeFragment.kt
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Copyright 2010-2024 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.psi
Expand All @@ -29,6 +18,7 @@ import com.intellij.psi.tree.IElementType
import com.intellij.testFramework.LightVirtualFile
import com.intellij.util.messages.Topic
import org.jetbrains.kotlin.idea.KotlinFileType
import org.jetbrains.kotlin.psi.KtCodeFragment.Companion.IMPORT_SEPARATOR
import org.jetbrains.kotlin.psi.psiUtil.getElementTextWithContext

abstract class KtCodeFragment(
Expand Down Expand Up @@ -198,6 +188,9 @@ abstract class KtCodeFragment(
return null
}

override val importList: KtImportList?
get() = importsAsImportList()

override val importLists: List<KtImportList>
get() = listOfNotNull(importsAsImportList())

Expand Down
4 changes: 2 additions & 2 deletions compiler/psi/src/org/jetbrains/kotlin/psi/KtCommonFile.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ open class KtCommonFile(viewProvider: FileViewProvider, val isCompiled: Boolean)
@Volatile
private var pathCached: String? = null

val importList: KtImportList?
get() = importLists.firstOrNull()
open val importList: KtImportList?
get() = findChildByTypeOrClass(KtStubElementTypes.IMPORT_LIST, KtImportList::class.java)

@Volatile
private var hasImportAlias: Boolean? = null
Expand Down

0 comments on commit ec425d4

Please sign in to comment.