on master help sign in
Fuse length if possible, otherwise run in constant time
0ef2424Bryan O'Sullivan
Data/Text.hs+9−2
@@ -254,8 +254,15 @@ null t = S.null (stream t)
254-- | /O(n)/ Returns the number of characters in a text.
254-- | /O(n)/ Returns the number of characters in a text.
255-- Subject to array fusion.
255-- Subject to array fusion.
256length :: Text -> Int
256length :: Text -> Int
257−length t = S.length (stream t)
257+length (Text _arr _off len) = len
258−{-# INLINE length #-}
258+{-# INLINE [1] length #-}
259+
260+{-# RULES
261+"TEXT length -> fused" [~1] forall t.
262+ length t = S.length (stream t)
263+"TEXT length -> unfused" [1] forall t.
264+ S.length (stream t) = length t
265+ #-}
259
266
260-- -----------------------------------------------------------------------------
267-- -----------------------------------------------------------------------------
261-- * Transformations
268-- * Transformations
Data/Text/Fusion.hs−1
@@ -167,7 +167,6 @@ eq (Stream next1 s1 _) (Stream next2 s2 _) = cmp (next1 s1) (next2 s2)
167 cmp (next1 s1') (next2 s2')
167 cmp (next1 s1') (next2 s2')
168{-# SPECIALISE eq :: Stream Char -> Stream Char -> Bool #-}
168{-# SPECIALISE eq :: Stream Char -> Stream Char -> Bool #-}
169
169
170−
171-- | /O(n) Convert a ByteString into a Stream Char, using the specified encoding standard.
170-- | /O(n) Convert a ByteString into a Stream Char, using the specified encoding standard.
172stream_bs :: Encoding -> ByteString -> Stream Char
171stream_bs :: Encoding -> ByteString -> Stream Char
173stream_bs ASCII bs = Stream next 0 l
172stream_bs ASCII bs = Stream next 0 l