Skip to content

Commit

Permalink
TreeOps: skip 1st stat in case body in NL optimizn
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Sep 30, 2024
1 parent 643084c commit 31c4c07
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,11 @@ object TreeOps {
tree: Tree,
)(implicit ftoks: FormatTokens): Seq[Tree] = tree match {
case SingleArgInBraces(_, fun: Term.FunctionTerm, _) => fun :: Nil
case b: Term.FunctionTerm if isBlockFunction(b) => b.body :: Nil
case t: Term.FunctionTerm if isBlockFunction(t) => t.body :: Nil
case t: Term.EnumeratorsBlock => getEnumStatements(t.enums)
case t: Tree.Block => t.stats
case t: CaseTree if t.body.tokens.nonEmpty => t.body :: Nil
case t @ Tree.Block(s) =>
if (!t.parent.is[CaseTree] || getSingleStatExceptEndMarker(s).isEmpty) s
else s.drop(1)
case _ => Nil
}

Expand Down Expand Up @@ -600,10 +601,13 @@ object TreeOps {
* block contains only a single statement. NB: in FormatWriter, when choosing
* to insert or remove end markers, we avoid such borderline cases.
*/
def getSingleStatExceptEndMarker(s: Seq[Stat]): Option[Stat] = s.headOption
.filter { _ =>
val len2 = s.lengthCompare(2)
len2 < 0 || len2 == 0 && s(1).is[Term.EndMarker]
def getSingleStatExceptEndMarker[A <: Tree](ss: List[A]): Option[A] =
ss match {
case s :: rs if (rs match {
case Nil | (_: Term.EndMarker) :: Nil => true
case _ => false
}) => Some(s)
case _ => None
}

def getSingleStatExceptEndMarker(t: Tree): Option[Tree] = t match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1958,9 +1958,8 @@ val strings = Seq(
s" $bestEPStr",
"Metrics:",
s" $metricHeader: ${bestScore.score}"
) ++ otherMetricHeaders.zip(bestScore.otherScores).map { case (h, s) =>
s" $h: $s"
} ++ outputPath.toSeq.map { p =>
) ++ otherMetricHeaders.zip(bestScore.otherScores)
.map { case (h, s) => s" $h: $s" } ++ outputPath.toSeq.map { p =>
s"The best variant params can be found in $p"
}
<<< 8.6: assignment with short expression
Expand Down

0 comments on commit 31c4c07

Please sign in to comment.