From aed3800eee7c5b1c09616d1f747a030ba4a02ce9 Mon Sep 17 00:00:00 2001 From: Albert Meltzer <7529386+kitbellew@users.noreply.github.com> Date: Thu, 24 Mar 2022 07:55:31 -0700 Subject: [PATCH] BestFirstSearch: cosmetic, extract enqueue method --- .../org/scalafmt/internal/BestFirstSearch.scala | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/BestFirstSearch.scala b/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/BestFirstSearch.scala index 5a5f685cd0..57f750ebed 100644 --- a/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/BestFirstSearch.scala +++ b/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/BestFirstSearch.scala @@ -118,6 +118,10 @@ private class BestFirstSearch private ( } Q += start + def enqueue(state: State) = { + Q.enqueue(state) + } + // TODO(olafur) this while loop is waaaaaaaaaaaaay tooo big. while (true) { val curr = Q.dequeue() @@ -161,8 +165,7 @@ private class BestFirstSearch private ( else shouldRecurseOnBlock(splitToken, stop) if (blockClose.nonEmpty) blockClose.foreach { end => - shortestPathMemo(curr, end, depth + 1, maxCost) - .foreach(Q.enqueue(_)) + shortestPathMemo(curr, end, depth + 1, maxCost).foreach(enqueue) } else if ( escapeInPathologicalCases && @@ -202,24 +205,24 @@ private class BestFirstSearch private ( val overflow = furtherState.appliedPenalty > nextNextState.appliedPenalty if (overflow) - Q.enqueue(nextNextState) + enqueue(nextNextState) else { optimalNotFound = false - Q.enqueue(furtherState) + enqueue(furtherState) } } else if ( !killOnFail && nextState.cost - curr.cost <= maxCost ) { // TODO(olafur) DRY. This solution can still be optimal. - Q.enqueue(nextState) + enqueue(nextState) } else { // else kill branch if (updateBest) best.remove(curr.depth) } case _ if optimalNotFound && nextState.cost - curr.cost <= maxCost => - Q.enqueue(nextState) + enqueue(nextState) case _ => // Kill branch. if (updateBest) best.remove(curr.depth) }