on master help sign in
Fuse length if possible, otherwise run in constant time

--HG-- extra : convert_revision : 1a94b67a8171ce1bfed9b895b961485a07bb0720

commit0ef24248bc4e7c0b1ab8383e689ee9ebcc856ba0 authorBryan O'Sullivan <bos@serpentine.com> dateTue 20 Jan 2009, 07:42 (18 years ago) parentff43615
2 files changed+9−3
Data/Text.hs+9−2 Data/Text/Fusion.hs−1
Data/Text.hs+9−2
@@ -254,8 +254,15 @@ null t = S.null (stream t)
254254-- | /O(n)/ Returns the number of characters in a text.
255255-- Subject to array fusion.
256256length :: Text -> Int
257−length t = S.length (stream t)
258−{-# INLINE length #-}
257+length (Text _arr _off len) = len
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+ #-}
259266
260267-- -----------------------------------------------------------------------------
261268-- * Transformations
Data/Text/Fusion.hs−1
@@ -167,7 +167,6 @@ eq (Stream next1 s1 _) (Stream next2 s2 _) = cmp (next1 s1) (next2 s2)
167167 cmp (next1 s1') (next2 s2')
168168{-# SPECIALISE eq :: Stream Char -> Stream Char -> Bool #-}
169169
170−
171170-- | /O(n) Convert a ByteString into a Stream Char, using the specified encoding standard.
172171stream_bs :: Encoding -> ByteString -> Stream Char
173172stream_bs ASCII bs = Stream next 0 l