Allow customizing source file path conversion in lookup storage
This commit is contained in:
@@ -30,15 +30,18 @@ import java.io.IOException
|
||||
import java.util.*
|
||||
|
||||
|
||||
open class LookupStorage(targetDataDir: File) : BasicMapsOwner(targetDataDir) {
|
||||
open class LookupStorage(
|
||||
targetDataDir: File,
|
||||
sourcePathConverter: SourceFileToPathConverter
|
||||
) : BasicMapsOwner(targetDataDir) {
|
||||
companion object {
|
||||
private val DELETED_TO_SIZE_TRESHOLD = 0.5
|
||||
private val MINIMUM_GARBAGE_COLLECTIBLE_SIZE = 10000
|
||||
}
|
||||
|
||||
private val countersFile = "counters".storageFile
|
||||
private val idToFile = registerMap(IdToFileMap("id-to-file".storageFile))
|
||||
private val fileToId = registerMap(FileToIdMap("file-to-id".storageFile))
|
||||
private val idToFile = registerMap(IdToFileMap("id-to-file".storageFile, sourcePathConverter))
|
||||
private val fileToId = registerMap(FileToIdMap("file-to-id".storageFile, sourcePathConverter))
|
||||
private val lookupMap = registerMap(LookupMap("lookups".storageFile))
|
||||
|
||||
@Volatile
|
||||
|
||||
@@ -18,26 +18,27 @@ package org.jetbrains.kotlin.incremental.storage
|
||||
|
||||
import java.io.File
|
||||
|
||||
internal class FileToIdMap(file: File) : BasicMap<File, Int>(file, FileKeyDescriptor, IntExternalizer) {
|
||||
override fun dumpKey(key: File): String = key.toString()
|
||||
|
||||
internal class FileToIdMap(
|
||||
file: File,
|
||||
private val sourcePathConverter: SourceFileToPathConverter
|
||||
) : BasicStringMap<Int>(file, IntExternalizer) {
|
||||
override fun dumpValue(value: Int): String = value.toString()
|
||||
|
||||
operator fun get(file: File): Int? = storage[file]
|
||||
operator fun get(file: File): Int? = storage[sourcePathConverter.toPath(file)]
|
||||
|
||||
operator fun set(file: File, id: Int) {
|
||||
storage[file] = id
|
||||
storage[sourcePathConverter.toPath(file)] = id
|
||||
}
|
||||
|
||||
fun remove(file: File) {
|
||||
storage.remove(file)
|
||||
storage.remove(sourcePathConverter.toPath(file))
|
||||
}
|
||||
|
||||
fun toMap(): Map<File, Int> {
|
||||
val result = HashMap<File, Int>()
|
||||
for (key in storage.keys) {
|
||||
val value = storage[key] ?: continue
|
||||
result[key] = value
|
||||
result[sourcePathConverter.toFile(key)] = value
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.incremental.storage
|
||||
|
||||
import org.jetbrains.kotlin.incremental.dumpCollection
|
||||
import java.io.File
|
||||
|
||||
class FilesMap(storageFile: File)
|
||||
: BasicStringMap<Collection<String>>(storageFile, PathStringDescriptor, StringCollectionExternalizer) {
|
||||
|
||||
operator fun set(sourceFile: File, outputFiles: Collection<File>) {
|
||||
storage[sourceFile.absolutePath] = outputFiles.map { it.absolutePath }
|
||||
}
|
||||
|
||||
operator fun get(sourceFile: File): Collection<File> =
|
||||
storage[sourceFile.absolutePath].orEmpty().map(::File)
|
||||
|
||||
override fun dumpValue(value: Collection<String>) =
|
||||
value.dumpCollection()
|
||||
|
||||
fun remove(file: File): Collection<File> =
|
||||
get(file).also { storage.remove(file.absolutePath) }
|
||||
}
|
||||
@@ -16,20 +16,24 @@
|
||||
|
||||
package org.jetbrains.kotlin.incremental.storage
|
||||
|
||||
import com.intellij.util.io.EnumeratorStringDescriptor
|
||||
import com.intellij.util.io.ExternalIntegerKeyDescriptor
|
||||
import java.io.File
|
||||
|
||||
internal class IdToFileMap(file: File) : BasicMap<Int, File>(file, ExternalIntegerKeyDescriptor(), FileKeyDescriptor) {
|
||||
internal class IdToFileMap(
|
||||
file: File,
|
||||
private val sourcePathConverter: SourceFileToPathConverter
|
||||
) : BasicMap<Int, String>(file, ExternalIntegerKeyDescriptor(), EnumeratorStringDescriptor.INSTANCE) {
|
||||
override fun dumpKey(key: Int): String = key.toString()
|
||||
|
||||
override fun dumpValue(value: File): String = value.toString()
|
||||
override fun dumpValue(value: String): String = value
|
||||
|
||||
operator fun get(id: Int): File? = storage[id]
|
||||
operator fun get(id: Int): File? = storage[id]?.let { sourcePathConverter.toFile(it) }
|
||||
|
||||
operator fun contains(id: Int): Boolean = id in storage
|
||||
|
||||
operator fun set(id: Int, file: File) {
|
||||
storage[id] = file
|
||||
storage[id] = sourcePathConverter.toPath(file)
|
||||
}
|
||||
|
||||
fun remove(id: Int) {
|
||||
|
||||
@@ -177,20 +177,6 @@ object PathStringDescriptor : EnumeratorStringDescriptor() {
|
||||
override fun isEqual(val1: String, val2: String?) = FileUtil.pathsEqual(val1, val2)
|
||||
}
|
||||
|
||||
object FileKeyDescriptor : KeyDescriptor<File> {
|
||||
override fun read(input: DataInput): File = File(input.readUTF())
|
||||
|
||||
override fun save(output: DataOutput, value: File) {
|
||||
output.writeUTF(value.canonicalPath)
|
||||
}
|
||||
|
||||
override fun getHashCode(value: File?): Int =
|
||||
FileUtil.FILE_HASHING_STRATEGY.computeHashCode(value)
|
||||
|
||||
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>
|
||||
|
||||
Reference in New Issue
Block a user