From a58defc52f2185444612430b1fa0152a5b824489 Mon Sep 17 00:00:00 2001 From: Dmitry Batkovich Date: Mon, 22 Mar 2021 09:27:38 +0300 Subject: [PATCH] index: do not count rebuilt hash enumerator handles twice EA-255338 GitOrigin-RevId: b399e99bdd2a8347a16f9c84fa134764b8b3c512 --- .../snapshot/SnapshotHashEnumeratorService.kt | 40 +++++++++++-------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/util/indexing/snapshot/SnapshotHashEnumeratorService.kt b/platform/lang-impl/src/com/intellij/util/indexing/snapshot/SnapshotHashEnumeratorService.kt index b98ed55280f7..a9648a42a824 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/snapshot/SnapshotHashEnumeratorService.kt +++ b/platform/lang-impl/src/com/intellij/util/indexing/snapshot/SnapshotHashEnumeratorService.kt @@ -32,6 +32,29 @@ internal class SnapshotHashEnumeratorService : Closeable { fun release() } + private inner class HashEnumeratorHandleImpl(private val requestorIndexId: ID<*, *>): HashEnumeratorHandle { + override fun enumerateHash(digest: ByteArray): Int = contentHashEnumerator!!.enumerate(digest) + + override fun release() { + lock.withLock { + handles.remove(this) + LOG.assertTrue(state != State.CLOSED, "handle is released for closed enumerator") + } + } + + override fun equals(other: Any?): Boolean { + return other is HashEnumeratorHandleImpl && other.requestorIndexId == requestorIndexId + } + + override fun hashCode(): Int { + return requestorIndexId.hashCode() + } + + override fun toString(): String { + return "handle for ${requestorIndexId.name}" + } + } + @Volatile private var state: State = State.CLOSED @@ -87,25 +110,10 @@ internal class SnapshotHashEnumeratorService : Closeable { } fun createHashEnumeratorHandle(requestorIndexId: ID<*, *>): HashEnumeratorHandle { - val handle = object : HashEnumeratorHandle { - override fun enumerateHash(digest: ByteArray): Int = contentHashEnumerator!!.enumerate(digest) - - override fun release() { - lock.withLock { - handles.remove(this) - LOG.assertTrue(state != State.CLOSED, "handle is released for closed enumerator") - } - } - - override fun toString(): String { - return "handle for ${requestorIndexId.name}" - } - } - + val handle = HashEnumeratorHandleImpl(requestorIndexId) lock.withLock { handles.add(handle) } - return handle } }