From 55469a6833ca4ccbae648be1206a8605e89dcdac Mon Sep 17 00:00:00 2001 From: Simon Jakobi Date: Tue, 19 Nov 2019 23:50:50 +0100 Subject: [PATCH] Speed up changesUponFlattening 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 #99. --- prettyprinter/src/Data/Text/Prettyprint/Doc/Internal.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prettyprinter/src/Data/Text/Prettyprint/Doc/Internal.hs b/prettyprinter/src/Data/Text/Prettyprint/Doc/Internal.hs index f3910f1f..1072ea4f 100755 --- a/prettyprinter/src/Data/Text/Prettyprint/Doc/Internal.hs +++ b/prettyprinter/src/Data/Text/Prettyprint/Doc/Internal.hs @@ -551,7 +551,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)