on master help sign in
Make strict takeWhileEnd_null test faster
commit054d273a29be6c7f35028eb0d67f38ea7979de73 authorBryan O'Sullivan <bos@serpentine.com> dateMon 26 Jun 2017, 16:52 (9 years ago) parentddac7b5
2 files changed+16−6
Data/Text/Lazy.hs+4−3 tests/Tests/Properties.hs+12−3
Data/Text/Lazy.hs+4−3
@@ -1153,9 +1153,10 @@ takeWhile p t0 = takeWhile' t0
11531153takeWhileEnd :: (Char -> Bool) -> Text -> Text
11541154takeWhileEnd p = takeChunk empty . L.reverse . toChunks
11551155 where takeChunk acc [] = acc
1156− takeChunk acc (t:ts) = if T.length t' < T.length t
1157− then (Chunk t' acc)
1158− else takeChunk (Chunk t' acc) ts
1156+ takeChunk acc (t:ts)
1157+ | T.lengthWord16 t' < T.lengthWord16 t
1158+ = chunk t' acc
1159+ | otherwise = takeChunk (Chunk t' acc) ts
11591160 where t' = T.takeWhileEnd p t
11601161{-# INLINE takeWhileEnd #-}
11611162
tests/Tests/Properties.hs+12−3
@@ -535,14 +535,20 @@ noMatch = do
535535 d <- suchThat char (/= c)
536536 return (c,d)
537537t_takeWhile p = L.takeWhile p `eqP` (unpackS . T.takeWhile p)
538+t_takeWhile_null n c
539+ = T.null $ T.takeWhile (==c) (T.replicate n (T.singleton c))
538540tl_takeWhile p = L.takeWhile p `eqP` (unpackS . TL.takeWhile p)
541+tl_takeWhile_null n c
542+ = TL.null $
543+ TL.takeWhile (==c) (TL.replicate n (TL.singleton c))
539544t_takeWhileEnd p = (L.reverse . L.takeWhile p . L.reverse) `eqP`
540545 (unpackS . T.takeWhileEnd p)
541−t_takeWhileEnd_null n = forAll noMatch $ \(c,d) -> T.null $
542− T.takeWhileEnd (==d) (T.replicate n (T.singleton c))
546+t_takeWhileEnd_null t = forAll noMatch $ \(c,d) -> T.null $
547+ T.takeWhileEnd (==d) (T.snoc t c)
543548tl_takeWhileEnd p = (L.reverse . L.takeWhile p . L.reverse) `eqP`
544549 (unpackS . TL.takeWhileEnd p)
545− TL.takeWhileEnd (==d) (TL.replicate n (TL.singleton c))
550+tl_takeWhileEnd_null t = forAll noMatch $ \(c,d) -> TL.null $
551+ TL.takeWhileEnd (==d) (TL.snoc t c)
546552s_dropWhile p = L.dropWhile p `eqP` (unpackS . S.dropWhile p)
547553s_dropWhile_s p = L.dropWhile p `eqP` (unpackS . S.unstream . S.dropWhile p)
548554sf_dropWhile q p = (L.dropWhile p . L.filter q) `eqP`
@@ -1170,10 +1176,13 @@ tests =
11701176 testProperty "s_takeWhile_s" s_takeWhile_s,
11711177 testProperty "sf_takeWhile" sf_takeWhile,
11721178 testProperty "t_takeWhile" t_takeWhile,
1179+ testProperty "t_takeWhile_null" t_takeWhile_null,
11731180 testProperty "tl_takeWhile" tl_takeWhile,
1181+ testProperty "tl_takeWhile_null" tl_takeWhile_null,
11741182 testProperty "t_takeWhileEnd" t_takeWhileEnd,
11751183 testProperty "t_takeWhileEnd_null" t_takeWhileEnd_null,
11761184 testProperty "tl_takeWhileEnd" tl_takeWhileEnd,
1185+ testProperty "tl_takeWhileEnd_null" tl_takeWhileEnd_null,
11771186 testProperty "sf_dropWhile" sf_dropWhile,
11781187 testProperty "s_dropWhile" s_dropWhile,
11791188 testProperty "s_dropWhile_s" s_dropWhile_s,