    {-# LANGUAGE CPP #-}

    module IsomorphismClass.TextCompat.Array where

    import qualified Data.ByteString.Short
    import qualified Data.ByteString.Short.Internal
    import qualified Data.Primitive.ByteArray
    import Data.Text.Array
    import GHC.Exts (ByteArray#)

    {-# INLINE toUnliftedByteArray #-}
    toUnliftedByteArray :: Array -> ByteArray#
    #if MIN_VERSION_text(2,0,0)
    toUnliftedByteArray :: Array -> ByteArray#
    toUnliftedByteArray (ByteArray ByteArray#
    a) = ByteArray#
    a
    #else
    toUnliftedByteArray (Array a) = a
    #endif

    {-# INLINE fromUnliftedByteArray #-}
    fromUnliftedByteArray :: ByteArray# -> Array
    #if MIN_VERSION_text(2,0,0)
    fromUnliftedByteArray :: ByteArray# -> Array
    fromUnliftedByteArray = ByteArray# -> Array
    ByteArray
    #else
    fromUnliftedByteArray = Array
    #endif

    {-# INLINE fromShortByteString #-}
    fromShortByteString :: Data.ByteString.Short.ShortByteString -> Array
    fromShortByteString :: ShortByteString -> Array
    fromShortByteString (Data.ByteString.Short.Internal.SBS ByteArray#
    arr) =
      ByteArray# -> Array
    fromUnliftedByteArray ByteArray#
    arr

    {-# INLINE toShortByteString #-}
    toShortByteString :: Array -> Data.ByteString.Short.ShortByteString
    toShortByteString :: Array -> ShortByteString
    toShortByteString Array
    a =
      ByteArray# -> ShortByteString
    Data.ByteString.Short.Internal.SBS (Array -> ByteArray#
    toUnliftedByteArray Array
    a)

    {-# INLINE fromByteArray #-}
    fromByteArray :: Data.Primitive.ByteArray.ByteArray -> Array
    fromByteArray :: Array -> Array
    fromByteArray (Data.Primitive.ByteArray.ByteArray ByteArray#
    arr) =
      ByteArray# -> Array
    fromUnliftedByteArray ByteArray#
    arr

    {-# INLINE toByteArray #-}
    toByteArray :: Array -> Data.Primitive.ByteArray.ByteArray
    toByteArray :: Array -> Array
    toByteArray Array
    a =
      ByteArray# -> Array
    Data.Primitive.ByteArray.ByteArray (Array -> ByteArray#
    toUnliftedByteArray Array
    a)