on master help sign in
Re-add fusion to definition of uncons

--HG-- extra : convert_revision : 62e494adf8b9c898781eb5bf9b850f68862643e9

commitaa4cdebbe89f2e2a9e716c0e8c4f14bc9a5b4812 authorBryan O'Sullivan <bos@serpentine.com> dateWed 28 Jan 2009, 06:23 (18 years ago) parent9051143
1 file changed+11−1
Data/Text.hs+11−1
Data/Text.hs+11−1
@@ -288,7 +288,17 @@ uncons (Text arr off len)
288288 n = A.unsafeIndex arr (off+1)
289289{-# INLINE uncons #-}
290290
291−-- | /O(n)/ Returns the last character of a 'Text', which must be
291+second :: (b -> c) -> (a,b) -> (a,c)
292+second f (a, b) = (a, f b)
293+
294+{-# RULES
295+"TEXT uncons -> fused" [~1] forall t.
296+ uncons t = fmap (second unstream) (S.uncons (stream t))
297+"TEXT uncons -> unfused" [1] forall t.
298+ fmap (second unstream) (S.uncons (stream t)) = uncons t
299+ #-}
300+
301+-- | /O(1)/ Returns the last character of a 'Text', which must be
292302-- non-empty. Subject to array fusion.
293303last :: Text -> Char
294304last (Text arr off len)