From 700170c2dff6bc4acce36a5429a3d2e402ed0e0e Mon Sep 17 00:00:00 2001 From: Alexey Tsvetkov Date: Thu, 29 Oct 2015 19:56:31 +0300 Subject: [PATCH] Hash file names Original commit: 87d836cd6715b328c6a0ed86fb39ed4fdf8e0c89 --- .../jps/incremental/LookupTrackerImpl.kt | 4 +- .../jps/incremental/storage/FilesMap.kt | 38 +++++++++++++++++++ .../jps/incremental/storage/LookupMap.kt | 12 ++++-- .../jps/incremental/storage/externalizers.kt | 21 ++++++++++ 4 files changed, 70 insertions(+), 5 deletions(-) create mode 100644 jps/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/storage/FilesMap.kt diff --git a/jps/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/LookupTrackerImpl.kt b/jps/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/LookupTrackerImpl.kt index b250b6df913..c8ad2681dc2 100644 --- a/jps/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/LookupTrackerImpl.kt +++ b/jps/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/LookupTrackerImpl.kt @@ -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) diff --git a/jps/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/storage/FilesMap.kt b/jps/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/storage/FilesMap.kt new file mode 100644 index 00000000000..05c98405d2c --- /dev/null +++ b/jps/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/storage/FilesMap.kt @@ -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>(file, ExternalIntegerKeyDescriptor(), PATH_COLLECTION_EXTERNALIZER) { + override fun dumpKey(key: Int): String = key.toString() + + override fun dumpValue(value: Collection): String = value.toString() + + public fun get(hash: Int): Collection? = storage[hash] + + public fun add(path: String): Int { + val hash = FileUtil.PATH_HASHING_STRATEGY.computeHashCode(path) + storage.append(hash) { it.writeUTF(path) } + return hash + } +} + + + diff --git a/jps/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/storage/LookupMap.kt b/jps/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/storage/LookupMap.kt index adc104dba2d..374451c2609 100644 --- a/jps/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/storage/LookupMap.kt +++ b/jps/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/storage/LookupMap.kt @@ -18,16 +18,20 @@ package org.jetbrains.kotlin.jps.incremental.storage import java.io.File -class LookupMap(file: File) : BasicMap>(file, INT_PAIR_KEY_DESCRIPTOR, PATH_COLLECTION_EXTERNALIZER) { +class LookupMap( + storage: File, + private val filesMap: FilesMap +) : BasicMap>(storage, INT_PAIR_KEY_DESCRIPTOR, INT_SET_EXTERNALIZER) { override fun dumpKey(key: IntPair): String = key.toString() - override fun dumpValue(value: Collection): String = value.toString() + override fun dumpValue(value: Set): 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? = storage[HashPair(name, scope)] + public fun get(name: String, scope: String): Set? = storage[HashPair(name, scope)] } diff --git a/jps/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/storage/externalizers.kt b/jps/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/storage/externalizers.kt index f8cfd2ed137..68618da5a45 100644 --- a/jps/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/storage/externalizers.kt +++ b/jps/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/storage/externalizers.kt @@ -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> { private enum class Kind { INT, FLOAT, LONG, DOUBLE, STRING } +} + + +object INT_SET_EXTERNALIZER : DataExternalizer> { + override fun save(out: DataOutput, value: Set) { + value.forEach { out.writeInt(it) } + } + + override fun read(`in`: DataInput): Set { + val result = TIntHashSet() + val stream = `in` as DataInputStream + + while (stream.available() > 0) { + val str = stream.readInt() + result.add(str) + } + + return TIntHashSetDecorator(result) + } } \ No newline at end of file