[commit: packages/containers] develop-0.6, develop-0.6-questionable, master, zip-devel: Move foldlStrict (defined 4 times) to Data.StrictFold. (27a5da9)

git at git.haskell.org git at git.haskell.org
Fri Dec 18 22:08:14 UTC 2015


Repository : ssh://git@git.haskell.org/containers

On branches: develop-0.6,develop-0.6-questionable,master,zip-devel
Link       : http://git.haskell.org/packages/containers.git/commitdiff/27a5da9e0a99b2df2cfb267eed2dae8167c746a2

>---------------------------------------------------------------

commit 27a5da9e0a99b2df2cfb267eed2dae8167c746a2
Author: Milan Straka <fox at ucw.cz>
Date:   Sun Oct 12 11:06:53 2014 +0200

    Move foldlStrict (defined 4 times) to Data.StrictFold.
    
    The foldlStrict is Data.List.foldl' which is always inlined, which
    allows more optimizations. Also, foldl' is not Haskell 98, although
    it is Haskell 2010.


>---------------------------------------------------------------

27a5da9e0a99b2df2cfb267eed2dae8167c746a2
 Data/IntMap/Base.hs   |  9 +--------
 Data/IntMap/Strict.hs |  1 +
 Data/IntSet/Base.hs   |  7 +------
 Data/Map/Base.hs      |  9 +--------
 Data/Map/Strict.hs    |  2 ++
 Data/Set/Base.hs      |  7 +------
 Data/StrictFold.hs    | 16 ++++++++++++++++
 containers.cabal      |  1 +
 8 files changed, 24 insertions(+), 28 deletions(-)

diff --git a/Data/IntMap/Base.hs b/Data/IntMap/Base.hs
index 75b3ae9..8d04bfa 100644
--- a/Data/IntMap/Base.hs
+++ b/Data/IntMap/Base.hs
@@ -211,7 +211,6 @@ module Data.IntMap.Base (
     , shorter
     , branchMask
     , highestBitMask
-    , foldlStrict
     ) where
 
 import Control.Applicative (Applicative(pure, (<*>)), (<$>))
@@ -229,6 +228,7 @@ import Prelude hiding (lookup, map, filter, foldr, foldl, null)
 import Data.BitUtil
 import Data.IntSet.Base (Key)
 import qualified Data.IntSet.Base as IntSet
+import Data.StrictFold
 import Data.StrictPair
 
 #if __GLASGOW_HASKELL__
@@ -2085,13 +2085,6 @@ branchMask p1 p2
   Utilities
 --------------------------------------------------------------------}
 
