Skip to content

Commit ee5d680

Browse files
committed
Optimize containsPhase
Avpid creation of moeratly hot closure
1 parent 9d436ea commit ee5d680

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

compiler/src/dotty/tools/dotc/core/Decorators.scala

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -151,18 +151,21 @@ object Decorators {
151151
* exact meaning of "contains" here.
152152
*/
153153
implicit class PhaseListDecorator(val names: List[String]) extends AnyVal {
154-
def containsPhase(phase: Phase): Boolean = phase match {
155-
case phase: MegaPhase => phase.miniPhases.exists(containsPhase)
156-
case _ =>
157-
names exists { name =>
158-
name == "all" || {
159-
val strippedName = name.stripSuffix("+")
160-
val logNextPhase = name != strippedName
161-
phase.phaseName.startsWith(strippedName) ||
162-
(logNextPhase && phase.prev.phaseName.startsWith(strippedName))
163-
}
154+
def containsPhase(phase: Phase): Boolean =
155+
names.nonEmpty && {
156+
phase match {
157+
case phase: MegaPhase => phase.miniPhases.exists(containsPhase)
158+
case _ =>
159+
names exists { name =>
160+
name == "all" || {
161+
val strippedName = name.stripSuffix("+")
162+
val logNextPhase = name != strippedName
163+
phase.phaseName.startsWith(strippedName) ||
164+
(logNextPhase && phase.prev.phaseName.startsWith(strippedName))
165+
}
166+
}
164167
}
165-
}
168+
}
166169
}
167170

168171
implicit class genericDeco[T](val x: T) extends AnyVal {

0 commit comments

Comments
 (0)