on master help sign in
Write an inline Eq instance for strict text
f5c1691Bryan O'Sullivan
Data/Text.hs+13−1
@@ -254,8 +254,20 @@ import Data.Int (Int64)
254-- Functions that can be fused by the compiler are marked with the
254-- Functions that can be fused by the compiler are marked with the
255-- phrase \"Subject to fusion\".
255-- phrase \"Subject to fusion\".
256
256
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+
257instance Eq Text where
269instance Eq Text where
258− t1 == t2 = stream t1 == stream t2
270+ (==) = eq
259 {-# INLINE (==) #-}
271 {-# INLINE (==) #-}
260
272
261instance Ord Text where
273instance Ord Text where