summaryrefslogtreecommitdiff
path: root/compiler/utils/OrdList.hs
diff options
context:
space:
mode:
authorklebinger.andreas@gmx.at <klebinger.andreas@gmx.at>2018-06-02 21:18:19 -0400
committerBen Gamari <ben@smart-cactus.org>2018-06-02 23:21:00 -0400
commit18cb4f5e1b88aef7770446a354bfcc1e0a075e89 (patch)
tree67784d663a44400b418d35f5ac5a38f8f39acef9 /compiler/utils/OrdList.hs
parentac91d07399207f4e22467bea3577cafd27a937d7 (diff)
downloadhaskell-18cb4f5e1b88aef7770446a354bfcc1e0a075e89.tar.gz
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
Diffstat (limited to 'compiler/utils/OrdList.hs')
-rw-r--r--compiler/utils/OrdList.hs1
1 files changed, 1 insertions, 0 deletions
diff --git a/compiler/utils/OrdList.hs b/compiler/utils/OrdList.hs
index 081210a534..a5739764d4 100644
--- a/compiler/utils/OrdList.hs
+++ b/compiler/utils/OrdList.hs
@@ -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