@@ -33,6 +33,7 @@ module Data.Text.Array
3333 , copyM
3434 , copyI
3535 , empty
36+ , equal
3637#if defined(ASSERTS)
3738 , length
3839#endif
@@ -265,3 +266,31 @@ copyI dest i0 src j0 top
265266 | i >= top = return ()
266267 | otherwise = do unsafeWrite dest i (src `unsafeIndex` j)
267268 slow (i+1) (j+1)
269+
270+-- | Compare portions of two arrays for equality. No bounds checking
271+-- is performed.
272+equal :: Array -- ^ First
273+ -> Int -- ^ Offset into first
274+ -> Array -- ^ Second
275+ -> Int -- ^ Offset into second
276+ -> Int -- ^ Count
277+ -> Bool
278+equal arrA offA arrB offB count
279+ | wordAligned offA && wordAligned offB = fast 0
280+ | otherwise = slow 0
281+ where
282+ countWords = count `div` wordFactor
283+ fast !i
284+ | i >= countWords = slow (i * wordFactor)
285+ | a /= b = False
286+ | otherwise = fast (i+1)
287+ where a = unsafeIndexWord arrA (offAW+i)
288+ b = unsafeIndexWord arrB (offBW+i)
289+ offAW = offA `div` wordFactor
290+ offBW = offB `div` wordFactor
291+ slow !i
292+ | i >= count = True
293+ | a /= b = False
294+ | otherwise = slow (i+1)
295+ where a = unsafeIndex arrA (offA+i)
296+ b = unsafeIndex arrB (offB+i)