Commits

Bryan O'Sullivan committed 365a2a2

Write an inline Eq instance for strict text

  • Participants
  • Parent commits 038a5d2

Comments (0)

Files changed (1)

File Data/Text.hs

 -- Functions that can be fused by the compiler are marked with the
 -- phrase \"Subject to fusion\".
 
+eq :: Text -> Text -> Bool
+eq (Text arrA offA lenA) (Text arrB offB lenB)
+   | lenA /= lenB = False
+   | otherwise    = go 0
+ where
+   go !n | n == lenA = True
+         | a /= b    = False
+         | otherwise = go (n+1)
+         where a = A.unsafeIndex arrA (offA+n)
+               b = A.unsafeIndex arrB (offB+n)
+{-# INLINE eq #-}
+
 instance Eq Text where
-    t1 == t2 = stream t1 == stream t2
+    (==) = eq
     {-# INLINE (==) #-}
 
 instance Ord Text where