File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -14,6 +14,8 @@ import System.Posix.Types (CSsize(..))
1414import GHC.Exts (ByteArray #)
1515import Data.Word (Word8 )
1616
17+ -- | Find index of next occurrence of given byte,
18+ -- relative to the starting offset, or @-1@ if not found.
1719memchr :: ByteArray # -> Int -> Int -> Word8 -> Int
1820#if defined(PURE_HASKELL)
1921memchr arr# off len w =
Original file line number Diff line number Diff line change @@ -111,12 +111,11 @@ indicesOne c = chunk
111111 where
112112 chunk :: Int64 -> Text -> [Int64 ]
113113 chunk ! _ Empty = []
114- chunk ! i (Chunk (T. Text oarr ooff olen) os) = go 0
114+ chunk ! i (Chunk (T. Text ( A. ByteArray oarr# ) ooff olen) os) = go 0
115115 where
116- go h | h >= olen = chunk (i+ intToInt64 olen) os
117- | on == c = i + intToInt64 h : go (h+ 1 )
118- | otherwise = go (h+ 1 )
119- where on = A. unsafeIndex oarr (ooff+ h)
116+ go h = case memchr oarr# (ooff+ h) (olen- h) c of
117+ - 1 -> chunk (i+ intToInt64 olen) os
118+ x -> i + intToInt64 h + intToInt64 x : go (h + x + 1 )
120119
121120-- | First argument is a strict Text, and second is a lazy one.
122121isPrefixOf :: T. Text -> Text -> Bool
Original file line number Diff line number Diff line change @@ -91,12 +91,11 @@ indices' (Text narr noff nlen) (Text harr@(A.ByteArray harr#) hoff hlen) = loop
9191{-# INLINE indices' #-}
9292
9393scanOne :: Word8 -> Text -> [Int ]
94- scanOne c (Text harr hoff hlen) = loop 0
94+ scanOne c (Text ( A. ByteArray harr# ) hoff hlen) = loop 0
9595 where
96- loop ! i
97- | i >= hlen = []
98- | A. unsafeIndex harr (hoff+ i) == c = i : loop (i+ 1 )
99- | otherwise = loop (i+ 1 )
96+ loop ! i = case memchr harr# (hoff + i) (hlen - i) c of
97+ - 1 -> []
98+ x -> i + x : loop (i + x + 1 )
10099{-# INLINE scanOne #-}
101100
102101word8ToInt :: Word8 -> Int
You can’t perform that action at this time.
0 commit comments