@@ -38,7 +38,7 @@ import Data.Word (Word16, Word64)
3838import qualified Data.Text.Internal as T
3939import qualified Data.Text as T
4040import Data.Text.Fusion.Internal (PairS(..))
41−import Data.Text.Lazy.Internal (Text(..))
41+import Data.Text.Lazy.Internal (Text(..), foldlChunks)
4242import Data.Bits ((.|.), (.&.))
4343import Data.Text.UnsafeShift (shiftL)
4444
@@ -79,7 +79,7 @@ indices needle@(Chunk n ns) haystack@(Chunk k ks)
7979 nlen = wordLength needle
8080 nlast = nlen - 1
8181 nindex = index n ns
82− z = foldChunks fin 0 needle
82+ z = foldlChunks fin 0 needle
8383 where fin _ (T.Text farr foff flen) = A.unsafeIndex farr (foff+flen-1)
8484 mask :*: skip = buildTable needle
8585 scanOne c i (T.Text oarr ooff olen) os = go 0
@@ -104,13 +104,8 @@ index (T.Text arr off len) xs i
104104swizzle :: Word16 -> Word64
105105swizzle k = 1 `shiftL` (fromIntegral k .&. 0x3f)
106106
107−foldChunks :: (a -> T.Text -> a) -> a -> Text -> a
108−foldChunks _ z Empty = z
109−foldChunks f z (Chunk c cs) = let z' = f z c
110− in z' `seq` foldChunks f z' cs
111−
112107wordLength :: Text -> Int64
113−wordLength = foldChunks sumLength 0
108+wordLength = foldlChunks sumLength 0
114109 where sumLength i (T.Text _ _ l) = i + fromIntegral l
115110
116111buildTable :: Text -> PairS Word64 Int64
@@ -129,5 +124,5 @@ buildTable needle@(Chunk k ks) = outer k ks 0 0 0 (nlen-2)
129124 | otherwise = skip
130125 xlast = xlen - 1
131126 nlen = wordLength needle
132− z = foldChunks fin 0 needle
127+ z = foldlChunks fin 0 needle
133128 where fin _ (T.Text farr foff flen) = A.unsafeIndex farr (foff+flen-1)