on master help sign in
Improve NFData instance
c48ef04Harendra Kumar
benchmark/Streamly/Benchmark/Data/Array.hs+4−7
@@ -22,7 +22,6 @@ import qualified Streamly.Benchmark.Prelude as P
22
22
23#ifdef MEMORY_ARRAY
23#ifdef MEMORY_ARRAY
24import qualified GHC.Exts as GHC
24import qualified GHC.Exts as GHC
25−import Foreign.Storable (Storable(..))
26#endif
25#endif
27
26
28#if !defined(DATA_ARRAY_PRIM) && !defined(DATA_ARRAY_PRIM_PINNED)
27#if !defined(DATA_ARRAY_PRIM) && !defined(DATA_ARRAY_PRIM_PINNED)
@@ -36,8 +35,7 @@ import Control.DeepSeq (deepseq)
36#ifdef MEMORY_ARRAY
35#ifdef MEMORY_ARRAY
37-- Drain a source that generates a pure array
36-- Drain a source that generates a pure array
38{-# INLINE benchPureSrc #-}
37{-# INLINE benchPureSrc #-}
39−benchPureSrc ::
40− (NFData a, Storable a) => String -> (Int -> Ops.Stream a) -> Benchmark
38+benchPureSrc :: String -> (Int -> Ops.Stream a) -> Benchmark
41benchPureSrc name src = benchPure name src id
39benchPureSrc name src = benchPure name src id
42#endif
40#endif
43
41
@@ -49,11 +47,10 @@ benchIO name src f = bench name $ nfIO $
49-- Drain a source that generates an array in the IO monad
47-- Drain a source that generates an array in the IO monad
50{-# INLINE benchIOSrc #-}
48{-# INLINE benchIOSrc #-}
51benchIOSrc ::
49benchIOSrc ::
50+#if !defined(DATA_ARRAY_PRIM) \
52−#if !defined(DATA_ARRAY_PRIM) && !defined(DATA_ARRAY_PRIM_PINNED)
51+ && !defined(DATA_ARRAY_PRIM_PINNED) \
52+ && !defined(MEMORY_ARRAY)
53 NFData a =>
53 NFData a =>
54−#endif
55−#ifdef MEMORY_ARRAY
56− Storable a =>
57#endif
54#endif
58 String -> (Int -> IO (Ops.Stream a)) -> Benchmark
55 String -> (Int -> IO (Ops.Stream a)) -> Benchmark
59benchIOSrc name src = benchIO name src id
56benchIOSrc name src = benchIO name src id
src/Streamly/Internal/Data/Array/Foreign/Mut/Type.hs+8−2
@@ -1144,9 +1144,15 @@ instance (Storable a, Eq a) => Eq (Array a) where
1144 (==) = arrcmp
1144 (==) = arrcmp
1145 -- arr1 == arr2 = runIdentity $ D.eqBy (==) (toStreamD arr1) (toStreamD arr2)
1145 -- arr1 == arr2 = runIdentity $ D.eqBy (==) (toStreamD arr1) (toStreamD arr2)
1146
1146
1147+-------------------------------------------------------------------------------
1148+-- NFData
1149+-------------------------------------------------------------------------------
1150+
1151+-- This is a Storable array, we cannot have unevaluated data in it so this is
1152+-- just a no op.
1147−instance (Storable a, NFData a) => NFData (Array a) where
1153+instance NFData (Array a) where
1148 {-# INLINE rnf #-}
1154 {-# INLINE rnf #-}
1149− rnf = foldl' (\_ x -> rnf x) ()
1155+ rnf Array {} = ()
1150
1156
1151#ifdef DEVBUILD
1157#ifdef DEVBUILD
1152-- Definitions using the Storable constraint from the Array type. These are to
1158-- Definitions using the Storable constraint from the Array type. These are to
src/Streamly/Internal/Data/Array/Foreign/Type.hs+4−2
@@ -612,9 +612,11 @@ instance (Storable a, Eq a) => Eq (Array a) where
612 {-# INLINE (==) #-}
612 {-# INLINE (==) #-}
613 arr1 == arr2 = runIdentity $ D.eqBy (==) (toStreamD arr1) (toStreamD arr2)
613 arr1 == arr2 = runIdentity $ D.eqBy (==) (toStreamD arr1) (toStreamD arr2)
614
614
615+-- Since this is a Storable array we cannot have unevaluated data in it so
616+-- this is just a no op.
615−instance (Storable a, NFData a) => NFData (Array a) where
617+instance NFData (Array a) where
616 {-# INLINE rnf #-}
618 {-# INLINE rnf #-}
617− rnf = foldl' (\_ x -> rnf x) ()
619+ rnf Array {} = ()
618
620
619instance (Storable a, Ord a) => Ord (Array a) where
621instance (Storable a, Ord a) => Ord (Array a) where
620 {-# INLINE compare #-}
622 {-# INLINE compare #-}