@@ -49,7 +49,7 @@ module Data.Text.Lazy
52− -- , length
52+ , length
54 -- * Transformations
54 -- * Transformations
@@ -150,8 +150,9 @@ import Prelude (Char, Bool(..), Functor(..), Int, Maybe(..), String,
150 Eq(..), Ord(..), (++),
150 Eq(..), Ord(..), (++),
151 Read(..), Show(..),
151 Read(..), Show(..),
152 (&&), (||), (+), (-), (.), ($),
152 (&&), (||), (+), (-), (.), ($),
153− not, return, otherwise)
153+ fromIntegral, not, return, otherwise)
154import qualified Prelude as P
154import qualified Prelude as P
155+import Data.Int (Int64)
155import Data.String (IsString(..))
156import Data.String (IsString(..))
156import qualified Data.Text as T
157import qualified Data.Text as T
157import qualified Data.Text.Fusion as S
158import qualified Data.Text.Fusion as S
@@ -295,6 +296,18 @@ null _ = False
295 S.null (stream t) = null t
296 S.null (stream t) = null t
299+length :: Text -> Int64
300+length = foldlChunks go 0
301+ where go l t = l + fromIntegral (T.length t)
302+{-# INLINE [1] length #-}
305+"LAZY TEXT length -> fused" [~1] forall t.
306+ length t = S.length64 (stream t)
307+"LAZY TEXT length -> unfused" [1] forall t.
308+ S.length64 (stream t) = length t
298-- | /O(1)/ Returns the last character of a 'Text', which must be
311-- | /O(1)/ Returns the last character of a 'Text', which must be
299-- non-empty. Subject to array fusion.
312-- non-empty. Subject to array fusion.
300last :: Text -> Char
313last :: Text -> Char