File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -31,12 +31,13 @@ import Prelude
3131type role MVector nominal representational
3232
3333-- | Mutable boxed vectors keyed on the monad they live in ('IO' or @'ST' s@).
34- data MVector s a = MVector { _offset :: {-# UNPACK #-} ! Int
34+ data MVector s a = MVector { unsafeOffset :: {-# UNPACK #-} ! Int
3535 -- ^ Offset in underlying array
36- , _size :: {-# UNPACK #-} ! Int
36+ , unsafeSize :: {-# UNPACK #-} ! Int
3737 -- ^ Size of slice
38- , _array :: {-# UNPACK #-} ! (MutableArray s a )
39- -- ^ Underlying array
38+ , unsafeMutableArray :: {-# UNPACK #-} ! (MutableArray s a )
39+ -- ^ Underlying mutable array
40+ }
4041 }
4142
4243
Original file line number Diff line number Diff line change @@ -43,9 +43,13 @@ import Unsafe.Coerce
4343type role MVector nominal nominal
4444
4545-- | Mutable vectors of primitive types.
46- data MVector s a = MVector {- # UNPACK #-} !Int -- ^ offset
47- {- # UNPACK #-} !Int -- ^ length
48- {- # UNPACK #-} !(MutableByteArray s ) -- ^ underlying mutable byte array
46+ data MVector s a = MVector { unsafeOffset :: {-# UNPACK #-} ! Int
47+ -- ^ Offset into the `unsafeMutableByteArray` in number of elements, not bytes
48+ , unsafeSize :: {-# UNPACK #-} ! Int
49+ -- ^ Size of the mutable vector in number of elements, not bytes
50+ , unsafeMutableByteArray :: {-# UNPACK #-} ! (MutableByteArray s )
51+ -- ^ Underlying mutable byte array
52+ }
4953
5054-- | /O(1)/ Unsafely coerce a mutable vector from one element type to another,
5155-- representationally equal type. The operation just changes the type of the
Original file line number Diff line number Diff line change @@ -48,9 +48,13 @@ import Data.Vector.Primitive.Mutable.Unsafe (MVector(..))
4848type role Vector nominal
4949
5050-- | Unboxed vectors of primitive types.
51- data Vector a = Vector {- # UNPACK #-} !Int -- ^ offset
52- {- # UNPACK #-} !Int -- ^ length
53- {- # UNPACK #-} !ByteArray -- ^ underlying byte array
51+ data Vector a = Vector { unsafeOffset :: {-# UNPACK #-} ! Int
52+ -- ^ Offset into `unsafeByteArray` in number of elements, not bytes
53+ , unsafeSize :: {-# UNPACK #-} ! Int
54+ -- ^ Number of elements in number of elements, not bytes
55+ , unsafeByteArray :: {-# UNPACK #-} ! ByteArray
56+ -- ^ Underlying byte array
57+ }
5458
5559type instance G. Mutable Vector = MVector
5660
Original file line number Diff line number Diff line change @@ -58,8 +58,11 @@ import Unsafe.Coerce
5858type role MVector nominal nominal
5959
6060-- | Mutable 'Storable'-based vectors.
61- data MVector s a = MVector {- # UNPACK #-} !Int
62- {- # UNPACK #-} !(ForeignPtr a )
61+ data MVector s a = MVector { unsafeSize :: {-# UNPACK #-} ! Int
62+ -- ^ Number of elements in a mutable vector
63+ , unsafeForeignPtr :: {-# UNPACK #-} ! (ForeignPtr a )
64+ -- ^ Underlying buffer as a `ForeignPtr`, which is allowed to be mutated
65+ }
6366
6467type IOVector = MVector RealWorld
6568type STVector s = MVector s
Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ import Prelude ( Monad(..), return )
2828type role MVector nominal representational
2929
3030-- | Mutable boxed vectors keyed on the monad they live in ('IO' or @'ST' s@).
31- newtype MVector s a = MVector ( MV. MVector s a )
31+ newtype MVector s a = MVector { unsafeLazyMVector :: MV. MVector s a }
3232
3333instance G. MVector MVector a where
3434 {-# INLINE basicLength #-}
Original file line number Diff line number Diff line change @@ -54,7 +54,7 @@ import qualified Data.Traversable as Traversable
5454import qualified GHC.Exts as Exts (IsList (.. ))
5555
5656-- | Strict boxed vectors, supporting efficient slicing.
57- newtype Vector a = Vector ( V. Vector a )
57+ newtype Vector a = Vector { unsafeLazyVector :: V. Vector a }
5858 deriving (Foldable.Foldable , Semigroup , Monoid )
5959
6060-- NOTE: [GND for strict vector]
You can’t perform that action at this time.
0 commit comments