on master help sign in
Add unsafeWriteIndex for Array.Foreign
7aa0e0dAdithya Kumar
src/Streamly/Internal/Data/Array/Foreign/Mut/Type.hs+9
@@ -56,6 +56,7 @@ module Streamly.Internal.Data.Array.Foreign.Mut.Type
56 , unsafeIndex
56 , unsafeIndex
57
57
58 -- * Mutation
58 -- * Mutation
59+ , unsafeWriteIndex
59 , unsafeSnoc
60 , unsafeSnoc
60 , snoc
61 , snoc
61
62
@@ -313,6 +314,14 @@ withNewArray count f = do
313-- snoc
314-- snoc
314-------------------------------------------------------------------------------
315-------------------------------------------------------------------------------
315
316
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+
316-- XXX grow the array when we are beyond bound.
325-- XXX grow the array when we are beyond bound.
317--
326--
318-- Internal routine for when the array is being created. Appends one item at
327-- Internal routine for when the array is being created. Appends one item at