Skip to content

Commit e7c1e74

Browse files
committed
Fix #642 Bad performance/memory leak for long list literals
A one-character fix that speeds up the formatting of long literals and drastically reduces memory usage. A very simple example is ```elm module Small exposing (x) x = [ 1, 2, 3 , 4] ``` But with a list literal of many thousands of elements. The newline forces all elements to get their own line. This is implemented as a fold, but in practice this would often perform ``` longList ++ shortList ``` By reversing the fold (from `foldl` to `foldr`) that turns into ``` shortList ++ longList ``` Which requires less traversals and memory.
1 parent 1fa616f commit e7c1e74

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/Box.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ stack1 children =
119119
[first] ->
120120
first
121121
boxes ->
122-
foldl1 stack' boxes
122+
foldr1 stack' boxes
123123

124124

125125
mapLines :: (Line -> Line) -> Box -> Box

0 commit comments

Comments
 (0)