From 08a5e36ee74d8ab69ed5f0e614663d6837595b1d Mon Sep 17 00:00:00 2001 From: Alexander Korepanov Date: Thu, 15 Dec 2022 16:42:15 +0100 Subject: [PATCH] [JS IR IC] Do not load deserializers and fingerprints together Optimization: in some cases we need only deserializers without fingerprints. --- .../ir/backend/js/ic/KotlinLibraryHeader.kt | 41 ++++++++++--------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/ic/KotlinLibraryHeader.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/ic/KotlinLibraryHeader.kt index 0408a75e25e..62f36d1882f 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/ic/KotlinLibraryHeader.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/ic/KotlinLibraryHeader.kt @@ -31,24 +31,9 @@ internal class KotlinLoadedLibraryHeader(private val library: KotlinLibrary) : K override val libraryFingerprint: ICHash by lazy { File(libraryFile.path).fileHashForIC() } - override val sourceFileDeserializers: Map by lazy { sourceFiles.first } - override val sourceFileFingerprints: Map by lazy { sourceFiles.second } - - override val jsOutputName: String? - get() = library.jsOutputName - - private val sourceFiles by lazy { - val filesCount = library.fileCount() - val extReg = ExtensionRegistryLite.newInstance() - - val deserializers = HashMap(filesCount) - val fingerprints = HashMap(filesCount) - - repeat(filesCount) { - val fileProto = IrFile.parseFrom(library.file(it).codedInputStream, extReg) - val srcFile = KotlinSourceFile(fileProto.fileEntry.name) - - deserializers[srcFile] = IdSignatureDeserializer(IrLibraryFileFromBytes(object : IrLibraryBytesSource() { + override val sourceFileDeserializers: Map by lazy { + buildMapUntil(sourceFiles.size) { + val deserializer = IdSignatureDeserializer(IrLibraryFileFromBytes(object : IrLibraryBytesSource() { private fun err(): Nothing = icError("Not supported") override fun irDeclaration(index: Int): ByteArray = err() override fun type(index: Int): ByteArray = err() @@ -58,9 +43,25 @@ internal class KotlinLoadedLibraryHeader(private val library: KotlinLibrary) : K override fun debugInfo(index: Int): ByteArray? = null }), null) - fingerprints[srcFile] = library.fingerprint(it) + put(sourceFiles[it], deserializer) + } + } + + override val sourceFileFingerprints: Map by lazy { + buildMapUntil(sourceFiles.size) { + put(sourceFiles[it], library.fingerprint(it)) + } + } + + override val jsOutputName: String? + get() = library.jsOutputName + + private val sourceFiles by lazy { + val extReg = ExtensionRegistryLite.newInstance() + Array(library.fileCount()) { + val fileProto = IrFile.parseFrom(library.file(it).codedInputStream, extReg) + KotlinSourceFile(fileProto.fileEntry.name) } - deserializers to fingerprints } }