Skip to content

Commit 313568c

Browse files
authored
Merge pull request #576 from haskell/indexing-storable
Make basicUnsafeIndexM strict in element for Storable
2 parents 65f4b3c + 9038a5a commit 313568c

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

‎vector/src/Data/Vector/Storable/Unsafe.hs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import Control.Monad.Primitive
3939
import Prelude
4040
( Eq, Ord, Monoid, Read, Show, Ordering(..), Int, IO, Num(..)
4141
, compare, mempty, mappend, mconcat, showsPrec, return, seq, undefined, div
42-
, (<), (<=), (>), (>=), (==), (/=), (.), ($) )
42+
, (<), (<=), (>), (>=), (==), (/=), (.), ($), ($!))
4343

4444
import Data.Data ( Data(..) )
4545
import Text.Read ( Read(..), readListPrecDefault )
@@ -123,7 +123,7 @@ instance Storable a => G.Vector Vector a where
123123
{-# INLINE basicUnsafeIndexM #-}
124124
basicUnsafeIndexM (UnsafeVector _ fp) i
125125
= return
126-
. unsafeInlineIO
126+
$! unsafeInlineIO
127127
$ unsafeWithForeignPtr fp $ \p ->
128128
peekElemOff p i
129129

‎vector/tests-inspect/Inspect/Alloc.hs‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ import System.Mem
2828
import Test.Alloc
2929
import Test.Ignore
3030

31-
import qualified Data.Vector.Unboxed as VU
31+
import qualified Data.Vector.Unboxed as VU
32+
import qualified Data.Vector.Storable as VS
33+
import qualified Data.Vector.Strict as VV
3234
import Inspect.Fusion
3335

3436

@@ -160,6 +162,11 @@ tests = testGroup "allocations"
160162
[ allocWHNF "test_concat" test_concat listVectorI
161163
]
162164
]
165+
, testGroup "indexing"
166+
[ allocWHNF "== storable" (uncurry (==)) (vectorS,vectorS)
167+
, allocWHNF "== unboxed" (uncurry (==)) (vectorI,vectorI)
168+
, allocWHNF "== boxed" (uncurry (==)) (vectorV,vectorV)
169+
]
163170
]
164171

165172
allocWHNF :: String -> (a -> b) -> a -> TestTree
@@ -194,6 +201,14 @@ vectorI :: VU.Vector Int
194201
{-# NOINLINE vectorI #-}
195202
vectorI = VU.generate size fromIntegral
196203

204+
vectorS :: VS.Vector Int
205+
{-# NOINLINE vectorS #-}
206+
vectorS = VS.generate size fromIntegral
207+
208+
vectorV :: VV.Vector Int
209+
{-# NOINLINE vectorV #-}
210+
vectorV = VV.generate size fromIntegral
211+
197212
vectorIdx :: VU.Vector (Int,Int)
198213
{-# NOINLINE vectorIdx #-}
199214
vectorIdx = VU.map (\i -> (i`div`3, i)) vectorI

0 commit comments

Comments
 (0)