Commits

Bryan O'Sullivan committed d679c01

Fuse length if possible, otherwise run in constant time

  • Participants
  • Parent commits e13e61c

Comments (0)

Files changed (2)

File Data/Text.hs

 -- | /O(n)/ Returns the number of characters in a text.
 -- Subject to array fusion.
 length :: Text -> Int
-length t = S.length (stream t)
-{-# INLINE length #-}
+length (Text _arr _off len) = len
+{-# INLINE [1] length #-}
+
+{-# RULES
+"TEXT length -> fused" [~1] forall t.
+    length t = S.length (stream t)
+"TEXT length -> unfused" [1] forall t.
+    S.length (stream t) = length t
+ #-}
 
 -- -----------------------------------------------------------------------------
 -- * Transformations

File Data/Text/Fusion.hs

                                           cmp (next1 s1') (next2 s2')
 {-# SPECIALISE eq :: Stream Char -> Stream Char -> Bool #-}
 
-
 -- | /O(n) Convert a ByteString into a Stream Char, using the specified encoding standard.
 stream_bs :: Encoding -> ByteString -> Stream Char
 stream_bs ASCII bs = Stream next 0 l