summaryrefslogtreecommitdiff
path: root/libraries
diff options
context:
space:
mode:
authorGregory <greg7mdp@gmail.com>2017-04-17 11:24:31 -0400
committerBen Gamari <ben@smart-cactus.org>2017-04-17 20:34:40 -0400
commit3d3975f2f4caf3af76a7ea27d2882ddaee7db3c9 (patch)
tree5b98f23eb14d259364c03b17639ff94bc468dcc1 /libraries
parentab2dcb1c474d918efdc875f3cca7ef5b6ebdce1a (diff)
downloadhaskell-3d3975f2f4caf3af76a7ea27d2882ddaee7db3c9.tar.gz
Fix space leak in sortBy
This makes yields a small improvement in sort performance: around 3.5% in runtime on random Ints. Reviewers: austin, hvr, mpickering Subscribers: siddhanathan, rwbarton, thomie Differential Revision: https://phabricator.haskell.org/D3454
Diffstat (limited to 'libraries')
-rw-r--r--libraries/base/Data/OldList.hs9
1 files changed, 6 insertions, 3 deletions
diff --git a/libraries/base/Data/OldList.hs b/libraries/base/Data/OldList.hs
index 428d3bded9..ec937e729b 100644
--- a/libraries/base/Data/OldList.hs
+++ b/libraries/base/Data/OldList.hs
@@ -1,5 +1,6 @@
{-# LANGUAGE Trustworthy #-}
-{-# LANGUAGE CPP, NoImplicitPrelude, ScopedTypeVariables, MagicHash #-}
+{-# LANGUAGE CPP, NoImplicitPrelude, ScopedTypeVariables,
+ MagicHash, BangPatterns #-}
-----------------------------------------------------------------------------
-- |
@@ -854,12 +855,14 @@ sortBy cmp = mergeAll . sequences
ascending a as (b:bs)
| a `cmp` b /= GT = ascending b (\ys -> as (a:ys)) bs
- ascending a as bs = as [a]: sequences bs
+ ascending a as bs = let !x = as [a]
+ in x : sequences bs
mergeAll [x] = x
mergeAll xs = mergeAll (mergePairs xs)
- mergePairs (a:b:xs) = merge a b: mergePairs xs
+ mergePairs (a:b:xs) = let !x = merge a b
+ in x : mergePairs xs
mergePairs xs = xs
merge as@(a:as') bs@(b:bs')