-foldlStrict :: (a -> b -> a) -> a -> [b] -> a
-foldlStrict f = go
-  where
-    go z []     = z
-    go z (x:xs) = let z' = f z x in z' `seq` go z' xs
-{-# INLINE foldlStrict #-}
-
 -- | /O(1)/.  Decompose a map into pieces based on the structure of the underlying
 -- tree.  This function is useful for consuming a map in parallel.
 --
diff --git a/Data/IntMap/Strict.hs b/Data/IntMap/Strict.hs
index 2ca3707..f19682e 100644
--- a/Data/IntMap/Strict.hs
+++ b/Data/IntMap/Strict.hs
@@ -258,6 +258,7 @@ import Data.IntMap.Base hiding
 
 import Data.BitUtil
 import qualified Data.IntSet.Base as IntSet
+import Data.StrictFold
 import Data.StrictPair
 
 -- $strictness
diff --git a/Data/IntSet/Base.hs b/Data/IntSet/Base.hs
index 0063c3f..c843d46 100644
--- a/Data/IntSet/Base.hs
+++ b/Data/IntSet/Base.hs
@@ -192,6 +192,7 @@ import Data.Word (Word)
 import Prelude hiding (filter, foldr, foldl, null, map)
 
 import Data.BitUtil
+import Data.StrictFold
 import Data.StrictPair
 
 #if __GLASGOW_HASKELL__
@@ -1491,12 +1492,6 @@ bitcount a0 x0 = go a0 x0
 {--------------------------------------------------------------------
   Utilities
 --------------------------------------------------------------------}
-foldlStrict :: (a -> b -> a) -> a -> [b] -> a
-foldlStrict f = go
-  where
-    go z []     = z
-    go z (x:xs) = let z' = f z x in z' `seq` go z' xs
-{-# INLINE foldlStrict #-}
 
 -- | /O(1)/.  Decompose a set into pieces based on the structure of the underlying
 -- tree.  This function is useful for consuming a set in parallel.
diff --git a/Data/Map/Base.hs b/Data/Map/Base.hs
index db9549f..650e003 100644
--- a/Data/Map/Base.hs
+++ b/Data/Map/Base.hs
@@ -262,7 +262,6 @@ module Data.Map.Base (
     , glue
     , trim
     , trimLookupLo
-    , foldlStrict
     , MaybeS(..)
     , filterGt
     , filterLt
@@ -279,6 +278,7 @@ import Data.Typeable
 import Prelude hiding (lookup, map, filter, foldr, foldl, null)
 
 import qualified Data.Set.Base as Set
+import Data.StrictFold
 
 #if __GLASGOW_HASKELL__
 import GHC.Exts ( build )
@@ -2826,13 +2826,6 @@ validsize t
 {--------------------------------------------------------------------
   Utilities
 --------------------------------------------------------------------}
-foldlStrict :: (a -> b -> a) -> a -> [b] -> a
-foldlStrict f = go
-  where
-    go z []     = z
-    go z (x:xs) = let z' = f z x in z' `seq` go z' xs
-{-# INLINE foldlStrict #-}
-
 
 -- | /O(1)/.  Decompose a map into pieces based on the structure of the underlying
 -- tree.  This function is useful for consuming a map in parallel.
diff --git a/Data/Map/Strict.hs b/Data/Map/Strict.hs
index 75a29c8..4e0d820 100644
--- a/Data/Map/Strict.hs
+++ b/Data/Map/Strict.hs
@@ -269,7 +269,9 @@ import Data.Map.Base hiding
     , updateMaxWithKey
     )
 import qualified Data.Set.Base as Set
+import Data.StrictFold
 import Data.StrictPair
+
 import Data.Bits (shiftL, shiftR)
 
 -- Use macros to define strictness of functions.  STRICT_x_OF_y
diff --git a/Data/Set/Base.hs b/Data/Set/Base.hs
index ffcdfd0..3a2c938 100644
--- a/Data/Set/Base.hs
+++ b/Data/Set/Base.hs
@@ -194,6 +194,7 @@ import qualified Data.Foldable as Foldable
 import Data.Typeable
 import Control.DeepSeq (NFData(rnf))
 
+import Data.StrictFold
 import Data.StrictPair
 
 #if __GLASGOW_HASKELL__
@@ -1416,12 +1417,6 @@ bin x l r
 {--------------------------------------------------------------------
   Utilities
 --------------------------------------------------------------------}
-foldlStrict :: (a -> b -> a) -> a -> [b] -> a
-foldlStrict f = go
-  where
-    go z []     = z
-    go z (x:xs) = let z' = f z x in z' `seq` go z' xs
-{-# INLINE foldlStrict #-}
 
 -- | /O(1)/.  Decompose a set into pieces based on the structure of the underlying
 -- tree.  This function is useful for consuming a set in parallel.
diff --git a/Data/StrictFold.hs b/Data/StrictFold.hs
new file mode 100644
index 0000000..9c90a66
--- /dev/null
+++ b/Data/StrictFold.hs
@@ -0,0 +1,16 @@
+{-# LANGUAGE CPP #-}
+#if !defined(TESTING) && __GLASGOW_HASKELL__ >= 703
+{-# LANGUAGE Trustworthy #-}
+#endif
+module Data.StrictFold (foldlStrict) where
+
+-- | Same as regular 'Data.List.foldl'', but marked INLINE so that it is always
+-- inlined. This allows further optimization of the call to f, which can be
+-- optimized/specialised/inlined.
+
+foldlStrict :: (a -> b -> a) -> a -> [b] -> a
+foldlStrict f = go
+  where
+    go z []     = z
+    go z (x:xs) = let z' = f z x in z' `seq` go z' xs
+{-# INLINE foldlStrict #-}
diff --git a/containers.cabal b/containers.cabal
index 209589b..a952a77 100644
--- a/containers.cabal
+++ b/containers.cabal
@@ -57,6 +57,7 @@ Library
         Data.IntSet.Base
         Data.Map.Base
         Data.Set.Base
+        Data.StrictFold
         Data.StrictPair
 
     include-dirs: include



More information about the ghc-commits mailing list