diff --git a/vector/src/Data/Vector/Storable/Unsafe.hs b/vector/src/Data/Vector/Storable/Unsafe.hs index 2d6f9224..dae9d34e 100644 --- a/vector/src/Data/Vector/Storable/Unsafe.hs +++ b/vector/src/Data/Vector/Storable/Unsafe.hs @@ -39,7 +39,7 @@ import Control.Monad.Primitive import Prelude ( Eq, Ord, Monoid, Read, Show, Ordering(..), Int, IO, Num(..) , compare, mempty, mappend, mconcat, showsPrec, return, seq, undefined, div - , (<), (<=), (>), (>=), (==), (/=), (.), ($) ) + , (<), (<=), (>), (>=), (==), (/=), (.), ($), ($!)) import Data.Data ( Data(..) ) import Text.Read ( Read(..), readListPrecDefault ) @@ -123,7 +123,7 @@ instance Storable a => G.Vector Vector a where {-# INLINE basicUnsafeIndexM #-} basicUnsafeIndexM (UnsafeVector _ fp) i = return - . unsafeInlineIO + $! unsafeInlineIO $ unsafeWithForeignPtr fp $ \p -> peekElemOff p i diff --git a/vector/tests-inspect/Inspect/Alloc.hs b/vector/tests-inspect/Inspect/Alloc.hs index f3bcb1ee..94104e3d 100644 --- a/vector/tests-inspect/Inspect/Alloc.hs +++ b/vector/tests-inspect/Inspect/Alloc.hs @@ -28,7 +28,9 @@ import System.Mem import Test.Alloc import Test.Ignore -import qualified Data.Vector.Unboxed as VU +import qualified Data.Vector.Unboxed as VU +import qualified Data.Vector.Storable as VS +import qualified Data.Vector.Strict as VV import Inspect.Fusion @@ -160,6 +162,11 @@ tests = testGroup "allocations" [ allocWHNF "test_concat" test_concat listVectorI ] ] + , testGroup "indexing" + [ allocWHNF "== storable" (uncurry (==)) (vectorS,vectorS) + , allocWHNF "== unboxed" (uncurry (==)) (vectorI,vectorI) + , allocWHNF "== boxed" (uncurry (==)) (vectorV,vectorV) + ] ] allocWHNF :: String -> (a -> b) -> a -> TestTree @@ -194,6 +201,14 @@ vectorI :: VU.Vector Int {-# NOINLINE vectorI #-} vectorI = VU.generate size fromIntegral +vectorS :: VS.Vector Int +{-# NOINLINE vectorS #-} +vectorS = VS.generate size fromIntegral + +vectorV :: VV.Vector Int +{-# NOINLINE vectorV #-} +vectorV = VV.generate size fromIntegral + vectorIdx :: VU.Vector (Int,Int) {-# NOINLINE vectorIdx #-} vectorIdx = VU.map (\i -> (i`div`3, i)) vectorI