From 95fdd99acd00dfddb606dc2e4cb758052a5c68c8 Mon Sep 17 00:00:00 2001 From: friendseeker <66892505+Friendseeker@users.noreply.github.com> Date: Sun, 5 Nov 2023 15:16:49 -0800 Subject: [PATCH] Improve performance of LookupAnalysis via pre-built index --- zinc/src/main/scala/sbt/internal/inc/LookupImpl.scala | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/zinc/src/main/scala/sbt/internal/inc/LookupImpl.scala b/zinc/src/main/scala/sbt/internal/inc/LookupImpl.scala index 068b3f78a..7069b2920 100644 --- a/zinc/src/main/scala/sbt/internal/inc/LookupImpl.scala +++ b/zinc/src/main/scala/sbt/internal/inc/LookupImpl.scala @@ -31,6 +31,14 @@ class LookupImpl(compileConfiguration: CompileConfiguration, previousSetup: Opti } } + private lazy val binaryClassNameToAnalysis: Map[String, Analysis] = { + analyses.flatMap { analysis => + analysis.relations.productClassName._2s.map { binaryClassName => + binaryClassName -> analysis + } + }.toMap + } + lazy val previousClasspathHash: Vector[FileHash] = { previousSetup match { case Some(x) => x.options.classpathHash.toVector @@ -45,7 +53,7 @@ class LookupImpl(compileConfiguration: CompileConfiguration, previousSetup: Opti private val entry = MixedAnalyzingCompiler.classPathLookup(compileConfiguration) override def lookupAnalysis(binaryClassName: String): Option[CompileAnalysis] = - analyses.find(_.relations.productClassName._2s.contains(binaryClassName)) + binaryClassNameToAnalysis.get(binaryClassName) override def lookupOnClasspath(binaryClassName: String): Option[VirtualFileRef] = entry(binaryClassName)