packages feed

text-short 0.1.4 → 0.1.5

raw patch · 4 files changed

+57/−12 lines, 4 filesdep −quickcheck-instancesdep ~basedep ~bytestringdep ~deepseq

Dependencies removed: quickcheck-instances

Dependency ranges changed: base, bytestring, deepseq, ghc-prim, tasty, template-haskell, text

Files

ChangeLog.md view
@@ -1,3 +1,7 @@+## 0.1.5++  * text-2.0 support+ ## 0.1.4    * Fix `fromString` for single character strings.
src-test/Tests.hs view
@@ -2,6 +2,7 @@ {-# LANGUAGE OverloadedLists   #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE TemplateHaskell   #-}+{-# OPTIONS_GHC -fno-warn-orphans #-}  #ifndef MIN_VERSION_GLASGOW_HASKELL #define MIN_VERSION_GLASGOW_HASKELL(x,y,z,w) ((x*100 + y) >= __GLASGOW_HASKELL__)@@ -14,11 +15,11 @@ import           Data.Maybe import           Data.Monoid import qualified Data.String               as D.S+import qualified Data.ByteString           as BS import qualified Data.Text                 as T import qualified Data.Text.Encoding        as T import qualified Data.Text.Short           as IUT import qualified Data.Text.Short.Partial   as IUT-import           Test.QuickCheck.Instances () import           Test.Tasty import           Test.Tasty.HUnit import           Test.Tasty.QuickCheck     as QC@@ -259,3 +260,18 @@ {-# NOINLINE testLit8 #-} testLit8 :: IUT.ShortText testLit8 = "\x7f"++-------------------------------------------------------------------------------+-- orphans+-------------------------------------------------------------------------------++-- orphan instances to not depend on quickcheck-instances+-- which would cause cycles++instance Arbitrary BS.ByteString where+    arbitrary = BS.pack `fmap` arbitrary+    shrink xs = BS.pack `fmap` shrink (BS.unpack xs)++instance Arbitrary T.Text where+    arbitrary = T.pack `fmap` arbitrary+    shrink xs = T.pack `fmap` shrink (T.unpack xs)
src/Data/Text/Short/Internal.hs view
@@ -126,7 +126,6 @@ import           Data.Semigroup import qualified Data.String                    as S import qualified Data.Text                      as T-import qualified Data.Text.Encoding             as T import           Foreign.C import           GHC.Base                       (assert, unsafeChr) import qualified GHC.CString                    as GHC@@ -149,6 +148,13 @@  import qualified Language.Haskell.TH.Syntax     as TH +#if MIN_VERSION_text(2,0,0)+import qualified Data.Text.Internal             as TI+import qualified Data.Text.Array                as TA+#else+import qualified Data.Text.Encoding             as T+#endif+ import qualified PrimOps  -- | A compact representation of Unicode strings.@@ -653,12 +659,16 @@ -- -- prop> (toText . fromText) t == t ----- This is currently not \(\mathcal{O}(1)\) because currently 'T.Text' uses UTF-16 as its internal representation.--- In the event that 'T.Text' will change its internal representation to UTF-8 this operation will become \(\mathcal{O}(1)\).+-- This is \(\mathcal{O}(1)\) with @text-2@.+-- Previously it wasn't because 'T.Text' used UTF-16 as its internal representation. -- -- @since 0.1 toText :: ShortText -> T.Text+#if MIN_VERSION_text(2,0,0)+toText (ShortText (BSSI.SBS ba)) = TI.Text (TA.ByteArray ba) 0 (I# (GHC.Exts.sizeofByteArray# ba))+#else toText = T.decodeUtf8 . toByteString+#endif  ---- @@ -692,7 +702,22 @@ -- -- @since 0.1 fromText :: T.Text -> ShortText+#if MIN_VERSION_text(2,0,0)+fromText (TI.Text (TA.ByteArray ba) off len) =+    ShortText (BSSI.SBS (case sliceByteArray (TA.ByteArray ba) off len of TA.ByteArray ba' -> ba'))++sliceByteArray :: TA.Array -> Int -> Int -> TA.Array+sliceByteArray ta@(TA.ByteArray ba) 0 len+    | len == I# (GHC.Exts.sizeofByteArray# ba)+    = ta+sliceByteArray ta off len = TA.run $ do+    ma <- TA.new len+    TA.copyI len ma 0 ta off+    return ma++#else fromText = fromByteStringUnsafe . T.encodeUtf8+#endif  -- | \(\mathcal{O}(n)\) Construct 'ShortText' from UTF-8 encoded 'ShortByteString' --
text-short.cabal view
@@ -1,6 +1,6 @@ cabal-version:       1.18 name:                text-short-version:             0.1.4+version:             0.1.5 synopsis:            Memory-efficient representation of Unicode text strings license:             BSD3 license-file:        LICENSE@@ -13,7 +13,7 @@                      .                      The main difference between 'Text' and 'ShortText' is that 'ShortText' uses UTF-8 instead of UTF-16 internally and also doesn't support zero-copy slicing (thereby saving 2 words). Consequently, the memory footprint of a (boxed) 'ShortText' value is 4 words (2 words when unboxed) plus the length of the UTF-8 encoded payload. -tested-with:         GHC==9.0.1, GHC==8.10.4, GHC==8.8.3, GHC==8.6.5, GHC==8.4.4, GHC==8.2.2, GHC==8.0.2, GHC==7.10.3, GHC==7.8.4, GHC==9.2.0.20210821+tested-with:         GHC==9.0.1, GHC==8.10.4, GHC==8.8.3, GHC==8.6.5, GHC==8.4.4, GHC==8.2.2, GHC==8.0.2, GHC==7.10.3, GHC==7.8.4, GHC==9.2.1 extra-source-files:  ChangeLog.md  Source-Repository head@@ -34,9 +34,9 @@    build-depends:       base        >= 4.7    && < 4.17                      , bytestring  >= 0.10.4 && < 0.12-                     , hashable    >= 1.2.6  && < 1.4+                     , hashable    >= 1.2.6  && < 1.5                      , deepseq     >= 1.3    && < 1.5-                     , text        >= 1.0    && < 1.3+                     , text        >= 1.0    && < 1.3 || >=2.0 && <2.1                      , binary      >= 0.7.1  && < 0.9                      , ghc-prim    >= 0.3.1  && < 0.9                      , template-haskell >= 2.9.0.0 && <2.19@@ -45,7 +45,7 @@     build-depends: bytestring >= 0.10.8.0    if !impl(ghc >= 8.0)-     build-depends: semigroups >= 0.18.2 && < 0.20+     build-depends: semigroups >= 0.18.2 && < 0.21    -- GHC version specific PrimOps   if impl(ghc >= 8.4)@@ -92,10 +92,10 @@                , text                , text-short                , template-haskell-                 -- deps which don't inherit constraints from library stanza:-               , tasty                >= 1.0.0  && < 1.5++  -- deps which don't inherit constraints from library stanza:+  build-depends: tasty                >= 1.4    && < 1.5                , tasty-quickcheck     >= 0.10   && < 0.11                , tasty-hunit          >= 0.10.0 && < 0.11-               , quickcheck-instances >= 0.3.14 && < 0.4    default-language:    Haskell2010