on master help sign in
Add unsafeWriteIndex for Array.Foreign
commit7aa0e0db4b1dd041ab2c6d19710cf649f516baa9 authorAdithya Kumar <adithya@composewell.com> dateSun 4 Apr 2021, 22:44 (6 years ago) parent833ad1f
1 file changed+9
src/Streamly/Internal/Data/Array/Foreign/Mut/Type.hs+9
src/Streamly/Internal/Data/Array/Foreign/Mut/Type.hs+9
@@ -56,6 +56,7 @@ module Streamly.Internal.Data.Array.Foreign.Mut.Type
5656 , unsafeIndex
5757
5858 -- * Mutation
59+ , unsafeWriteIndex
5960 , unsafeSnoc
6061 , snoc
6162
@@ -313,6 +314,14 @@ withNewArray count f = do
313314-- snoc
314315-------------------------------------------------------------------------------
315316
317+{-# INLINE unsafeWriteIndex #-}
318+unsafeWriteIndex :: forall a. Storable a => Array a -> Int -> a -> IO (Array a)
319+unsafeWriteIndex arr@Array {..} i x =
320+ withForeignPtr aStart
321+ $ \begin -> do
322+ poke (begin `plusPtr` (i * sizeOf (undefined :: a))) x
323+ return arr
324+
316325-- XXX grow the array when we are beyond bound.
317326--
318327-- Internal routine for when the array is being created. Appends one item at