[klib] Optimized away some Files.exists()

This commit is contained in:
Igor Chevdar
2020-11-16 20:45:48 +05:00
parent f597343d82
commit 03693e3d5a
2 changed files with 12 additions and 9 deletions
@@ -54,8 +54,10 @@ abstract class KotlinLibrarySearchPathResolver<L : KotlinLibrary>(
(listOf(currentDirHead) + repoRoots + listOf(localHead, distHead, distPlatformHead)).filterNotNull()
}
private val files: Set<String> by lazy { searchRoots.flatMap { it.listFilesOrEmpty }.map { it.absolutePath }.toSet() }
private fun found(candidate: File): File? {
fun check(file: File): Boolean = file.exists
fun check(file: File): Boolean = files.contains(file.absolutePath) || file.exists
val noSuffix = File(candidate.path.removeSuffixIfPresent(KLIB_FILE_EXTENSION_WITH_DOT))
val withSuffix = File(candidate.path.suffixIfNot(KLIB_FILE_EXTENSION_WITH_DOT))
@@ -292,4 +294,4 @@ class CompilerSingleFileKlibResolveAllowingIrProvidersStrategy(
SingleKlibComponentResolver(
libraryFile.absolutePath, logger, knownIrProviders
).resolve(libraryFile.absolutePath)
}
}
@@ -28,20 +28,21 @@ open class BaseKotlinLibraryImpl(
override val libraryFile get() = access.klib
override val libraryName: String by lazy { access.inPlace { it.libraryName } }
override val componentList: List<String> by lazy {
access.inPlace {
it.libDir.listFiles
private val componentListAndHasPre14Manifest by lazy {
access.inPlace { layout ->
val listFiles = layout.libDir.listFiles
listFiles
.filter { it.isDirectory }
.filter { it.listFiles.map { it.name }.contains(KLIB_MANIFEST_FILE_NAME) }
.map { it.name }
.map { it.name } to listFiles.any { it.absolutePath == layout.pre_1_4_manifest.absolutePath }
}
}
override val componentList: List<String> get() = componentListAndHasPre14Manifest.first
override fun toString() = "$libraryName[default=$isDefault]"
override val has_pre_1_4_manifest: Boolean by lazy {
access.inPlace { it.pre_1_4_manifest.exists }
}
override val has_pre_1_4_manifest: Boolean get() = componentListAndHasPre14Manifest.second
override val manifestProperties: Properties by lazy {
access.inPlace { it.manifestFile.loadProperties() }