More efficient implementation of containsFilesWithExactPackage() (don't materialize KtFile instances we don't actually need)

This commit is contained in:
Dmitry Jemerov
2017-01-30 20:02:35 +01:00
parent 62e1d49def
commit fa6bfe932e
2 changed files with 14 additions and 8 deletions
+1 -1
View File
@@ -15,7 +15,6 @@
<orderEntry type="library" scope="PROVIDED" name="java-i18n" level="project" />
<orderEntry type="library" scope="PROVIDED" name="gradle-and-groovy-plugin" level="project" />
<orderEntry type="module" module-name="eval4j" />
<orderEntry type="library" exported="" name="intellij-core-analysis" level="project" />
<orderEntry type="module-library">
<library>
<CLASSES>
@@ -35,5 +34,6 @@
<orderEntry type="module" module-name="idea-jps-common" />
<orderEntry type="module" module-name="cli-common" />
<orderEntry type="module" module-name="descriptors" />
<orderEntry type="library" exported="" name="idea-full" level="project" />
</component>
</module>
@@ -17,6 +17,8 @@
package org.jetbrains.kotlin.idea.stubindex
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.newvfs.persistent.PersistentFS
import com.intellij.openapi.vfs.newvfs.persistent.PersistentFSImpl
import com.intellij.psi.search.GlobalSearchScope
import com.intellij.psi.stubs.StubIndex
import org.jetbrains.kotlin.name.FqName
@@ -60,13 +62,17 @@ object PackageIndexUtil {
searchScope: GlobalSearchScope,
project: Project
): Boolean {
var result = false
StubIndex.getInstance().processElements<String, KtFile>(
KotlinExactPackagesIndex.getInstance().key, packageFqName.asString(), project, searchScope, KtFile::class.java
) {
result = true
false
val ids = StubIndex.getInstance().getContainingIds(KotlinExactPackagesIndex.getInstance().key,
packageFqName.asString(),
project,
searchScope)
val fs = PersistentFS.getInstance() as PersistentFSImpl
while (ids.hasNext()) {
val file = fs.findFileByIdIfCached(ids.next())
if (file != null && file in searchScope) {
return true
}
}
return result
return false
}
}