From 376fb151232a2ce4a117273dce9896d3c8a08e5c Mon Sep 17 00:00:00 2001 From: Alexey Tsvetkov Date: Thu, 29 Oct 2015 17:44:10 +0300 Subject: [PATCH] Move LookupMap Original commit: f6f300d903ed5016e9dd6a20c93d74371e29dd85 --- .../jps/incremental/LookupTrackerImpl.kt | 47 +---------------- .../kotlin/jps/incremental/storage/IntPair.kt | 52 +++++++++++++++++++ .../jps/incremental/storage/LookupMap.kt | 35 +++++++++++++ 3 files changed, 88 insertions(+), 46 deletions(-) create mode 100644 jps/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/storage/IntPair.kt create mode 100644 jps/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/storage/LookupMap.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 5e11010e236..c65d559ece2 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 @@ -16,14 +16,11 @@ package org.jetbrains.kotlin.jps.incremental -import com.intellij.util.io.KeyDescriptor import org.jetbrains.jps.builders.storage.StorageProvider import org.jetbrains.jps.incremental.storage.StorageOwner import org.jetbrains.kotlin.incremental.components.LookupTracker import org.jetbrains.kotlin.incremental.components.ScopeKind -import org.jetbrains.kotlin.jps.incremental.storage.BasicMap -import java.io.DataInput -import java.io.DataOutput +import org.jetbrains.kotlin.jps.incremental.storage.LookupMap import java.io.File object LOOKUP_TRACKER_STORAGE_PROVIDER : StorageProvider() { @@ -50,45 +47,3 @@ class LookupTrackerImpl(targetDataDir: File) : LookupTracker, StorageOwner { } } -private class LookupMap(file: File) : BasicMap>(file, INT_PAIR_KEY_DESCRIPTOR, PathCollectionExternalizer) { - override fun dumpKey(key: IntPair): String = key.toString() - - override fun dumpValue(value: Collection): String = value.toString() - - public fun add(name: String, scope: String, path: String) { - storage.append(HashPair(name, scope)) { out -> out.writeUTF(path) } - } - - public fun get(name: String, scope: String): Collection? = storage[HashPair(name, scope)] -} - -private data class IntPair(val first: Int, val second: Int) : Comparable { - override fun compareTo(other: IntPair): Int { - val firstCmp = first.compareTo(other.first) - - if (firstCmp != 0) return firstCmp - - return second.compareTo(other.second) - } -} - -private fun HashPair(a: Any, b: Any): IntPair = IntPair(a.hashCode(), b.hashCode()) - -private object INT_PAIR_KEY_DESCRIPTOR : KeyDescriptor { - override fun read(`in`: DataInput): IntPair { - val first = `in`.readInt() - val second = `in`.readInt() - return IntPair(first, second) - } - - override fun save(out: DataOutput, value: IntPair?) { - if (value == null) return - - out.writeInt(value.first) - out.writeInt(value.second) - } - - override fun getHashCode(value: IntPair?): Int = value?.hashCode() ?: 0 - - override fun isEqual(val1: IntPair?, val2: IntPair?): Boolean = val1 == val2 -} diff --git a/jps/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/storage/IntPair.kt b/jps/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/storage/IntPair.kt new file mode 100644 index 00000000000..d285bdd3520 --- /dev/null +++ b/jps/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/storage/IntPair.kt @@ -0,0 +1,52 @@ +/* + * 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.util.io.KeyDescriptor +import java.io.DataInput +import java.io.DataOutput + +data class IntPair(val first: Int, val second: Int) : Comparable { + override fun compareTo(other: IntPair): Int { + val firstCmp = first.compareTo(other.first) + + if (firstCmp != 0) return firstCmp + + return second.compareTo(other.second) + } +} + +fun HashPair(a: Any, b: Any): IntPair = IntPair(a.hashCode(), b.hashCode()) + +internal object INT_PAIR_KEY_DESCRIPTOR : KeyDescriptor { + override fun read(`in`: DataInput): IntPair { + val first = `in`.readInt() + val second = `in`.readInt() + return IntPair(first, second) + } + + override fun save(out: DataOutput, value: IntPair?) { + if (value == null) return + + out.writeInt(value.first) + out.writeInt(value.second) + } + + override fun getHashCode(value: IntPair?): Int = value?.hashCode() ?: 0 + + override fun isEqual(val1: IntPair?, val2: IntPair?): Boolean = val1 == val2 +} \ No newline at end of file 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 new file mode 100644 index 00000000000..e89741f75e9 --- /dev/null +++ b/jps/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/storage/LookupMap.kt @@ -0,0 +1,35 @@ +/* + * 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 org.jetbrains.kotlin.jps.incremental.PathCollectionExternalizer +import java.io.File + +class LookupMap(file: File) : BasicMap>(file, INT_PAIR_KEY_DESCRIPTOR, PathCollectionExternalizer) { + override fun dumpKey(key: IntPair): String = key.toString() + + override fun dumpValue(value: Collection): String = value.toString() + + public fun add(name: String, scope: String, path: String) { + storage.append(HashPair(name, scope)) { out -> out.writeUTF(path) } + } + + public fun get(name: String, scope: String): Collection? = storage[HashPair(name, scope)] +} + + +