Simplify collection externalizers
This commit is contained in:
@@ -523,18 +523,18 @@ public class IncrementalCacheImpl(
|
||||
override fun dumpValue(value: Boolean) = ""
|
||||
}
|
||||
|
||||
private inner class MultifileClassFacadeMap(storageFile: File) : BasicStringMap<List<String>>(storageFile, StringListExternalizer) {
|
||||
public fun add(facadeName: JvmClassName, partNames: List<String>) {
|
||||
private inner class MultifileClassFacadeMap(storageFile: File) : BasicStringMap<Collection<String>>(storageFile, StringCollectionExternalizer) {
|
||||
public fun add(facadeName: JvmClassName, partNames: Collection<String>) {
|
||||
storage[facadeName.internalName] = partNames
|
||||
}
|
||||
|
||||
public fun getMultifileClassParts(facadeName: String): List<String>? = storage[facadeName]
|
||||
public fun getMultifileClassParts(facadeName: String): Collection<String>? = storage[facadeName]
|
||||
|
||||
public fun remove(className: JvmClassName) {
|
||||
storage.remove(className.internalName)
|
||||
}
|
||||
|
||||
override fun dumpValue(value: List<String>): String = value.toString()
|
||||
override fun dumpValue(value: Collection<String>): String = value.dumpCollection()
|
||||
}
|
||||
|
||||
private inner class MultifileClassPartMap(storageFile: File) : BasicStringMap<String>(storageFile, EnumeratorStringDescriptor.INSTANCE) {
|
||||
@@ -553,7 +553,7 @@ public class IncrementalCacheImpl(
|
||||
override fun dumpValue(value: String): String = value
|
||||
}
|
||||
|
||||
private inner class SourceToClassesMap(storageFile: File) : BasicStringMap<List<String>>(storageFile, PathStringDescriptor.INSTANCE, StringListExternalizer) {
|
||||
private inner class SourceToClassesMap(storageFile: File) : BasicStringMap<Collection<String>>(storageFile, PathStringDescriptor.INSTANCE, StringCollectionExternalizer) {
|
||||
public fun clearOutputsForSource(sourceFile: File) {
|
||||
remove(sourceFile.absolutePath)
|
||||
}
|
||||
@@ -565,7 +565,7 @@ public class IncrementalCacheImpl(
|
||||
public operator fun get(sourceFile: File): Collection<JvmClassName> =
|
||||
storage[sourceFile.absolutePath].orEmpty().map { JvmClassName.byInternalName(it) }
|
||||
|
||||
override fun dumpValue(value: List<String>) = value.toString()
|
||||
override fun dumpValue(value: Collection<String>) = value.dumpCollection()
|
||||
|
||||
override fun clean() {
|
||||
storage.keys.forEach { remove(it) }
|
||||
@@ -594,16 +594,15 @@ public class IncrementalCacheImpl(
|
||||
override fun dumpValue(value: Boolean) = ""
|
||||
}
|
||||
|
||||
private inner class DirtyInlineFunctionsMap(storageFile: File) : BasicStringMap<List<String>>(storageFile, StringListExternalizer) {
|
||||
public fun getEntries(): Map<JvmClassName, List<String>> =
|
||||
private inner class DirtyInlineFunctionsMap(storageFile: File) : BasicStringMap<Collection<String>>(storageFile, StringCollectionExternalizer) {
|
||||
public fun getEntries(): Map<JvmClassName, Collection<String>> =
|
||||
storage.keys.toMap(JvmClassName::byInternalName) { storage[it]!! }
|
||||
|
||||
public fun put(className: JvmClassName, changedFunctions: List<String>) {
|
||||
storage[className.internalName] = changedFunctions
|
||||
}
|
||||
|
||||
override fun dumpValue(value: List<String>) =
|
||||
value.dumpCollection()
|
||||
override fun dumpValue(value: Collection<String>) = value.dumpCollection()
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -18,16 +18,16 @@ package org.jetbrains.kotlin.jps.incremental.storage
|
||||
|
||||
import java.io.File
|
||||
|
||||
internal class LookupMap(storage: File) : BasicMap<LookupSymbolKey, Set<Int>>(storage, LookupSymbolKeyDescriptor, IntSetExternalizer) {
|
||||
internal class LookupMap(storage: File) : BasicMap<LookupSymbolKey, Collection<Int>>(storage, LookupSymbolKeyDescriptor, IntCollectionExternalizer) {
|
||||
override fun dumpKey(key: LookupSymbolKey): String = key.toString()
|
||||
|
||||
override fun dumpValue(value: Set<Int>): String = value.toString()
|
||||
override fun dumpValue(value: Collection<Int>): String = value.toString()
|
||||
|
||||
public fun add(name: String, scope: String, fileId: Int) {
|
||||
storage.append(LookupSymbolKey(name, scope)) { out -> out.writeInt(fileId) }
|
||||
}
|
||||
|
||||
public operator fun get(key: LookupSymbolKey): Set<Int>? = storage[key]
|
||||
public operator fun get(key: LookupSymbolKey): Collection<Int>? = storage[key]
|
||||
|
||||
public operator fun set(key: LookupSymbolKey, fileIds: Set<Int>) {
|
||||
storage[key] = fileIds
|
||||
|
||||
@@ -18,11 +18,11 @@ package org.jetbrains.kotlin.jps.incremental.storage
|
||||
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.util.io.DataExternalizer
|
||||
import com.intellij.util.io.EnumeratorStringDescriptor
|
||||
import com.intellij.util.io.IOUtil
|
||||
import com.intellij.util.io.KeyDescriptor
|
||||
import gnu.trove.THashSet
|
||||
import gnu.trove.TIntHashSet
|
||||
import gnu.trove.decorator.TIntHashSetDecorator
|
||||
import org.jetbrains.jps.incremental.storage.PathStringDescriptor
|
||||
import java.io.DataInput
|
||||
import java.io.DataInputStream
|
||||
import java.io.DataOutput
|
||||
@@ -125,44 +125,6 @@ object StringToLongMapExternalizer : StringMapExternalizer<Long>() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
object StringListExternalizer : DataExternalizer<List<String>> {
|
||||
override fun save(output: DataOutput, value: List<String>) {
|
||||
value.forEach { IOUtil.writeUTF(output, it) }
|
||||
}
|
||||
|
||||
override fun read(input: DataInput): List<String> {
|
||||
val result = ArrayList<String>()
|
||||
|
||||
while ((input as DataInputStream).available() > 0) {
|
||||
result.add(IOUtil.readUTF(input))
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
object PathCollectionExternalizer : DataExternalizer<Collection<String>> {
|
||||
override fun save(output: DataOutput, value: Collection<String>) {
|
||||
for (str in value) {
|
||||
IOUtil.writeUTF(output, str)
|
||||
}
|
||||
}
|
||||
|
||||
override fun read(input: DataInput): Collection<String> {
|
||||
val result = THashSet(FileUtil.PATH_HASHING_STRATEGY)
|
||||
val stream = input as DataInputStream
|
||||
|
||||
while (stream.available() > 0) {
|
||||
val str = IOUtil.readUTF(stream)
|
||||
result.add(str)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
object ConstantsMapExternalizer : DataExternalizer<Map<String, Any>> {
|
||||
override fun save(output: DataOutput, map: Map<String, Any>?) {
|
||||
output.writeInt(map!!.size())
|
||||
@@ -222,25 +184,6 @@ object ConstantsMapExternalizer : DataExternalizer<Map<String, Any>> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
object IntSetExternalizer : DataExternalizer<Set<Int>> {
|
||||
override fun save(output: DataOutput, value: Set<Int>) {
|
||||
value.forEach { output.writeInt(it) }
|
||||
}
|
||||
|
||||
override fun read(input: DataInput): Set<Int> {
|
||||
val result = TIntHashSet()
|
||||
val stream = input as DataInputStream
|
||||
|
||||
while (stream.available() > 0) {
|
||||
val str = stream.readInt()
|
||||
result.add(str)
|
||||
}
|
||||
|
||||
return TIntHashSetDecorator(result)
|
||||
}
|
||||
}
|
||||
|
||||
object IntExternalizer : DataExternalizer<Int> {
|
||||
override fun read(input: DataInput): Int = input.readInt()
|
||||
|
||||
@@ -261,4 +204,30 @@ object FileKeyDescriptor : KeyDescriptor<File> {
|
||||
|
||||
override fun isEqual(val1: File?, val2: File?): Boolean =
|
||||
FileUtil.FILE_HASHING_STRATEGY.equals(val1, val2)
|
||||
}
|
||||
}
|
||||
|
||||
open class CollectionExternalizer<T>(
|
||||
private val elementExternalizer: DataExternalizer<T>,
|
||||
private val newCollection: ()->MutableCollection<T>
|
||||
) : DataExternalizer<Collection<T>> {
|
||||
override fun read(input: DataInput): Collection<T> {
|
||||
val result = newCollection()
|
||||
val stream = input as DataInputStream
|
||||
|
||||
while (stream.available() > 0) {
|
||||
result.add(elementExternalizer.read(stream))
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
override fun save(output: DataOutput, value: Collection<T>) {
|
||||
value.forEach { elementExternalizer.save(output, it) }
|
||||
}
|
||||
}
|
||||
|
||||
object StringCollectionExternalizer : CollectionExternalizer<String>(EnumeratorStringDescriptor(), { HashSet() })
|
||||
|
||||
object PathCollectionExternalizer : CollectionExternalizer<String>(PathStringDescriptor(), { THashSet(FileUtil.PATH_HASHING_STRATEGY) })
|
||||
|
||||
object IntCollectionExternalizer : CollectionExternalizer<Int>(IntExternalizer, { HashSet() })
|
||||
|
||||
Reference in New Issue
Block a user