From c0348865ff8b9100a8ec54be03e375c3dddc8900 Mon Sep 17 00:00:00 2001 From: Ben Gamari Date: Tue, 12 Oct 2021 20:46:32 -0400 Subject: compiler: Eliminate two uses of foldr in favor of foldl' These two uses constructed maps, which is a case where foldl' is generally more efficient since we avoid constructing an intermediate O(n)-depth stack. --- compiler/GHC/Cmm/DebugBlock.hs | 2 +- compiler/GHC/Cmm/Sink.hs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'compiler/GHC/Cmm') diff --git a/compiler/GHC/Cmm/DebugBlock.hs b/compiler/GHC/Cmm/DebugBlock.hs index b4528ae301..977ab271f7 100644 --- a/compiler/GHC/Cmm/DebugBlock.hs +++ b/compiler/GHC/Cmm/DebugBlock.hs @@ -121,7 +121,7 @@ cmmDebugGen modLoc decls = map (blocksForScope Nothing) topScopes | otherwise = panic "findP impossible" #endif - scopeMap = foldr (uncurry insertMulti) Map.empty childScopes + scopeMap = foldl' (\acc (key, scope) -> insertMulti key scope acc) Map.empty childScopes -- This allows us to recover ticks that we lost by flattening -- the graph. Basically, if the parent is A but the child is diff --git a/compiler/GHC/Cmm/Sink.hs b/compiler/GHC/Cmm/Sink.hs index 84f9317f21..68b20fd307 100644 --- a/compiler/GHC/Cmm/Sink.hs +++ b/compiler/GHC/Cmm/Sink.hs @@ -268,7 +268,7 @@ findJoinPoints blocks = mapFilter (>1) succ_counts all_succs = concatMap successors blocks succ_counts :: LabelMap Int - succ_counts = foldr (\l -> mapInsertWith (+) l 1) mapEmpty all_succs + succ_counts = foldl' (\acc l -> mapInsertWith (+) l 1 acc) mapEmpty all_succs -- -- filter the list of assignments to remove any assignments that -- cgit v1.2.1