@@ -58,6 +58,8 @@ indices _needle@(Text narr noff nlen) _haystack@(Text harr hoff hlen)
58 z = nindex nlast
58 z = nindex nlast
59 nindex k = A.unsafeIndex narr (noff+k)
59 nindex k = A.unsafeIndex narr (noff+k)
60 hindex k = A.unsafeIndex harr (hoff+k)
60 hindex k = A.unsafeIndex harr (hoff+k)
61+ hindex' k | k == hlen = 0
62+ | otherwise = A.unsafeIndex harr (hoff+k)
61 (mask :: Word64) :*: skip = buildTable 0 0 (nlen-2)
63 (mask :: Word64) :*: skip = buildTable 0 0 (nlen-2)
62 buildTable !i !msk !skp
64 buildTable !i !msk !skp
63 | i >= nlast = (msk .|. swizzle z) :*: skp
65 | i >= nlast = (msk .|. swizzle z) :*: skp
@@ -78,7 +80,7 @@ indices _needle@(Text narr noff nlen) _haystack@(Text harr hoff hlen)
78 delta | nextInPattern = nlen + 1
80 delta | nextInPattern = nlen + 1
79 | c == z = skip + 1
81 | c == z = skip + 1
80 | otherwise = 1
82 | otherwise = 1
81− nextInPattern = mask .&. swizzle (hindex (i+nlen)) == 0
83+ nextInPattern = mask .&. swizzle (hindex' (i+nlen)) == 0
82 scanOne c = loop 0
84 scanOne c = loop 0
83 where loop !i | i >= hlen = []
85 where loop !i | i >= hlen = []
84 | hindex i == c = i : loop (i+1)
86 | hindex i == c = i : loop (i+1)