Skip to content

Commit

Permalink
Avoid re-using empty iterator in debug logging
Browse files Browse the repository at this point in the history
  • Loading branch information
retronym committed Jul 15, 2021
1 parent 538ddae commit d53f2e1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand Down
33 changes: 33 additions & 0 deletions internal/zinc-persist/src/test/scala/sbt/inc/binary/Scratch.scala
Original file line number Diff line number Diff line change
@@ -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
)
)
}
)
}
}

0 comments on commit d53f2e1

Please sign in to comment.