on master help sign in
Fix bad performance of Data.Text.Lazy.uncons
156d940Bryan O'Sullivan
Data/Text/Lazy.hs+2−2
@@ -174,7 +174,7 @@ module Data.Text.Lazy
174 ) where
174 ) where
175
175
176import Prelude (Char, Bool(..), Maybe(..), String,
176import Prelude (Char, Bool(..), Maybe(..), String,
177− Eq(..), Ord(..), Ordering, Read(..), Show(..),
177+ Eq(..), Ord(..), Ordering(..), Read(..), Show(..),
178 (&&), (+), (-), (.), ($), (++),
178 (&&), (+), (-), (.), ($), (++),
179 div, error, flip, fromIntegral, not, otherwise)
179 div, error, flip, fromIntegral, not, otherwise)
180import qualified Prelude as P
180import qualified Prelude as P
@@ -335,7 +335,7 @@ uncons :: Text -> Maybe (Char, Text)
335uncons Empty = Nothing
335uncons Empty = Nothing
336uncons (Chunk t ts) =
336uncons (Chunk t ts) =
337 Just (T.unsafeHead t,
337 Just (T.unsafeHead t,
338− if T.length t == 1 then ts else Chunk (T.unsafeTail t) ts)
338+ if T.compareLength t 1 == EQ then ts else Chunk (T.unsafeTail t) ts)
339{-# INLINE uncons #-}
339{-# INLINE uncons #-}
340
340
341-- | /O(1)/ Returns the first character of a 'Text', which must be
341-- | /O(1)/ Returns the first character of a 'Text', which must be