@@ -125,10 +125,10 @@ module Streamly.Internal.Memory.Array
125125
126126 -- * Casting
127127 , cast
128− , castWord8
129128 , unsafeCast
130− , withPtr
131− , withCString
129+ , asPtr
130+ , asByteArray
131+ , asCString
132132
133133 -- * Folding Arrays
134134 , streamFold
@@ -521,8 +521,8 @@ unsafeCast (Array start end) = Array (castForeignPtr start) (castPtr end)
521521--
522522-- /Internal/
523523--
524−castWord8 :: Array a -> Array Word8
525−castWord8 = unsafeCast
524+asByteArray :: Array a -> Array Word8
525+asByteArray = unsafeCast
526526
527527-- | Cast an array having elements of type @a@ into an array having elements of
528528-- type @b@. The length of the array should be a multiple of the size of the
@@ -538,25 +538,27 @@ cast arr =
538538 then Nothing
539539 else Just $ unsafeCast arr
540540
541−-- | Use the array as @Ptr a@.
541+-- | Use an @Array a@ as @Ptr b@.
542542--
543543-- /Unsafe/
544544--
545545-- /Internal/
546546--
547−withPtr :: Array a -> (Ptr b -> IO c) -> IO c
548−withPtr Array{..} act = do
547+asPtr :: Array a -> (Ptr b -> IO c) -> IO c
548+asPtr Array{..} act = do
549549 withForeignPtr aStart $ \ptr -> act (castPtr ptr)
550550
551−-- | Convert the array into a null terminated CString Ptr.
551+-- | Convert an array of any type into a null terminated CString Ptr.
552552--
553553-- /Unsafe/
554554--
555+-- /O(n) Time: (creates a copy of the array)/
556+--
555557-- /Internal/
556558--
557−withCString :: Array a -> (CString -> IO b) -> IO b
558−withCString arr act = do
559− let Array{..} = castWord8 arr <> A.fromList [0]
559+asCString :: Array a -> (CString -> IO b) -> IO b
560+asCString arr act = do
561+ let Array{..} = asByteArray arr <> A.fromList [0]
560562 withForeignPtr aStart $ \ptr -> act (castPtr ptr)
561563
562564-------------------------------------------------------------------------------