diff --git a/core/src/Streamly/Internal/Data/MutArray/Lib.c b/core/src/Streamly/Internal/Data/MutArray/Lib.c index dea78f6373..641a0d94c9 100644 --- a/core/src/Streamly/Internal/Data/MutArray/Lib.c +++ b/core/src/Streamly/Internal/Data/MutArray/Lib.c @@ -13,8 +13,3 @@ size_t memchr_index(const void *dst, size_t off, int c, size_t len) { return len; } } - -int memcmp_index(const void *p1, size_t p1_off, const void *p2, size_t p2_off, size_t len) { - int cmp = memcmp((char *)p1 + p1_off, (char *)p2 + p2_off, len); - return cmp; -} diff --git a/core/src/Streamly/Internal/Data/MutArray/Type.hs b/core/src/Streamly/Internal/Data/MutArray/Type.hs index 27bfb5af9b..9d8a370feb 100644 --- a/core/src/Streamly/Internal/Data/MutArray/Type.hs +++ b/core/src/Streamly/Internal/Data/MutArray/Type.hs @@ -295,9 +295,6 @@ module Streamly.Internal.Data.MutArray.Type , isPower2 , roundUpToPower2 - -- * Foreign APIs - , c_memcmp_index - -- * Deprecated , realloc , createOfWith @@ -379,7 +376,7 @@ import Data.Char (ord) import Data.Functor.Identity (Identity(..)) import Data.Proxy (Proxy(..)) import Data.Word (Word8, Word16) -import Foreign.C.Types (CSize(..), CInt(..)) +import Foreign.C.Types (CSize(..)) import Foreign.Ptr (plusPtr) import Streamly.Internal.Data.MutByteArray.Type ( MutByteArray(..) @@ -436,11 +433,6 @@ foreign import ccall unsafe "memchr_index" c_memchr_index foreign import ccall unsafe "string.h strlen" c_strlen :: Ptr Word8 -> IO CSize -foreign import ccall unsafe "memcmp_index" c_memcmp_index - :: MutableByteArray# RealWorld -> CSize - -> MutableByteArray# RealWorld -> CSize - -> CSize -> IO CInt - -- | Given an 'Unboxed' type (unused first arg) and a number of bytes, return -- how many elements of that type will completely fit in those bytes. -- diff --git a/core/src/Streamly/Internal/Data/RingArray.hs b/core/src/Streamly/Internal/Data/RingArray.hs index 6ff3fc63ff..e69c0306b7 100644 --- a/core/src/Streamly/Internal/Data/RingArray.hs +++ b/core/src/Streamly/Internal/Data/RingArray.hs @@ -642,21 +642,21 @@ eqArrayN RingArray{..} Array.Array{..} nBytes | arrEnd - arrStart < nBytes = error "eqArrayN: array is shorter than n" | ringSize < nBytes = error "eqArrayN: ring is shorter than n" | nBytes == 0 = return True - | nBytesC <= p1Len = do - part1 <- MutArray.c_memcmp_index arr# 0 ring# p1Off nBytesC + | nBytes <= p1Len = do + part1 <- + MutByteArray.unsafeByteCmp + arrContents 0 ringContents ringHead nBytes pure $ part1 == 0 | otherwise = do - part1 <- MutArray.c_memcmp_index arr# 0 ring# p1Off p1Len - part2 <- MutArray.c_memcmp_index arr# p1Len ring# p2Off p2Len + part1 <- + MutByteArray.unsafeByteCmp + arrContents 0 ringContents ringHead p1Len + part2 <- + MutByteArray.unsafeByteCmp arrContents p1Len ringContents 0 p2Len pure $ part1 == 0 && part2 == 0 where - nBytesC = fromIntegral nBytes - arr# = MutByteArray.getMutByteArray# arrContents - ring# = MutByteArray.getMutByteArray# ringContents - p1Off = fromIntegral ringHead - p1Len = fromIntegral $ ringSize - ringHead - p2Off = 0 - p2Len = nBytesC - p1Len + p1Len = ringSize - ringHead + p2Len = nBytes - p1Len -- | Byte compare the entire length of ringBuffer with the given array, -- starting at the supplied ring head index. Returns true if the Array and @@ -669,16 +669,16 @@ eqArray :: RingArray a -> Array a -> IO Bool eqArray RingArray{..} Array.Array{..} | arrEnd - arrStart < ringSize = error "eqArrayN: array is shorter than ring" | otherwise = do - part1 <- MutArray.c_memcmp_index arr# 0 ring# p1Off p1Len - part2 <- MutArray.c_memcmp_index arr# p1Len ring# p2Off p2Len + part1 <- + MutByteArray.unsafeByteCmp + arrContents 0 ringContents ringHead p1Len + part2 <- + MutByteArray.unsafeByteCmp + arrContents p1Len ringContents 0 p2Len pure $ part1 == 0 && part2 == 0 where - arr# = MutByteArray.getMutByteArray# arrContents - ring# = MutByteArray.getMutByteArray# ringContents - p1Off = fromIntegral ringHead - p1Len = fromIntegral $ ringSize - ringHead - p2Off = 0 - p2Len = fromIntegral ringHead + p1Len = ringSize - ringHead + p2Len = ringHead ------------------------------------------------------------------------------- -- Folding