@@ -1004,14 +1004,16 @@ take :: Int -> Text -> Text
10041004take n t@(Text arr off len)
10051005 | n <= 0 = empty
10061006 | n >= len = t
1007− | otherwise = Text arr off (loop 0 0)
1008− where
1009− loop !i !cnt
1010− | i >= len || cnt >= n = i
1011− | otherwise = loop (i+d) (cnt+1)
1012− where d = iter_ t i
1007+ | otherwise = text arr off (iterN n t)
10131008{-# INLINE [1] take #-}
10141009
1010+iterN :: Int -> Text -> Int
1011+iterN n t@(Text _arr _off len) = loop 0 0
1012+ where loop !i !cnt
1013+ | i >= len || cnt >= n = i
1014+ | otherwise = loop (i+d) (cnt+1)
1015+ where d = iter_ t i
1016+
10151017{-# RULES
10161018"TEXT take -> fused" [~1] forall n t.
10171019 take n t = unstream (S.take n (stream t))