on master help sign in
Make lazy find faster

--HG-- extra : convert_revision : 6038b4359adad31651b9f8d328a41b879a54d792

commit334d78d775ea49d2c19e0d93341ee305ca93cce5 authorBryan O'Sullivan <bos@serpentine.com> dateFri 23 Jul 2010, 20:38 (16 years ago) parent689bbef
1 file changed+5−3
Data/Text/Lazy.hs+5−3
Data/Text/Lazy.hs+5−3
@@ -940,10 +940,12 @@ find :: Text -- ^ @needle@ to search for
940940 -> [(Text, Text)]
941941find pat src
942942 | null pat = emptyError "find"
943− | otherwise = L.map step (indices pat src)
943+ | otherwise = go 0 empty src (indices pat src)
944944 where
945− step x = let h :*: t = splitAtWord x src
946− in (h, t)
945+ go !n p s (x:xs) = let h :*: t = splitAtWord (x-n) s
946+ h' = append p h
947+ in (h',t) : go x h' t xs
948+ go _ _ _ _ = []
947949
948950-- | /O(n)/ 'breakBy' is like 'spanBy', but the prefix returned is over
949951-- elements that fail the predicate @p@.