on master help sign in
Rework splitAt to use our shiny extractified loop
commite339ba9af67d33f294e018db7102e6fabdd91318 authorBryan O'Sullivan <bos@serpentine.com> dateFri 7 Mar 2014, 09:49 (13 years ago) parent5c62b11
1 file changed+2−7
Data/Text.hs+2−7
Data/Text.hs+2−7
@@ -1164,13 +1164,8 @@ splitAt :: Int -> Text -> (Text, Text)
11641164splitAt n t@(Text arr off len)
11651165 | n <= 0 = (empty, t)
11661166 | n >= len = (t, empty)
1167− | otherwise = (Text arr off k, Text arr (off+k) (len-k))
1168− where k = loop 0 0
1169− loop !i !cnt
1170− | i >= len || cnt >= n = i
1171− | otherwise = loop (i+d) (cnt+1)
1172− where d = iter_ t i
1173−{-# INLINE splitAt #-}
1167+ | otherwise = (text arr off k, text arr (off+k) (len-k))
1168+ where k = iterN n t
11741169
11751170-- | /O(n)/ 'span', applied to a predicate @p@ and text @t@, returns
11761171-- a pair whose first element is the longest prefix (possibly empty)