Skip to content
Snippets Groups Projects
Commit 18cb4f5e authored by Andreas Klebinger's avatar Andreas Klebinger Committed by Ben Gamari
Browse files

Check for singletons when creating Bag/OrdList from a list.

This gives us `One x` instead of `Many (x : [])` reducing overhead.
For compiling spectral/simple with -O0 difference was ~ -0.05%
allocations.

The only drawback is that something like toOL (x:panic "") will now
panic.  But that seems like a reasonable tradeoff.

Test Plan: ci, looking at +RTS -s

Reviewers: bgamari, jmct

Reviewed By: bgamari

Subscribers: jmct, rwbarton, thomie, carter

Differential Revision: https://phabricator.haskell.org/D4770
parent ac91d073
No related branches found
No related tags found
No related merge requests found
......@@ -328,6 +328,7 @@ mapAccumBagLM f s (ListBag xs) = do { (s', xs') <- mapAccumLM f s xs
listToBag :: [a] -> Bag a
listToBag [] = EmptyBag
listToBag [x] = UnitBag x
listToBag vs = ListBag vs
bagToList :: Bag a -> [a]
......
......@@ -122,4 +122,5 @@ foldlOL k z (Many xs) = foldl k z xs
toOL :: [a] -> OrdList a
toOL [] = None
toOL [x] = One x
toOL xs = Many xs
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment