From 173e7e2dbda129509748def57aa02950ad93e8f1 Mon Sep 17 00:00:00 2001 From: Paweł Marks Date: Tue, 7 Jul 2020 08:12:17 +0200 Subject: Cache location provider --- .../resolvers/local/DefaultLocationProviderFactory.kt | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/base/src/main/kotlin/resolvers/local/DefaultLocationProviderFactory.kt b/plugins/base/src/main/kotlin/resolvers/local/DefaultLocationProviderFactory.kt index 1918472b..442d2e6d 100644 --- a/plugins/base/src/main/kotlin/resolvers/local/DefaultLocationProviderFactory.kt +++ b/plugins/base/src/main/kotlin/resolvers/local/DefaultLocationProviderFactory.kt @@ -3,10 +3,21 @@ package org.jetbrains.dokka.base.resolvers.local import org.jetbrains.dokka.pages.MultimoduleRootPageNode import org.jetbrains.dokka.pages.RootPageNode import org.jetbrains.dokka.plugability.DokkaContext +import java.util.* +import java.util.concurrent.ConcurrentHashMap class DefaultLocationProviderFactory(private val context: DokkaContext) : LocationProviderFactory { - override fun getLocationProvider(pageNode: RootPageNode) = + private val cache = ConcurrentHashMap() + + override fun getLocationProvider(pageNode: RootPageNode) = cache.computeIfAbsent(CacheWrapper(pageNode)) { if (pageNode.children.first() is MultimoduleRootPageNode) MultimoduleLocationProvider(pageNode, context) else DefaultLocationProvider(pageNode, context) + } +} + +private class CacheWrapper(val pageNode: RootPageNode) { + override fun equals(other: Any?) = other is CacheWrapper && other.pageNode == this.pageNode + + override fun hashCode() = System.identityHashCode(pageNode) } \ No newline at end of file -- cgit