Commit ed93c4c8 authored by Bodigrim's avatar Bodigrim
Browse files

Move equal into Data.Text.Internal.Lazy

parent a9d417f9
......@@ -36,12 +36,15 @@ module Data.Text.Internal.Lazy
, defaultChunkSize
, smallChunkSize
, chunkOverhead
, equal
) where
import Data.Bits (shiftL)
import Data.Text ()
import Data.Typeable (Typeable)
import Foreign.Storable (sizeOf)
import qualified Data.Text.Array as A
import qualified Data.Text.Internal as T
data Text = Empty
......@@ -117,3 +120,16 @@ smallChunkSize = 128 - chunkOverhead
chunkOverhead :: Int
chunkOverhead = sizeOf (undefined :: Int) `shiftL` 1
{-# INLINE chunkOverhead #-}
equal :: Text -> Text -> Bool
equal Empty Empty = True
equal Empty _ = False
equal _ Empty = False
equal (Chunk (T.Text arrA offA lenA) as) (Chunk (T.Text arrB offB lenB) bs) =
case compare lenA lenB of
LT -> A.equal arrA offA arrB offB lenA &&
as `equal` Chunk (T.Text arrB (offB + lenA) (lenB - lenA)) bs
EQ -> A.equal arrA offA arrB offB lenA &&
as `equal` bs
GT -> A.equal arrA offA arrB offB lenB &&
Chunk (T.Text arrA (offA + lenB) (lenA - lenB)) as `equal` bs
......@@ -214,7 +214,6 @@ import Data.Monoid (Monoid(..))
import Data.Semigroup (Semigroup(..))
import Data.String (IsString(..))
import qualified Data.Text as T
import qualified Data.Text.Array as A
import qualified Data.Text.Internal as T
import qualified Data.Text.Internal.Fusion.Common as S
import qualified Data.Text.Unsafe as T
......@@ -222,7 +221,7 @@ import qualified Data.Text.Internal.Lazy.Fusion as S
import Data.Text.Internal.Fusion.Types (PairS(..))
import Data.Text.Internal.Lazy.Fusion (stream, unstream)
import Data.Text.Internal.Lazy (Text(..), chunk, empty, foldlChunks,
foldrChunks, smallChunkSize)
foldrChunks, smallChunkSize, equal)
import Data.Text.Internal (firstf, safe, text)
import Data.Text.Lazy.Encoding (decodeUtf8', encodeUtf8)
import Data.Text.Internal.Lazy.Search (indices)
......@@ -275,19 +274,6 @@ import GHC.Stack (HasCallStack)
-- >>> import qualified Data.Text as T
-- >>> :seti -XOverloadedStrings
equal :: Text -> Text -> Bool
equal Empty Empty = True
equal Empty _ = False
equal _ Empty = False
equal (Chunk (T.Text arrA offA lenA) as) (Chunk (T.Text arrB offB lenB) bs) =
case compare lenA lenB of
LT -> A.equal arrA offA arrB offB lenA &&
as `equal` Chunk (T.Text arrB (offB + lenA) (lenB - lenA)) bs
EQ -> A.equal arrA offA arrB offB lenA &&
as `equal` bs
GT -> A.equal arrA offA arrB offB lenB &&
Chunk (T.Text arrA (offA + lenB) (lenA - lenB)) as `equal` bs
instance Eq Text where
(==) = equal
{-# INLINE (==) #-}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment