From ded11b5ccb7a9761d9afe29b076eb120ca5b87c2 Mon Sep 17 00:00:00 2001 From: Simon Jakobi Date: Mon, 27 Jan 2020 22:24:28 +0100 Subject: [PATCH] group: Split top-level flatAlt This results in a significant speedup in the usual dhall benchmark. Includes #123. Closes #115. --- .../src/Data/Text/Prettyprint/Doc/Internal.hs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/prettyprinter/src/Data/Text/Prettyprint/Doc/Internal.hs b/prettyprinter/src/Data/Text/Prettyprint/Doc/Internal.hs index 843c6267..46568e44 100755 --- a/prettyprinter/src/Data/Text/Prettyprint/Doc/Internal.hs +++ b/prettyprinter/src/Data/Text/Prettyprint/Doc/Internal.hs @@ -519,10 +519,16 @@ hardline = Line -- use of it. group :: Doc ann -> Doc ann -- See note [Group: special flattening] -group x = case changesUponFlattening x of - Flattened x' -> Union x' x - AlreadyFlat -> x - NeverFlat -> x +group x = case x of + Union{} -> x + FlatAlt a b -> case changesUponFlattening b of + Flattened b' -> Union b' a + AlreadyFlat -> Union b a + NeverFlat -> a + _ -> case changesUponFlattening x of + Flattened x' -> Union x' x + AlreadyFlat -> x + NeverFlat -> x -- Note [Group: special flattening] --