@@ -261,8 +261,7 @@ instance Eq Text where
261 {-# INLINE (==) #-}
261 {-# INLINE (==) #-}
263instance Ord Text where
263instance Ord Text where
264− compare t1 t2 = compare (stream t1) (stream t2)
264+ compare = compareText
265− {-# INLINE compare #-}
267instance Show Text where
266instance Show Text where
268 showsPrec p ps r = showsPrec p (unpack ps) r
267 showsPrec p ps r = showsPrec p (unpack ps) r
@@ -304,6 +303,20 @@ instance Data Text where
304 dataTypeOf _ = mkNorepType "Data.Text.Text"
303 dataTypeOf _ = mkNorepType "Data.Text.Text"
306+-- | /O(n)/ Compare two 'Text' values lexicographically.
307+compareText :: Text -> Text -> Ordering
308+compareText ta@(Text _arrA _offA lenA) tb@(Text _arrB _offB lenB)
309+ | lenA == 0 && lenB == 0 = EQ
310+ | otherwise = go 0 0
313+ | i >= lenA || j >= lenB = compare lenA lenB
316+ | otherwise = go (i+di) (j+dj)
317+ where Iter a di = iter ta i
318+ Iter b dj = iter tb j
307-- -----------------------------------------------------------------------------
320-- -----------------------------------------------------------------------------
308-- * Conversion to/from 'Text'
321-- * Conversion to/from 'Text'