From d53f2e156570a75e6d719a04250ee423c60b555a Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Thu, 15 Jul 2021 14:02:29 +1000 Subject: [PATCH] Avoid re-using empty iterator in debug logging --- .../internal/inc/MemberRefInvalidator.scala | 9 +++-- .../test/scala/sbt/inc/binary/Scratch.scala | 33 +++++++++++++++++++ 2 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 internal/zinc-persist/src/test/scala/sbt/inc/binary/Scratch.scala diff --git a/internal/zinc-core/src/main/scala/sbt/internal/inc/MemberRefInvalidator.scala b/internal/zinc-core/src/main/scala/sbt/internal/inc/MemberRefInvalidator.scala index 1189bd45fb..4ef2c242a0 100644 --- a/internal/zinc-core/src/main/scala/sbt/internal/inc/MemberRefInvalidator.scala +++ b/internal/zinc-core/src/main/scala/sbt/internal/inc/MemberRefInvalidator.scala @@ -135,14 +135,17 @@ private[inc] class MemberRefInvalidator(log: Logger, logRecompileOnMacro: Boolea private def filteredDependencies(dependent: Set[String]): Set[String] = { dependent.filter { case from if isScalaClass(from) => - val affectedNames = usedNames(from).iterator.filter(modifiedNames.isModified) - if (affectedNames.isEmpty) { + val fromUsedNames = usedNames(from) + val affected = fromUsedNames.exists(modifiedNames.isModified) + if (!affected) { log.debug( s"None of the modified names appears in source file of $from. This dependency is not being considered for invalidation." ) false } else { - log.debug(s"The following modified names cause invalidation of $from: $affectedNames") + def showUsedNames: String = + fromUsedNames.iterator.filter(modifiedNames.isModified).mkString("[", ", ", "]") + log.debug(s"The following modified names cause invalidation of $from: $showUsedNames") true } case from => diff --git a/internal/zinc-persist/src/test/scala/sbt/inc/binary/Scratch.scala b/internal/zinc-persist/src/test/scala/sbt/inc/binary/Scratch.scala new file mode 100644 index 0000000000..35e18d9294 --- /dev/null +++ b/internal/zinc-persist/src/test/scala/sbt/inc/binary/Scratch.scala @@ -0,0 +1,33 @@ +package sbt.inc.binary + +object Scratch { + def timed[T](f: => T) = { + val start = System.nanoTime; + try f + finally { + println(((System.nanoTime - start) / 1000 / 1000) + " ms") + } + } + def main(args: Array[String]): Unit = { + for (i <- 1 to 32) { + println( + timed( + sbt.internal.inc.FileAnalysisStore + .binary(new java.io.File("/Users/jz/code/scala/target/compiler/zinc/inc_compile.zip")) + .get + ) + ) + } + timed( + for (i <- 1 to 32) { + println( + timed( + sbt.internal.inc.FileAnalysisStore + .binary(new java.io.File("/Users/jz/code/scala/target/compiler/zinc/inc_compile.zip")) + .get + ) + ) + } + ) + } +}