Skip to content

Commit

Permalink
Speed up changesUponFlattening
Browse files Browse the repository at this point in the history
Since the first Union alternative was produced by the previous
call to to changesUponFlattening, it seems unnecessary to
scrutinize it again.

This speeds up some prettyprinter-heavy applications in dhall
by 20 to 42%.

This assumes some kind of idempotence in changesUponFlattening.

Fixes quchen#99.
  • Loading branch information
sjakobi committed Nov 19, 2019
1 parent 7da3b1d commit 0ee3916
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion prettyprinter/src/Data/Text/Prettyprint/Doc/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ changesUponFlattening :: Doc ann -> Maybe (Doc ann)
changesUponFlattening = \doc -> case doc of
FlatAlt _ y -> Just (flatten y)
Line -> Just Fail
Union x _ -> changesUponFlattening x <|> Just x
Union x _ -> Just x
Nest i x -> fmap (Nest i) (changesUponFlattening x)
Annotated ann x -> fmap (Annotated ann) (changesUponFlattening x)

Expand Down

0 comments on commit 0ee3916

Please sign in to comment.