@@ -92,134 +92,6 @@ import Prelude hiding ( length, null, replicate, reverse, map, read,
9292
9393#include "vector.h"
9494
95- {-
96- type family Immutable (v :: * -> * -> *) :: * -> *
97-
98- -- | Class of mutable vectors parameterised with a primitive state token.
99- --
100- class MBundle.Pointer u a => MVector v a where
101- -- | Length of the mutable vector. This method should not be
102- -- called directly, use 'length' instead.
103- basicLength :: v s a -> Int
104-
105- -- | Yield a part of the mutable vector without copying it. This method
106- -- should not be called directly, use 'unsafeSlice' instead.
107- basicUnsafeSlice :: Int -- ^ starting index
108- -> Int -- ^ length of the slice
109- -> v s a
110- -> v s a
111-
112- -- Check whether two vectors overlap. This method should not be
113- -- called directly, use 'overlaps' instead.
114- basicOverlaps :: v s a -> v s a -> Bool
115-
116- -- | Create a mutable vector of the given length. This method should not be
117- -- called directly, use 'unsafeNew' instead.
118- basicUnsafeNew :: PrimMonad m => Int -> m (v (PrimState m) a)
119-
120- -- | Create a mutable vector of the given length and fill it with an
121- -- initial value. This method should not be called directly, use
122- -- 'replicate' instead.
123- basicUnsafeReplicate :: PrimMonad m => Int -> a -> m (v (PrimState m) a)
124-
125- -- | Yield the element at the given position. This method should not be
126- -- called directly, use 'unsafeRead' instead.
127- basicUnsafeRead :: PrimMonad m => v (PrimState m) a -> Int -> m a
128-
129- -- | Replace the element at the given position. This method should not be
130- -- called directly, use 'unsafeWrite' instead.
131- basicUnsafeWrite :: PrimMonad m => v (PrimState m) a -> Int -> a -> m ()
132-
133- -- | Reset all elements of the vector to some undefined value, clearing all
134- -- references to external objects. This is usually a noop for unboxed
135- -- vectors. This method should not be called directly, use 'clear' instead.
136- basicClear :: PrimMonad m => v (PrimState m) a -> m ()
137-
138- -- | Set all elements of the vector to the given value. This method should
139- -- not be called directly, use 'set' instead.
140- basicSet :: PrimMonad m => v (PrimState m) a -> a -> m ()
141-
142- basicUnsafeCopyPointer :: PrimMonad m => v (PrimState m) a
143- -> Immutable v a
144- -> m ()
145-
146- -- | Copy a vector. The two vectors may not overlap. This method should not
147- -- be called directly, use 'unsafeCopy' instead.
148- basicUnsafeCopy :: PrimMonad m => v (PrimState m) a -- ^ target
149- -> v (PrimState m) a -- ^ source
150- -> m ()
151-
152- -- | Move the contents of a vector. The two vectors may overlap. This method
153- -- should not be called directly, use 'unsafeMove' instead.
154- basicUnsafeMove :: PrimMonad m => v (PrimState m) a -- ^ target
155- -> v (PrimState m) a -- ^ source
156- -> m ()
157-
158- -- | Grow a vector by the given number of elements. This method should not be
159- -- called directly, use 'unsafeGrow' instead.
160- basicUnsafeGrow :: PrimMonad m => v (PrimState m) a -> Int
161- -> m (v (PrimState m) a)
162-
163- {- # INLINE basicUnsafeReplicate #-}
164- basicUnsafeReplicate n x
165- = do
166- v <- basicUnsafeNew n
167- basicSet v x
168- return v
169-
170- {- # INLINE basicClear #-}
171- basicClear _ = return ()
172-
173- {- # INLINE basicSet #-}
174- basicSet !v x
175- | n == 0 = return ()
176- | otherwise = do
177- basicUnsafeWrite v 0 x
178- do_set 1
179- where
180- !n = basicLength v
181-
182- do_set i | 2*i < n = do basicUnsafeCopy (basicUnsafeSlice i i v)
183- (basicUnsafeSlice 0 i v)
184- do_set (2*i)
185- | otherwise = basicUnsafeCopy (basicUnsafeSlice i (n-i) v)
186- (basicUnsafeSlice 0 (n-i) v)
187-
188- {- # INLINE basicUnsafeCopyPointer #-}
189- basicUnsafeCopyPointer !dst !src = do_copy 0 src
190- where
191- do_copy !i p | Just (x,q) <- MBundle.pget p = do
192- basicUnsafeWrite dst i x
193- do_copy (i+1) q
194- | otherwise = return ()
195-
196- {- # INLINE basicUnsafeCopy #-}
197- basicUnsafeCopy !dst !src = do_copy 0
198- where
199- !n = basicLength src
200-
201- do_copy i | i < n = do
202- x <- basicUnsafeRead src i
203- basicUnsafeWrite dst i x
204- do_copy (i+1)
205- | otherwise = return ()
206-
207- {- # INLINE basicUnsafeMove #-}
208- basicUnsafeMove !dst !src
209- | basicOverlaps dst src = do
210- srcCopy <- clone src
211- basicUnsafeCopy dst srcCopy
212- | otherwise = basicUnsafeCopy dst src
213-
214- {- # INLINE basicUnsafeGrow #-}
215- basicUnsafeGrow v by
216- = do
217- v' <- basicUnsafeNew (n+by)
218- basicUnsafeCopy (basicUnsafeSlice 0 n v') v
219- return v'
220- where
221- n = basicLength v
222- -}
22395
22496-- ------------------
22597-- Internal functions
@@ -338,16 +210,6 @@ munstream s = case upperBound (MBundle.size s) of
338210 Just n -> munstreamMax s n
339211 Nothing -> munstreamUnknown s
340212
341- -- FIXME: I can't think of how to prevent GHC from floating out
342- -- unstreamUnknown. That is bad because SpecConstr then generates two
343- -- specialisations: one for when it is called from unstream (it doesn't know
344- -- the shape of the vector) and one for when the vector has grown. To see the
345- -- problem simply compile this:
346- --
347- -- fromList = Data.Vector.Unboxed.unstream . Bundle.fromList
348- --
349- -- I'm not sure this still applies (19/04/2010)
350-
351213munstreamMax :: (PrimMonad m , MVector v a )
352214 => MBundle m u a -> Int -> m (v (PrimState m ) a )
353215{-# INLINE munstreamMax #-}
@@ -396,16 +258,6 @@ vmunstream s = case upperBound (MBundle.size s) of
396258 Just n -> vmunstreamMax s n
397259 Nothing -> vmunstreamUnknown s
398260
399- -- FIXME: I can't think of how to prevent GHC from floating out
400- -- unstreamUnknown. That is bad because SpecConstr then generates two
401- -- specialisations: one for when it is called from unstream (it doesn't know
402- -- the shape of the vector) and one for when the vector has grown. To see the
403- -- problem simply compile this:
404- --
405- -- fromList = Data.Vector.Unboxed.unstream . Bundle.fromList
406- --
407- -- I'm not sure this still applies (19/04/2010)
408-
409261vmunstreamMax :: (PrimMonad m , V. Vector v a )
410262 => MBundle m v a -> Int -> m (V. Mutable v (PrimState m ) a )
411263{-# INLINE vmunstreamMax #-}
0 commit comments