@@ -38,7 +38,7 @@ import Data.Word (Word16, Word64)
38import qualified Data.Text.Internal as T
38import qualified Data.Text.Internal as T
39import qualified Data.Text as T
39import qualified Data.Text as T
40import Data.Text.Fusion.Internal (PairS(..))
40import Data.Text.Fusion.Internal (PairS(..))
41−import Data.Text.Lazy.Internal (Text(..))
41+import Data.Text.Lazy.Internal (Text(..), foldlChunks)
42import Data.Bits ((.|.), (.&.))
42import Data.Bits ((.|.), (.&.))
43import Data.Text.UnsafeShift (shiftL)
43import Data.Text.UnsafeShift (shiftL)
@@ -79,7 +79,7 @@ indices needle@(Chunk n ns) haystack@(Chunk k ks)
79 nlen = wordLength needle
79 nlen = wordLength needle
80 nlast = nlen - 1
80 nlast = nlen - 1
81 nindex = index n ns
81 nindex = index n ns
82− z = foldChunks fin 0 needle
82+ z = foldlChunks fin 0 needle
83 where fin _ (T.Text farr foff flen) = A.unsafeIndex farr (foff+flen-1)
83 where fin _ (T.Text farr foff flen) = A.unsafeIndex farr (foff+flen-1)
84 mask :*: skip = buildTable needle
84 mask :*: skip = buildTable needle
85 scanOne c i (T.Text oarr ooff olen) os = go 0
85 scanOne c i (T.Text oarr ooff olen) os = go 0
@@ -104,13 +104,8 @@ index (T.Text arr off len) xs i
104swizzle :: Word16 -> Word64
104swizzle :: Word16 -> Word64
105swizzle k = 1 `shiftL` (fromIntegral k .&. 0x3f)
105swizzle k = 1 `shiftL` (fromIntegral k .&. 0x3f)
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
112wordLength :: Text -> Int64
107wordLength :: Text -> Int64
113−wordLength = foldChunks sumLength 0
108+wordLength = foldlChunks sumLength 0
114 where sumLength i (T.Text _ _ l) = i + fromIntegral l
109 where sumLength i (T.Text _ _ l) = i + fromIntegral l
116buildTable :: Text -> PairS Word64 Int64
111buildTable :: Text -> PairS Word64 Int64
@@ -129,5 +124,5 @@ buildTable needle@(Chunk k ks) = outer k ks 0 0 0 (nlen-2)
129 | otherwise = skip
124 | otherwise = skip
130 xlast = xlen - 1
125 xlast = xlen - 1
131 nlen = wordLength needle
126 nlen = wordLength needle
132− z = foldChunks fin 0 needle
127+ z = foldlChunks fin 0 needle
133 where fin _ (T.Text farr foff flen) = A.unsafeIndex farr (foff+flen-1)
128 where fin _ (T.Text farr foff flen) = A.unsafeIndex farr (foff+flen-1)