summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Data/Packed/Internal/Vector.hs15
1 files changed, 12 insertions, 3 deletions
diff --git a/lib/Data/Packed/Internal/Vector.hs b/lib/Data/Packed/Internal/Vector.hs
index 772aafd..7d6e3d5 100644
--- a/lib/Data/Packed/Internal/Vector.hs
+++ b/lib/Data/Packed/Internal/Vector.hs
@@ -21,9 +21,12 @@ import Foreign
21import Complex 21import Complex
22import Control.Monad(when) 22import Control.Monad(when)
23 23
24import GHC.Base
25import GHC.IOBase
26
24-- | A one-dimensional array of objects stored in a contiguous memory block. 27-- | A one-dimensional array of objects stored in a contiguous memory block.
25data Vector t = V { dim :: Int -- ^ number of elements 28data Vector t = V { dim :: {-# UNPACK #-} !Int -- ^ number of elements
26 , fptr :: ForeignPtr t -- ^ foreign pointer to the memory block 29 , fptr :: {-# UNPACK #-}!(ForeignPtr t) -- ^ foreign pointer to the memory block
27 } 30 }
28 31
29vec = withVector 32vec = withVector
@@ -53,7 +56,12 @@ fromList l = unsafePerformIO $ do
53 app1 f vec v "fromList" 56 app1 f vec v "fromList"
54 return v 57 return v
55 58
56safeRead v = unsafePerformIO . withForeignPtr (fptr v) 59safeRead v = inlinePerformIO . withForeignPtr (fptr v)
60{-# INLINE safeRead #-}
61
62inlinePerformIO :: IO a -> a
63inlinePerformIO (IO m) = case m realWorld# of (# _, r #) -> r
64{-# INLINE inlinePerformIO #-}
57 65
58{- | extracts the Vector elements to a list 66{- | extracts the Vector elements to a list
59 67
@@ -77,6 +85,7 @@ at' v n = safeRead v $ flip peekElemOff n
77at :: Storable a => Vector a -> Int -> a 85at :: Storable a => Vector a -> Int -> a
78at v n | n >= 0 && n < dim v = at' v n 86at v n | n >= 0 && n < dim v = at' v n
79 | otherwise = error "vector index out of range" 87 | otherwise = error "vector index out of range"
88{-# INLINE at #-}
80 89
81{- | takes a number of consecutive elements from a Vector 90{- | takes a number of consecutive elements from a Vector
82 91