@@ -20,6 +20,7 @@ import org.jetbrains.jps.builders.storage.StorageProvider
|
||||
import org.jetbrains.kotlin.incremental.components.LookupTracker
|
||||
import org.jetbrains.kotlin.incremental.components.ScopeKind
|
||||
import org.jetbrains.kotlin.jps.incremental.storage.BasicMapsOwner
|
||||
import org.jetbrains.kotlin.jps.incremental.storage.FilesMap
|
||||
import org.jetbrains.kotlin.jps.incremental.storage.LookupMap
|
||||
import java.io.File
|
||||
|
||||
@@ -31,7 +32,8 @@ class LookupTrackerImpl(private val targetDataDir: File) : BasicMapsOwner(), Loo
|
||||
private val String.storageFile: File
|
||||
get() = File(targetDataDir, this + IncrementalCacheImpl.CACHE_EXTENSION)
|
||||
|
||||
private val lookupMap = registerMap(LookupMap("lookups".storageFile))
|
||||
private val filesMap = registerMap(FilesMap("files".storageFile))
|
||||
private val lookupMap = registerMap(LookupMap("lookups".storageFile, filesMap))
|
||||
|
||||
override fun record(lookupContainingFile: String, lookupLine: Int?, lookupColumn: Int?, scopeFqName: String, scopeKind: ScopeKind, name: String) {
|
||||
lookupMap.add(name, scopeFqName, lookupContainingFile)
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.jps.incremental.storage
|
||||
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.util.io.ExternalIntegerKeyDescriptor
|
||||
import java.io.File
|
||||
|
||||
class FilesMap(file: File) : BasicMap<Int, Collection<String>>(file, ExternalIntegerKeyDescriptor(), PATH_COLLECTION_EXTERNALIZER) {
|
||||
override fun dumpKey(key: Int): String = key.toString()
|
||||
|
||||
override fun dumpValue(value: Collection<String>): String = value.toString()
|
||||
|
||||
public fun get(hash: Int): Collection<String>? = storage[hash]
|
||||
|
||||
public fun add(path: String): Int {
|
||||
val hash = FileUtil.PATH_HASHING_STRATEGY.computeHashCode(path)
|
||||
storage.append(hash) { it.writeUTF(path) }
|
||||
return hash
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -18,16 +18,20 @@ package org.jetbrains.kotlin.jps.incremental.storage
|
||||
|
||||
import java.io.File
|
||||
|
||||
class LookupMap(file: File) : BasicMap<IntPair, Collection<String>>(file, INT_PAIR_KEY_DESCRIPTOR, PATH_COLLECTION_EXTERNALIZER) {
|
||||
class LookupMap(
|
||||
storage: File,
|
||||
private val filesMap: FilesMap
|
||||
) : BasicMap<IntPair, Set<Int>>(storage, INT_PAIR_KEY_DESCRIPTOR, INT_SET_EXTERNALIZER) {
|
||||
override fun dumpKey(key: IntPair): String = key.toString()
|
||||
|
||||
override fun dumpValue(value: Collection<String>): String = value.toString()
|
||||
override fun dumpValue(value: Set<Int>): String = value.toString()
|
||||
|
||||
public fun add(name: String, scope: String, path: String) {
|
||||
storage.append(HashPair(name, scope)) { out -> out.writeUTF(path) }
|
||||
val pathHash = filesMap.add(path)
|
||||
storage.append(HashPair(name, scope)) { out -> out.writeInt(pathHash) }
|
||||
}
|
||||
|
||||
public fun get(name: String, scope: String): Collection<String>? = storage[HashPair(name, scope)]
|
||||
public fun get(name: String, scope: String): Set<Int>? = storage[HashPair(name, scope)]
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -21,6 +21,8 @@ import com.intellij.util.io.DataExternalizer
|
||||
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 java.io.DataInput
|
||||
import java.io.DataInputStream
|
||||
import java.io.DataOutput
|
||||
@@ -215,4 +217,23 @@ object CONSTANTS_MAP_EXTERNALIZER : DataExternalizer<Map<String, Any>> {
|
||||
private enum class Kind {
|
||||
INT, FLOAT, LONG, DOUBLE, STRING
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
object INT_SET_EXTERNALIZER : DataExternalizer<Set<Int>> {
|
||||
override fun save(out: DataOutput, value: Set<Int>) {
|
||||
value.forEach { out.writeInt(it) }
|
||||
}
|
||||
|
||||
override fun read(`in`: DataInput): Set<Int> {
|
||||
val result = TIntHashSet()
|
||||
val stream = `in` as DataInputStream
|
||||
|
||||
while (stream.available() > 0) {
|
||||
val str = stream.readInt()
|
||||
result.add(str)
|
||||
}
|
||||
|
||||
return TIntHashSetDecorator(result)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user