@@ -204,8 +204,22 @@ import Data.Text.Internal (textP)
204import qualified Data.Text.Util as U
204import qualified Data.Text.Util as U
205import Data.Text.Lazy.Search (indices)
205import Data.Text.Lazy.Search (indices)
207+equal :: Text -> Text -> Bool
208+equal Empty Empty = True
209+equal Empty _ = False
210+equal _ Empty = False
211+equal (Chunk a as) (Chunk b bs) =
212+ case compare lenA lenB of
213+ LT -> a == (T.takeWord16 lenA b) &&
214+ as `equal` Chunk (T.dropWord16 lenA b) bs
215+ EQ -> a == b && as `equal` bs
216+ GT -> T.takeWord16 lenB a == b &&
217+ Chunk (T.dropWord16 lenB a) as `equal` bs
218+ where lenA = T.lengthWord16 a
219+ lenB = T.lengthWord16 b
207instance Eq Text where
221instance Eq Text where
208− t1 == t2 = stream t1 == stream t2
222+ (==) = equal
209 {-# INLINE (==) #-}
223 {-# INLINE (==) #-}
211instance Ord Text where
225instance Ord Text where