Faster startup avoiding unnecessary class loading
This commit is contained in:
committed by
Vladimir Dolzhenko
parent
f7d0be980b
commit
c853ae49a2
+3
-3
@@ -15,9 +15,9 @@ import org.jetbrains.kotlin.serialization.konan.KonanSerializerProtocol
|
||||
import org.jetbrains.kotlin.serialization.konan.NullFlexibleTypeDeserializer
|
||||
|
||||
class KotlinNativeMetadataDecompiler : KotlinNativeMetadataDecompilerBase<KotlinNativeMetadataVersion>(
|
||||
KotlinNativeMetaFileType, KonanSerializerProtocol, NullFlexibleTypeDeserializer,
|
||||
KotlinNativeMetadataVersion.DEFAULT_INSTANCE,
|
||||
KotlinNativeMetadataVersion.INVALID_VERSION,
|
||||
KotlinNativeMetaFileType, { KonanSerializerProtocol }, NullFlexibleTypeDeserializer,
|
||||
{ KotlinNativeMetadataVersion.DEFAULT_INSTANCE },
|
||||
{ KotlinNativeMetadataVersion.INVALID_VERSION },
|
||||
KotlinNativeMetaFileType.STUB_VERSION
|
||||
) {
|
||||
|
||||
|
||||
+11
-9
@@ -30,14 +30,14 @@ import java.io.IOException
|
||||
|
||||
abstract class KotlinNativeMetadataDecompilerBase<out V : BinaryVersion>(
|
||||
private val fileType: FileType,
|
||||
private val serializerProtocol: SerializerExtensionProtocol,
|
||||
private val serializerProtocol: () -> SerializerExtensionProtocol,
|
||||
private val flexibleTypeDeserializer: FlexibleTypeDeserializer,
|
||||
private val expectedBinaryVersion: V,
|
||||
private val invalidBinaryVersion: V,
|
||||
private val expectedBinaryVersion: () -> V,
|
||||
private val invalidBinaryVersion: () -> V,
|
||||
stubVersion: Int
|
||||
) : ClassFileDecompilers.Full() {
|
||||
|
||||
private val stubBuilder =
|
||||
private val metadataStubBuilder: KotlinNativeMetadataStubBuilder =
|
||||
KotlinNativeMetadataStubBuilder(
|
||||
stubVersion,
|
||||
fileType,
|
||||
@@ -45,13 +45,15 @@ abstract class KotlinNativeMetadataDecompilerBase<out V : BinaryVersion>(
|
||||
::readFileSafely
|
||||
)
|
||||
|
||||
private val renderer = DescriptorRenderer.withOptions { defaultDecompilerRendererOptions() }
|
||||
private val renderer: DescriptorRenderer by lazy {
|
||||
DescriptorRenderer.withOptions { defaultDecompilerRendererOptions() }
|
||||
}
|
||||
|
||||
protected abstract fun doReadFile(file: VirtualFile): FileWithMetadata?
|
||||
|
||||
override fun accepts(file: VirtualFile) = file.fileType == fileType
|
||||
|
||||
override fun getStubBuilder() = stubBuilder
|
||||
override fun getStubBuilder() = metadataStubBuilder
|
||||
|
||||
override fun createFileViewProvider(file: VirtualFile, manager: PsiManager, physical: Boolean) =
|
||||
KotlinDecompiledFileViewProvider(manager, file, physical) { provider ->
|
||||
@@ -81,14 +83,14 @@ abstract class KotlinNativeMetadataDecompilerBase<out V : BinaryVersion>(
|
||||
val file = readFileSafely(virtualFile)
|
||||
|
||||
return when (file) {
|
||||
is FileWithMetadata.Incompatible -> createIncompatibleAbiVersionDecompiledText(expectedBinaryVersion, file.version)
|
||||
is FileWithMetadata.Incompatible -> createIncompatibleAbiVersionDecompiledText(expectedBinaryVersion(), file.version)
|
||||
is FileWithMetadata.Compatible -> decompiledText(
|
||||
file,
|
||||
serializerProtocol,
|
||||
serializerProtocol(),
|
||||
flexibleTypeDeserializer,
|
||||
renderer
|
||||
)
|
||||
null -> createIncompatibleAbiVersionDecompiledText(expectedBinaryVersion, invalidBinaryVersion)
|
||||
null -> createIncompatibleAbiVersionDecompiledText(expectedBinaryVersion(), invalidBinaryVersion())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -21,7 +21,7 @@ import org.jetbrains.kotlin.serialization.konan.NullFlexibleTypeDeserializer
|
||||
open class KotlinNativeMetadataStubBuilder(
|
||||
private val version: Int,
|
||||
private val fileType: FileType,
|
||||
private val serializerProtocol: SerializerExtensionProtocol,
|
||||
private val serializerProtocol: () -> SerializerExtensionProtocol,
|
||||
private val readFile: (VirtualFile) -> FileWithMetadata?
|
||||
) : ClsStubBuilder() {
|
||||
|
||||
@@ -39,7 +39,7 @@ open class KotlinNativeMetadataStubBuilder(
|
||||
val renderer = DescriptorRenderer.withOptions { defaultDecompilerRendererOptions() }
|
||||
val ktFileText = decompiledText(
|
||||
file,
|
||||
serializerProtocol,
|
||||
serializerProtocol(),
|
||||
NullFlexibleTypeDeserializer,
|
||||
renderer
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user