diff --git a/benchmark/Streamly/Benchmark/Unicode/Stream.hs b/benchmark/Streamly/Benchmark/Unicode/Stream.hs index 12528c9516..0c99d253bb 100644 --- a/benchmark/Streamly/Benchmark/Unicode/Stream.hs +++ b/benchmark/Streamly/Benchmark/Unicode/Stream.hs @@ -264,10 +264,10 @@ _copyStreamUtf8' inh outh = copyStreamUtf16 :: Handle -> Handle -> IO () copyStreamUtf16 inh outh = Stream.fold (Handle.writeChunks outh) - $ fmap Array.castUnsafe $ Array.chunksOf (arrayPayloadSize (16 * 1024)) + $ fmap Array.unsafeCast $ Array.chunksOf (arrayPayloadSize (16 * 1024)) $ Unicode.encodeUtf16le' $ Unicode.decodeUtf16le - $ Array.concat $ fmap Array.castUnsafe $ Unicode.mkEvenW8Chunks + $ Array.concat $ fmap Array.unsafeCast $ Unicode.mkEvenW8Chunks $ Handle.readChunks inh #ifdef INSPECTION diff --git a/core/src/Streamly/Internal/Data/Array.hs b/core/src/Streamly/Internal/Data/Array.hs index d895b4be6c..45a98b7d91 100644 --- a/core/src/Streamly/Internal/Data/Array.hs +++ b/core/src/Streamly/Internal/Data/Array.hs @@ -49,11 +49,11 @@ module Streamly.Internal.Data.Array -- * Casting , cast , asBytes - , castUnsafe + , unsafeCast , asCStringUnsafe -- * Subarrays - , getSliceUnsafe + , unsafeGetSlice -- , getSlice , sliceIndexerFromLen , slicerFromLen @@ -89,6 +89,8 @@ module Streamly.Internal.Data.Array , deserialize -- * Deprecated + , castUnsafe + , getSliceUnsafe , pinnedSerialize , genSlicesFromLen , getSlicesFromLen @@ -294,19 +296,21 @@ find = Unfold.fold Fold.null . Stream.unfold (indexFinder p) -- /Unsafe/ -- -- /Pre-release/ -{-# INLINE getSliceUnsafe #-} -getSliceUnsafe :: +{-# INLINE unsafeGetSlice #-} +unsafeGetSlice, getSliceUnsafe :: forall a. Unbox a => Int -- ^ starting index -> Int -- ^ length of the slice -> Array a -> Array a -getSliceUnsafe index len (Array contents start e) = +unsafeGetSlice index len (Array contents start e) = let size = SIZE_OF(a) start1 = start + (index * size) end1 = start1 + (len * size) in assert (end1 <= e) (Array contents start1 end1) +RENAME(getSliceUnsafe,unsafeGetSlice) + -- | Split the array into a stream of slices using a predicate. The element -- matching the predicate is dropped. -- @@ -466,19 +470,20 @@ streamTransform f arr = -- -- /Pre-release/ -- -castUnsafe :: +unsafeCast, castUnsafe :: #ifdef DEVBUILD Unbox b => #endif Array a -> Array b -castUnsafe (Array contents start end) = +unsafeCast (Array contents start end) = Array contents start end +RENAME(castUnsafe,unsafeCast) -- | Cast an @Array a@ into an @Array Word8@. -- -- asBytes :: Array a -> Array Word8 -asBytes = castUnsafe +asBytes = unsafeCast -- | Cast an array having elements of type @a@ into an array having elements of -- type @b@. The length of the array should be a multiple of the size of the @@ -491,7 +496,7 @@ cast arr = r = len `mod` SIZE_OF(b) in if r /= 0 then Nothing - else Just $ castUnsafe arr + else Just $ unsafeCast arr -- | Convert an array of any type into a null terminated CString Ptr. If the -- array is unpinned it is first converted to a pinned array which requires a diff --git a/core/src/Streamly/Internal/Data/Array/Generic.hs b/core/src/Streamly/Internal/Data/Array/Generic.hs index 8af5ac3e32..9a33320aee 100644 --- a/core/src/Streamly/Internal/Data/Array/Generic.hs +++ b/core/src/Streamly/Internal/Data/Array/Generic.hs @@ -40,12 +40,14 @@ module Streamly.Internal.Data.Array.Generic , fold -- * Random Access - , getIndexUnsafe + , unsafeGetIndex , getIndex - , getSliceUnsafe + , unsafeGetSlice , strip -- * Deprecated + , getIndexUnsafe + , getSliceUnsafe , writeN , write , fromByteStr# @@ -53,6 +55,7 @@ module Streamly.Internal.Data.Array.Generic where #include "inline.hs" +#include "deprecation.h" import Control.Monad (replicateM) import Control.Monad.IO.Class (MonadIO) @@ -206,17 +209,17 @@ toList arr = loop 0 len = length arr loop i | i == len = [] - loop i = getIndexUnsafe i arr : loop (i + 1) + loop i = unsafeGetIndex i arr : loop (i + 1) {-# INLINE_NORMAL read #-} read :: Monad m => Array a -> Stream m a read arr = - D.map (`getIndexUnsafe` arr) $ D.enumerateFromToIntegral 0 (length arr - 1) + D.map (`unsafeGetIndex` arr) $ D.enumerateFromToIntegral 0 (length arr - 1) {-# INLINE_NORMAL readRev #-} readRev :: Monad m => Array a -> Stream m a readRev arr = - D.map (`getIndexUnsafe` arr) + D.map (`unsafeGetIndex` arr) $ D.enumerateFromThenToIntegral (arrLen - 1) (arrLen - 2) 0 where arrLen = length arr @@ -249,9 +252,9 @@ streamFold f arr = f (read arr) -- not check the bounds. -- -- @since 0.8.0 -{-# INLINE getIndexUnsafe #-} -getIndexUnsafe :: Int -> Array a -> a -getIndexUnsafe i arr = +{-# INLINE unsafeGetIndex #-} +unsafeGetIndex, getIndexUnsafe :: Int -> Array a -> a +unsafeGetIndex i arr = unsafePerformIO $ MArray.unsafeGetIndex i (unsafeThaw arr) -- | Lookup the element at the given index. Index starts from 0. @@ -260,7 +263,7 @@ getIndexUnsafe i arr = getIndex :: Int -> Array a -> Maybe a getIndex i arr = if i >= 0 && i < length arr - then Just $ getIndexUnsafe i arr + then Just $ unsafeGetIndex i arr else Nothing -- >>> import qualified Streamly.Data.Stream as Stream @@ -284,9 +287,9 @@ createOfLast n = FL.rmapM f (RB.createOf n) arr <- RB.copyToMutArray 0 n rb return $ unsafeFreeze arr -{-# INLINE getSliceUnsafe #-} -getSliceUnsafe :: Int -> Int -> Array a -> Array a -getSliceUnsafe offset len = +{-# INLINE unsafeGetSlice #-} +unsafeGetSlice, getSliceUnsafe :: Int -> Int -> Array a -> Array a +unsafeGetSlice offset len = unsafeFreeze . MArray.unsafeGetSlice offset len . unsafeThaw -- XXX This is not efficient as it copies the array. We should support array @@ -346,3 +349,10 @@ instance Read a => Read (Array a) where if fromListWord == "fromList " then fromList <$> readPrec else ReadPrec.pfail + +------------------------------------------------------------------------------- +-- Backward Compatibility +------------------------------------------------------------------------------- + +RENAME(getSliceUnsafe,unsafeGetSlice) +RENAME(getIndexUnsafe,unsafeGetIndex) diff --git a/core/src/Streamly/Internal/Data/Array/Type.hs b/core/src/Streamly/Internal/Data/Array/Type.hs index 9fa5715515..24f9acc234 100644 --- a/core/src/Streamly/Internal/Data/Array/Type.hs +++ b/core/src/Streamly/Internal/Data/Array/Type.hs @@ -77,8 +77,8 @@ module Streamly.Internal.Data.Array.Type -- ** Reading -- *** Indexing - , unsafeIndexIO -- XXX unsafeGetIndexIO - , getIndexUnsafe -- XXX unsafeGetIndex + , unsafeGetIndexIO + , unsafeGetIndex -- *** To Streams , read @@ -91,7 +91,7 @@ module Streamly.Internal.Data.Array.Type -- *** Unfolds , producer -- experimental - , readerUnsafe + , unsafeReader , reader , readerRev @@ -170,6 +170,9 @@ module Streamly.Internal.Data.Array.Type , pinnedFromListN , pinnedFromList , pinnedChunksOf + , unsafeIndexIO + , getIndexUnsafe + , readerUnsafe ) where @@ -698,19 +701,19 @@ breakOn sep arr = do -- | Return element at the specified index without checking the bounds. -- -- Unsafe because it does not check the bounds of the array. -{-# INLINE_NORMAL unsafeIndexIO #-} -unsafeIndexIO :: forall a. Unbox a => Int -> Array a -> IO a -unsafeIndexIO i arr = MA.unsafeGetIndex i (unsafeThaw arr) +{-# INLINE_NORMAL unsafeGetIndexIO #-} +unsafeGetIndexIO, unsafeIndexIO :: forall a. Unbox a => Int -> Array a -> IO a +unsafeGetIndexIO i arr = MA.unsafeGetIndex i (unsafeThaw arr) -- | Return element at the specified index without checking the bounds. -{-# INLINE_NORMAL getIndexUnsafe #-} -getIndexUnsafe :: forall a. Unbox a => Int -> Array a -> a -getIndexUnsafe i arr = let !r = unsafeInlineIO $ unsafeIndexIO i arr in r +{-# INLINE_NORMAL unsafeGetIndex #-} +unsafeGetIndex, getIndexUnsafe :: forall a. Unbox a => Int -> Array a -> a +unsafeGetIndex i arr = let !r = unsafeInlineIO $ unsafeGetIndexIO i arr in r -{-# DEPRECATED unsafeIndex "Please use 'getIndexUnsafe' instead" #-} +{-# DEPRECATED unsafeIndex "Please use 'unsafeGetIndex' instead" #-} {-# INLINE_NORMAL unsafeIndex #-} unsafeIndex :: forall a. Unbox a => Int -> Array a -> a -unsafeIndex = getIndexUnsafe +unsafeIndex = unsafeGetIndex -- | /O(1)/ Get the byte length of the array. -- @@ -748,9 +751,9 @@ reader = Producer.simplify producer -- -- /Pre-release/ -- -{-# INLINE_NORMAL readerUnsafe #-} -readerUnsafe :: forall m a. (Monad m, Unbox a) => Unfold m (Array a) a -readerUnsafe = Unfold step inject +{-# INLINE_NORMAL unsafeReader #-} +unsafeReader, readerUnsafe :: forall m a. (Monad m, Unbox a) => Unfold m (Array a) a +unsafeReader = Unfold step inject where inject (Array contents start end) = @@ -1288,3 +1291,11 @@ nil = empty instance Unbox a => Monoid (Array a) where mempty = nil mappend = (<>) + +------------------------------------------------------------------------------- +-- Backward Compatibility +------------------------------------------------------------------------------- + +RENAME(unsafeIndexIO,unsafeGetIndexIO) +RENAME(getIndexUnsafe,unsafeGetIndex) +RENAME(readerUnsafe,unsafeReader) diff --git a/core/src/Streamly/Internal/Data/Binary/Parser.hs b/core/src/Streamly/Internal/Data/Binary/Parser.hs index 34b4d0b2a7..efc8b57d06 100644 --- a/core/src/Streamly/Internal/Data/Binary/Parser.hs +++ b/core/src/Streamly/Internal/Data/Binary/Parser.hs @@ -57,7 +57,7 @@ import Streamly.Internal.Data.Maybe.Strict (Maybe'(..)) import Streamly.Internal.Data.Tuple.Strict (Tuple' (..)) import qualified Streamly.Data.Array as A import qualified Streamly.Internal.Data.Array as A - (getIndexUnsafe, castUnsafe) + (unsafeGetIndex, unsafeCast) import qualified Streamly.Internal.Data.Parser as PR (fromPure, either, satisfy, takeEQ) import qualified Streamly.Internal.Data.Parser as PRD @@ -388,7 +388,7 @@ charLatin1 = fmap (chr . fromIntegral) word8 {-# INLINE word64host #-} word64host :: MonadIO m => Parser Word8 m Word64 word64host = - fmap (A.getIndexUnsafe 0 . A.castUnsafe) $ PR.takeEQ 8 (A.createOf 8) + fmap (A.unsafeGetIndex 0 . A.unsafeCast) $ PR.takeEQ 8 (A.createOf 8) ------------------------------------------------------------------------------- -- Type class diff --git a/core/src/Streamly/Internal/Data/Fold/Combinators.hs b/core/src/Streamly/Internal/Data/Fold/Combinators.hs index fa7e0b849d..258b93a579 100644 --- a/core/src/Streamly/Internal/Data/Fold/Combinators.hs +++ b/core/src/Streamly/Internal/Data/Fold/Combinators.hs @@ -1465,7 +1465,7 @@ takeEndBySeq patArr (Fold fstep finitial fextract ffinal) = -- Done <$> ffinal acc return $ Partial $ SplitOnSeqEmpty acc | patLen == 1 -> do - pat <- liftIO $ Array.unsafeIndexIO 0 patArr + pat <- liftIO $ Array.unsafeGetIndexIO 0 patArr return $ Partial $ SplitOnSeqSingle acc pat | SIZE_OF(a) * patLen <= sizeOf (Proxy :: Proxy Word) -> return $ Partial $ SplitOnSeqWord acc 0 0 @@ -1631,7 +1631,7 @@ takeEndBySeq_ patArr (Fold fstep finitial fextract ffinal) = -- Done <$> ffinal acc return $ Partial $ SplitOnSeqEmpty acc | patLen == 1 -> do - pat <- liftIO $ Array.unsafeIndexIO 0 patArr + pat <- liftIO $ Array.unsafeGetIndexIO 0 patArr return $ Partial $ SplitOnSeqSingle acc pat -- XXX Need to add tests for this case | SIZE_OF(a) * patLen <= sizeOf (Proxy :: Proxy Word) -> diff --git a/core/src/Streamly/Internal/Data/Scanl/Combinators.hs b/core/src/Streamly/Internal/Data/Scanl/Combinators.hs index ee700e561d..5b0a8464a2 100644 --- a/core/src/Streamly/Internal/Data/Scanl/Combinators.hs +++ b/core/src/Streamly/Internal/Data/Scanl/Combinators.hs @@ -1424,7 +1424,7 @@ takeEndBySeq patArr (Fold fstep finitial fextract ffinal) = -- Done <$> ffinal acc return $ Partial $ SplitOnSeqEmpty acc | patLen == 1 -> do - pat <- liftIO $ Array.unsafeIndexIO 0 patArr + pat <- liftIO $ Array.unsafeGetIndexIO 0 patArr return $ Partial $ SplitOnSeqSingle acc pat | SIZE_OF(a) * patLen <= sizeOf (Proxy :: Proxy Word) -> return $ Partial $ SplitOnSeqWord acc 0 0 @@ -1564,7 +1564,7 @@ takeEndBySeq_ patArr (Fold fstep finitial fextract ffinal) = -- Done <$> ffinal acc return $ Partial $ SplitOnSeqEmpty acc | patLen == 1 -> do - pat <- liftIO $ Array.unsafeIndexIO 0 patArr + pat <- liftIO $ Array.unsafeGetIndexIO 0 patArr return $ Partial $ SplitOnSeqSingle acc pat -- XXX Need to add tests for this case | SIZE_OF(a) * patLen <= sizeOf (Proxy :: Proxy Word) -> diff --git a/core/src/Streamly/Internal/Data/Stream/Nesting.hs b/core/src/Streamly/Internal/Data/Stream/Nesting.hs index e02af947aa..013ec07d41 100644 --- a/core/src/Streamly/Internal/Data/Stream/Nesting.hs +++ b/core/src/Streamly/Internal/Data/Stream/Nesting.hs @@ -2500,7 +2500,7 @@ takeEndBySeqWith withSep patArr (Stream step state) = case () of _ | patLen == 0 -> return Stop | patLen == 1 -> do - pat <- liftIO $ A.unsafeIndexIO 0 patArr + pat <- liftIO $ A.unsafeGetIndexIO 0 patArr return $ Skip $ TakeEndBySeqSingle state pat | SIZE_OF(a) * patLen <= sizeOf (Proxy :: Proxy Word) -> return $ Skip $ TakeEndBySeqWordInit 0 0 state @@ -2845,7 +2845,7 @@ splitSepBySeq_ patArr (Fold fstep initial _ final) (Stream step state) = | patLen == 0 -> return $ Skip $ SplitOnSeqEmpty acc state | patLen == 1 -> do - pat <- liftIO $ A.unsafeIndexIO 0 patArr + pat <- liftIO $ A.unsafeGetIndexIO 0 patArr return $ Skip $ SplitOnSeqSingle acc state pat | SIZE_OF(a) * patLen <= sizeOf (Proxy :: Proxy Word) -> return $ Skip $ SplitOnSeqWordInit acc state @@ -3229,7 +3229,7 @@ splitOnSuffixSeq withSep patArr (Fold fstep initial _ final) (Stream step state) | patLen == 0 -> skip $ SplitOnSuffixSeqEmpty fs state | patLen == 1 -> do - pat <- liftIO $ A.unsafeIndexIO 0 patArr + pat <- liftIO $ A.unsafeGetIndexIO 0 patArr skip $ SplitOnSuffixSeqSingleInit fs state pat | SIZE_OF(a) * patLen <= sizeOf (Proxy :: Proxy Word) -> skip $ SplitOnSuffixSeqWordInit fs state diff --git a/core/src/Streamly/Internal/Data/StreamK.hs b/core/src/Streamly/Internal/Data/StreamK.hs index 6fdb642f50..ccf4f3b228 100644 --- a/core/src/Streamly/Internal/Data/StreamK.hs +++ b/core/src/Streamly/Internal/Data/StreamK.hs @@ -1583,8 +1583,8 @@ backTrackGenericChunks = go then go (n - len) xs (cons x stream) else if n == len then (cons x stream, xs) - else let arr1 = GenArr.getSliceUnsafe (len - n) n x - arr2 = GenArr.getSliceUnsafe 0 (len - n) x + else let arr1 = GenArr.unsafeGetSlice (len - n) n x + arr2 = GenArr.unsafeGetSlice 0 (len - n) x in (cons arr1 stream, arr2:xs) -- | Similar to 'parseBreak' but works on generic arrays diff --git a/core/src/Streamly/Internal/FileSystem/Path/Common.hs b/core/src/Streamly/Internal/FileSystem/Path/Common.hs index 5e097bcb2b..f3b422d0c4 100644 --- a/core/src/Streamly/Internal/FileSystem/Path/Common.hs +++ b/core/src/Streamly/Internal/FileSystem/Path/Common.hs @@ -121,7 +121,7 @@ unsafeFromChunk :: Array Word8 -> Array a unsafeFromChunk = #ifndef DEBUG - Array.castUnsafe + Array.unsafeCast #else fromJust . fromChunk #endif @@ -229,7 +229,7 @@ wordToChar = unsafeChr . fromIntegral -- | Index a word in an array and convert it to Char. unsafeIndexChar :: (Unbox a, Integral a) => Int -> Array a -> Char -unsafeIndexChar i a = wordToChar (Array.getIndexUnsafe i a) +unsafeIndexChar i a = wordToChar (Array.unsafeGetIndex i a) ------------------------------------------------------------------------------ -- Separator parsing @@ -333,9 +333,9 @@ isDrive a = Array.length a == 2 && unsafeHasDrive a isRelativeCurDir :: (Unbox a, Integral a) => OS -> Array a -> Bool isRelativeCurDir os a | len == 0 = False -- empty path should not occur - | wordToChar (Array.getIndexUnsafe 0 a) /= '.' = False + | wordToChar (Array.unsafeGetIndex 0 a) /= '.' = False | len < 2 = True - | otherwise = isSeparatorWord os (Array.getIndexUnsafe 1 a) + | otherwise = isSeparatorWord os (Array.unsafeGetIndex 1 a) where @@ -345,7 +345,7 @@ isRelativeCurDir os a hasLeadingSeparator :: (Unbox a, Integral a) => OS -> Array a -> Bool hasLeadingSeparator os a | Array.length a == 0 = False -- empty path should not occur - | isSeparatorWord os (Array.getIndexUnsafe 0 a) = True + | isSeparatorWord os (Array.unsafeGetIndex 0 a) = True | otherwise = False -- | A non-UNC path starting with a separator. @@ -359,8 +359,8 @@ isRelativeCurDriveRoot a where len = Array.length a - c0 = Array.getIndexUnsafe 0 a - c1 = Array.getIndexUnsafe 1 a + c0 = Array.unsafeGetIndex 0 a + c1 = Array.unsafeGetIndex 1 a sep0 = isSeparatorWord Windows c0 -- | @C:@ or @C:a...@. @@ -387,8 +387,8 @@ isAbsoluteUNC a where - c0 = Array.getIndexUnsafe 0 a - c1 = Array.getIndexUnsafe 1 a + c0 = Array.unsafeGetIndex 0 a + c1 = Array.unsafeGetIndex 1 a -- | Note that on Windows a path starting with a separator is relative to -- current drive while on Posix this is absolute path as there is only one @@ -551,11 +551,11 @@ unsafeSplitPrefix os prefixLen arr = (drive, path) len = Array.length arr -- XXX Array.readFrom may be useful here - afterDrive = Array.getSliceUnsafe prefixLen (len - prefixLen) arr + afterDrive = Array.unsafeGetSlice prefixLen (len - prefixLen) arr n = countLeadingBy (isSeparatorWord os) afterDrive cnt = prefixLen + n - drive = Array.getSliceUnsafe 0 cnt arr - path = Array.getSliceUnsafe cnt (len - cnt) arr + drive = Array.unsafeGetSlice 0 cnt arr + path = Array.unsafeGetSlice cnt (len - cnt) arr -- XXX We can produce a normalized result for the drive during split. @@ -631,11 +631,11 @@ parseSegment arr len sepOff = (segOff, segCnt) where - arr1 = Array.getSliceUnsafe sepOff (len - sepOff) arr + arr1 = Array.unsafeGetSlice sepOff (len - sepOff) arr sepCnt = countLeadingBy (isSeparatorWord Windows) arr1 segOff = sepOff + sepCnt - arr2 = Array.getSliceUnsafe segOff (len - segOff) arr + arr2 = Array.unsafeGetSlice segOff (len - segOff) arr segCnt = countLeadingBy (not . isSeparatorWord Windows) arr2 -- XXX We can split a path as "root, . , rest" or "root, /, rest". @@ -698,7 +698,7 @@ unsafeSplitUNC arr = where len = Array.length arr - arr1 = Array.getSliceUnsafe 2 (len - 2) arr + arr1 = Array.unsafeGetSlice 2 (len - 2) arr cnt1 = countLeadingBy (not . isSeparatorWord Windows) arr1 sepOff = 2 + cnt1 @@ -789,7 +789,7 @@ splitPath os arr = let stream = Stream.indexEndBy_ (isSeparatorWord os) (Array.read rest) & Stream.filter (not . shouldFilterOut) - & fmap (\(i, len) -> Array.getSliceUnsafe i len rest) + & fmap (\(i, len) -> Array.unsafeGetSlice i len rest) in if Array.length root == 0 then stream diff --git a/core/src/Streamly/Internal/FileSystem/Windows/ReadDir.hsc b/core/src/Streamly/Internal/FileSystem/Windows/ReadDir.hsc index d1f8672f53..0c2b4be9e2 100644 --- a/core/src/Streamly/Internal/FileSystem/Windows/ReadDir.hsc +++ b/core/src/Streamly/Internal/FileSystem/Windows/ReadDir.hsc @@ -104,7 +104,7 @@ failWith fn_name err_code = do c_msg <- getErrorMessage err_code msg <- if c_msg == nullPtr then return $ "Error 0x" ++ Numeric.showHex err_code "" - else do + else do msg <- peekCWString c_msg -- We ignore failure of freeing c_msg, given we're already failing _ <- localFree c_msg @@ -145,8 +145,8 @@ openDirStream p = do Array.asCStringUnsafe (Path.toChunk path) $ \pathPtr -> do -- XXX Use getLastError to distinguish the case when no -- matching file is found. See the doc of FindFirstFileW. - failIf - (== iNVALID_HANDLE_VALUE) + failIf + (== iNVALID_HANDLE_VALUE) ("FindFirstFileW: " ++ Path.toString path) $ c_FindFirstFileW (castPtr pathPtr) dataPtr ref <- newIORef True @@ -199,8 +199,8 @@ readDirStreamEither (DirStream (h, ref, fdata)) = isMeta <- isMetaDir dname if isMeta then findNext ptr - else return (Just (Left (mkPath (Array.castUnsafe name)))) - else return (Just (Right (mkPath (Array.castUnsafe name)))) + else return (Just (Left (mkPath (Array.unsafeCast name)))) + else return (Just (Right (mkPath (Array.unsafeCast name)))) findNext ptr = do retval <- liftIO $ c_FindNextFileW h ptr diff --git a/core/src/Streamly/Internal/Unicode/Stream.hs b/core/src/Streamly/Internal/Unicode/Stream.hs index 5eb99aadf7..98d164ef8e 100644 --- a/core/src/Streamly/Internal/Unicode/Stream.hs +++ b/core/src/Streamly/Internal/Unicode/Stream.hs @@ -737,8 +737,8 @@ mkEvenW8Chunks (D.Stream step state) = D.Stream step1 (MECSInit state) Yield arr st1 -> let len = Array.length arr in if (len .&. 1) == 1 - then let arr1 = Array.getSliceUnsafe 0 (len - 1) arr - remElem = Array.getIndexUnsafe (len - 1) arr + then let arr1 = Array.unsafeGetSlice 0 (len - 1) arr + remElem = Array.unsafeGetIndex (len - 1) arr in Yield arr1 (MECSBuffer remElem st1) else Yield arr (MECSInit st1) Skip s -> Skip (MECSInit s) @@ -750,19 +750,19 @@ mkEvenW8Chunks (D.Stream step state) = D.Stream step1 (MECSInit state) Yield arr st1 | Array.length arr == 0 -> Skip (MECSBuffer remElem st1) Yield arr st1 | Array.length arr == 1 -> - let fstElem = Array.getIndexUnsafe 0 arr + let fstElem = Array.unsafeGetIndex 0 arr w16 = Array.fromList [remElem, fstElem] in Yield w16 (MECSInit st1) Yield arr st1 -> let len = Array.length arr in if (len .&. 1) == 1 - then let arr1 = Array.getSliceUnsafe 1 (len - 1) arr - fstElem = Array.getIndexUnsafe 0 arr + then let arr1 = Array.unsafeGetSlice 1 (len - 1) arr + fstElem = Array.unsafeGetIndex 0 arr w16 = Array.fromList [remElem, fstElem] in Yield w16 (MECSYieldAndInit arr1 st1) - else let arr1 = Array.getSliceUnsafe 1 (len - 2) arr - fstElem = Array.getIndexUnsafe 0 arr - lstElem = Array.getIndexUnsafe (len - 1) arr + else let arr1 = Array.unsafeGetSlice 1 (len - 2) arr + fstElem = Array.unsafeGetIndex 0 arr + lstElem = Array.unsafeGetIndex (len - 1) arr w16 = Array.fromList [remElem, fstElem] in Yield w16 (MECSYieldAndBuffer arr1 lstElem st1) diff --git a/src/Streamly/Internal/FileSystem/Event/Darwin.hs b/src/Streamly/Internal/FileSystem/Event/Darwin.hs index c9b011414d..7538742a72 100644 --- a/src/Streamly/Internal/FileSystem/Event/Darwin.hs +++ b/src/Streamly/Internal/FileSystem/Event/Darwin.hs @@ -493,10 +493,10 @@ data Event = Event readOneEvent :: Parser Word8 IO Event readOneEvent = do arr <- PR.takeEQ 24 (A.createOf 24) - let arr1 = A.castUnsafe arr :: Array Word64 - eid = A.getIndexUnsafe 0 arr1 - eflags = A.getIndexUnsafe 1 arr1 - pathLen = fromIntegral $ A.getIndexUnsafe 2 arr1 + let arr1 = A.unsafeCast arr :: Array Word64 + eid = A.unsafeGetIndex 0 arr1 + eflags = A.unsafeGetIndex 1 arr1 + pathLen = fromIntegral $ A.unsafeGetIndex 2 arr1 path <- PR.takeEQ pathLen (A.createOf pathLen) return $ Event { eventId = eid diff --git a/src/Streamly/Internal/FileSystem/Event/Linux.hs b/src/Streamly/Internal/FileSystem/Event/Linux.hs index 5c60501e30..a25bc87118 100644 --- a/src/Streamly/Internal/FileSystem/Event/Linux.hs +++ b/src/Streamly/Internal/FileSystem/Event/Linux.hs @@ -192,7 +192,7 @@ import qualified Streamly.Internal.FileSystem.Path as Path import qualified Streamly.Internal.Data.Array as A ( asCStringUnsafe, unsafePinnedAsPtr - , getSliceUnsafe, read + , unsafeGetSlice, read ) import qualified Streamly.Internal.FileSystem.DirIO as Dir (readDirs) import qualified Streamly.Internal.Data.Parser as PR @@ -664,7 +664,7 @@ removeTrailingSlash path = Nothing -> error "removeTrailingSlash: Bug: Invalid index" Just x -> if x == fromIntegral (ord '/') - then A.getSliceUnsafe 0 n path + then A.unsafeGetSlice 0 n path else path else path diff --git a/test/Streamly/Test/Data/Array.hs b/test/Streamly/Test/Data/Array.hs index 5f72193188..1282bf74f4 100644 --- a/test/Streamly/Test/Data/Array.hs +++ b/test/Streamly/Test/Data/Array.hs @@ -126,7 +126,7 @@ testStripNull = do unsafeSlice :: Int -> Int -> [Int] -> Bool unsafeSlice i n list = let lst = take n $ drop i list - arr = A.toList $ A.getSliceUnsafe i n $ A.fromList list + arr = A.toList $ A.unsafeGetSlice i n $ A.fromList list in arr == lst testBubbleWith :: Bool -> Property @@ -183,7 +183,7 @@ testFromToList inp = A.toList (A.fromList inp) `shouldBe` inp testUnsafeIndxedFromList :: [Char] -> IO () testUnsafeIndxedFromList inp = let arr = A.fromList inp - in fmap (`A.getIndexUnsafe` arr) [0 .. (length inp - 1)] `shouldBe` inp + in fmap (`A.unsafeGetIndex` arr) [0 .. (length inp - 1)] `shouldBe` inp getIntList :: Ptr Int -> Int -> IO [Int] getIntList ptr byteLen = do @@ -334,7 +334,7 @@ main = describe "toList . fromList" $ do it "testFromToList abc" (testFromToList "abc") it "testFromToList \\22407" (testFromToList "\22407") - describe "getIndexUnsafe . fromList" $ do + describe "unsafeGetIndex . fromList" $ do it "testUnsafeIndxedFromList abc" (testUnsafeIndxedFromList "abc") it "testUnsafeIndxedFromList \\22407" (testUnsafeIndxedFromList "\22407") diff --git a/test/Streamly/Test/Data/Parser.hs b/test/Streamly/Test/Data/Parser.hs index 439f7b056f..fde76190dd 100644 --- a/test/Streamly/Test/Data/Parser.hs +++ b/test/Streamly/Test/Data/Parser.hs @@ -928,10 +928,10 @@ data Event = Event readOneEvent :: P.Parser Word8 IO Event readOneEvent = do arr <- P.takeEQ 24 (A.createOf 24) - let arr1 = A.castUnsafe arr :: A.Array Word64 - eid = A.getIndexUnsafe 0 arr1 - eflags = A.getIndexUnsafe 1 arr1 - pathLen = fromIntegral $ A.getIndexUnsafe 2 arr1 + let arr1 = A.unsafeCast arr :: A.Array Word64 + eid = A.unsafeGetIndex 0 arr1 + eflags = A.unsafeGetIndex 1 arr1 + pathLen = fromIntegral $ A.unsafeGetIndex 2 arr1 -- XXX handle if pathLen is 0 path <- P.takeEQ pathLen (A.createOf pathLen) return $ Event