From 7e32f2edefe8ad397595ec3c6f71bfee28379648 Mon Sep 17 00:00:00 2001 From: Albert Meltzer <7529386+kitbellew@users.noreply.github.com> Date: Sat, 4 May 2024 08:22:14 -0700 Subject: [PATCH] BestFirstSearch: minor optimization with HashMap --- .../src/main/scala/org/scalafmt/internal/BestFirstSearch.scala | 3 +-- 1 file changed, 1 insertion(+), 2 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 5b7c46474b..58f35701e9 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 @@ -166,8 +166,7 @@ private class BestFirstSearch private ( actualSplit.foreach { split => val nextState = curr.next(split, allAltAreNL) val updateBest = !keepSlowStates && depth == 0 && split.isNL && - !best.contains(curr.depth) - if (updateBest) best.update(curr.depth, nextState) + best.getOrElseUpdate(curr.depth, nextState).eq(nextState) style.runner.event(Enqueue(split)) split.optimalAt match { case Some(OptimalToken(token, killOnFail))