on master help sign in
Write an inline Eq instance for strict text

--HG-- extra : convert_revision : ac0f0bc2bfdf03ef27103ac490441319d08160aa

commitf5c16910de1606197e2d124724a168186e8a7a52 authorBryan O'Sullivan <bos@serpentine.com> dateTue 19 Oct 2010, 04:57 (16 years ago) parentfd1ebdf
1 file changed+13−1
Data/Text.hs+13−1
Data/Text.hs+13−1
@@ -254,8 +254,20 @@ import Data.Int (Int64)
254254-- Functions that can be fused by the compiler are marked with the
255255-- phrase \"Subject to fusion\".
256256
257+eq :: Text -> Text -> Bool
258+eq (Text arrA offA lenA) (Text arrB offB lenB)
259+ | lenA /= lenB = False
260+ | otherwise = go 0
261+ where
262+ go !n | n == lenA = True
263+ | a /= b = False
264+ | otherwise = go (n+1)
265+ where a = A.unsafeIndex arrA (offA+n)
266+ b = A.unsafeIndex arrB (offB+n)
267+{-# INLINE eq #-}
268+
257269instance Eq Text where
258− t1 == t2 = stream t1 == stream t2
270+ (==) = eq
259271 {-# INLINE (==) #-}
260272
261273instance Ord Text where