Skip to content

Commit 3d75b78

Browse files
committed
Use IOUtil instead of DataOutput for readUTF/writeUTF in file based index
It uses less space and also may be a little bit faster
1 parent 0fb5a18 commit 3d75b78

File tree

2 files changed

+18
-28
lines changed

2 files changed

+18
-28
lines changed

idea/idea-analysis/src/org/jetbrains/kotlin/idea/vfilefinder/fileIndexes.kt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.idea.vfilefinder
1919
import com.intellij.ide.highlighter.JavaClassFileType
2020
import com.intellij.openapi.diagnostic.Logger
2121
import com.intellij.util.indexing.*
22+
import com.intellij.util.io.IOUtil
2223
import com.intellij.util.io.KeyDescriptor
2324
import org.jetbrains.kotlin.idea.caches.IDEKotlinBinaryClassCache
2425
import org.jetbrains.kotlin.idea.decompiler.js.JsMetaFileUtils
@@ -32,9 +33,9 @@ abstract class KotlinFileIndexBase<T>(classOfIndex: Class<T>) : ScalarIndexExten
3233
val KEY: ID<FqName, Void> = ID.create(classOfIndex.canonicalName)
3334

3435
private val KEY_DESCRIPTOR : KeyDescriptor<FqName> = object : KeyDescriptor<FqName> {
35-
override fun save(output: DataOutput, value: FqName) = output.writeUTF(value.asString())
36+
override fun save(output: DataOutput, value: FqName) = IOUtil.writeUTF(output, value.asString())
3637

37-
override fun read(input: DataInput) = FqName(input.readUTF())
38+
override fun read(input: DataInput) = FqName(IOUtil.readUTF(input))
3839

3940
override fun getHashCode(value: FqName) = value.asString().hashCode()
4041

@@ -76,9 +77,9 @@ object KotlinClassFileIndex : KotlinFileIndexBase<KotlinClassFileIndex>(KotlinCl
7677

7778
override fun getVersion() = VERSION
7879

79-
private val VERSION = 2
80+
private val VERSION = 3
8081

81-
private val INDEXER = indexer() { fileContent ->
82+
private val INDEXER = indexer { fileContent ->
8283
val headerInfo = IDEKotlinBinaryClassCache.getKotlinBinaryClassHeaderData(fileContent.file, fileContent.content)
8384
if (headerInfo != null && headerInfo.classHeader.metadataVersion.isCompatible()) headerInfo.classId.asSingleFqName() else null
8485
}
@@ -92,9 +93,9 @@ object KotlinJavaScriptMetaFileIndex : KotlinFileIndexBase<KotlinJavaScriptMetaF
9293

9394
override fun getVersion() = VERSION
9495

95-
private val VERSION = 2
96+
private val VERSION = 3
9697

97-
private val INDEXER = indexer() { fileContent ->
98+
private val INDEXER = indexer { fileContent ->
9899
if (fileContent.fileType == KotlinJavaScriptMetaFileType) JsMetaFileUtils.getClassFqName(fileContent.file) else null
99100
}
100101

idea/idea-analysis/src/org/jetbrains/kotlin/idea/vfilefinder/moduleMappingIndexes.kt

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616

1717
package org.jetbrains.kotlin.idea.vfilefinder
1818

19-
import com.intellij.openapi.diagnostic.Logger
2019
import com.intellij.util.indexing.*
2120
import com.intellij.util.io.DataExternalizer
21+
import com.intellij.util.io.IOUtil
2222
import com.intellij.util.io.KeyDescriptor
2323
import org.jetbrains.kotlin.load.kotlin.ModuleMapping
2424
import org.jetbrains.kotlin.load.kotlin.PackageParts
@@ -27,41 +27,30 @@ import java.io.DataOutput
2727

2828
object KotlinModuleMappingIndex : FileBasedIndexExtension<String, PackageParts>() {
2929

30-
private val classOfIndex = KotlinModuleMappingIndex::class.java.canonicalName
31-
32-
val KEY: ID<String, PackageParts> = ID.create(classOfIndex)
30+
val KEY: ID<String, PackageParts> = ID.create(KotlinModuleMappingIndex::class.java.canonicalName)
3331

3432
private val KEY_DESCRIPTOR = object : KeyDescriptor<String> {
35-
override fun save(output: DataOutput, value: String) = output.writeUTF(value)
33+
override fun save(output: DataOutput, value: String) = IOUtil.writeUTF(output, value)
3634

37-
override fun read(input: DataInput) = input.readUTF()
35+
override fun read(input: DataInput) = IOUtil.readUTF(input)
3836

3937
override fun getHashCode(value: String) = value.hashCode()
4038

4139
override fun isEqual(val1: String?, val2: String?) = val1 == val2
4240
}
4341

4442
private val VALUE_EXTERNALIZER = object : DataExternalizer<PackageParts> {
45-
override fun read(`in`: DataInput): PackageParts? {
46-
val packageFqName = `in`.readUTF()
47-
val parts = PackageParts(packageFqName)
48-
val size = `in`.readInt()
49-
(1..size).forEach {
50-
parts.parts.add(`in`.readUTF())
51-
}
52-
53-
return parts
54-
}
43+
override fun read(input: DataInput): PackageParts? =
44+
PackageParts(IOUtil.readUTF(input)).apply {
45+
parts.addAll(IOUtil.readStringList(input))
46+
}
5547

5648
override fun save(out: DataOutput, value: PackageParts?) {
57-
out.writeUTF(value!!.packageFqName)
58-
out.writeInt(value.parts.size)
59-
value.parts.forEach { out.writeUTF(it) }
49+
IOUtil.writeUTF(out, value!!.packageFqName)
50+
IOUtil.writeStringList(out, value.parts)
6051
}
6152
}
6253

63-
private val LOG = Logger.getInstance(classOfIndex)
64-
6554
override fun getName() = KEY
6655

6756
override fun dependsOnFileContent() = true
@@ -74,7 +63,7 @@ object KotlinModuleMappingIndex : FileBasedIndexExtension<String, PackageParts>(
7463
return FileBasedIndex.InputFilter { file -> file.extension == ModuleMapping.MAPPING_FILE_EXT }
7564
}
7665

77-
override fun getVersion(): Int = 1
66+
override fun getVersion(): Int = 2
7867

7968
override fun getIndexer(): DataIndexer<String, PackageParts, FileContent> {
8069
return DataIndexer<String, PackageParts, FileContent> { inputData ->

0 commit comments

Comments
 (0)