@@ -14,7 +14,7 @@ module Streamly.Internal.Data.Array.Foreign.Mut.Type
1414 Array (..)
1515
1616 -- * Construction
17− , mutableArray
17+ , fromForeignPtrUnsafe
1818 , unsafeWithNewArray
1919 , newArray
2020 , newArrayAligned
@@ -229,13 +229,24 @@ data Array a =
229229 , aBound :: {-# UNPACK #-} !(Ptr a) -- ^ first address beyond allocated memory
230230 }
231231
232−{-# INLINE mutableArray #-}
233−mutableArray ::
232+-- | @fromForeignPtrUnsafe foreignPtr end bound@ creates an 'Array' that starts
233+-- at the memory pointed by the @foreignPtr@, @end@ is the first unused
234+-- address, and @bound@ is the first address beyond the allocated memory.
235+--
236+-- Unsafe: Make sure that foreignPtr <= end <= bound and (end - start) is an
237+-- integral multiple of the element size.
238+--
239+-- /Pre-release/
240+--
241+{-# INLINE fromForeignPtrUnsafe #-}
242+fromForeignPtrUnsafe ::
234243#ifdef DEVBUILD
235244 Storable a =>
236245#endif
237246 ForeignPtr a -> Ptr a -> Ptr a -> Array a
238−mutableArray = Array
247+fromForeignPtrUnsafe fp end bound =
248+ assert (unsafeForeignPtrToPtr fp <= end && end <= bound)
249+ (Array fp end bound)
239250
240251-------------------------------------------------------------------------------
241252-- Construction