Skip to content

Commit 51ec1d1

Browse files
authored
group: Split top-level FlatAlt, preserve top-level Union (#140)
This results in a significant speedup in the usual dhall benchmark. Closes #115.
1 parent 0c32982 commit 51ec1d1

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

prettyprinter/src/Data/Text/Prettyprint/Doc/Internal.hs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -519,10 +519,16 @@ hardline = Line
519519
-- use of it.
520520
group :: Doc ann -> Doc ann
521521
-- See note [Group: special flattening]
522-
group x = case changesUponFlattening x of
523-
Flattened x' -> Union x' x
524-
AlreadyFlat -> x
525-
NeverFlat -> x
522+
group x = case x of
523+
Union{} -> x
524+
FlatAlt a b -> case changesUponFlattening b of
525+
Flattened b' -> Union b' a
526+
AlreadyFlat -> Union b a
527+
NeverFlat -> a
528+
_ -> case changesUponFlattening x of
529+
Flattened x' -> Union x' x
530+
AlreadyFlat -> x
531+
NeverFlat -> x
526532

527533
-- Note [Group: special flattening]
528534
--

0 commit comments

Comments
 (0)