Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support text-2.0 #170

Merged
merged 1 commit into from
Apr 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/Data/Store/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,19 @@ instance Store LBS.ByteString where
peek = fmap LBS.fromStrict peek

instance Store T.Text where
#if MIN_VERSION_text(2,0,0)
size = VarSize $ \x ->
sizeOf (undefined :: Int) +
T.lengthWord8 x
poke x = do
let !(T.Text (TA.ByteArray array) w8Off w8Len) = x
poke w8Len
pokeFromByteArray array w8Off w8Len
peek = do
w8Len <- peek
ByteArray array <- peekToByteArray "Data.Text.Text" w8Len
return (T.Text (TA.ByteArray array) 0 w8Len)
#else
size = VarSize $ \x ->
sizeOf (undefined :: Int) +
2 * (T.lengthWord16 x)
Expand All @@ -454,6 +467,7 @@ instance Store T.Text where
w16Len <- peek
ByteArray array <- peekToByteArray "Data.Text.Text" (2 * w16Len)
return (T.Text (TA.Array array) 0 w16Len)
#endif

------------------------------------------------------------------------
-- Known size instances
Expand Down
2 changes: 1 addition & 1 deletion store-core/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ dependencies:
- bytestring >=0.10.4.0 && < 1.0 # soft
- transformers >=0.3.0.0 && < 1.0 # soft
- ghc-prim >=0.3.1.0 && < 1.0 # soft
- text >=1.2.0.4 && < 2.0 #soft
- text >=1.2.0.4 && < 1.3 || >= 2.0 && < 2.1 #soft

library:
source-dirs: src
Expand Down
2 changes: 1 addition & 1 deletion store-core/store-core.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ library
, bytestring >=0.10.4.0 && <1.0
, ghc-prim >=0.3.1.0 && <1.0
, primitive >=0.6 && <1.0
, text >=1.2.0.4 && <2.0
, text >=1.2.0.4 && <1.3 || >=2.0 && <2.1
, transformers >=0.3.0.0 && <1.0
if flag(force-alignment) || arch(PPC) || arch(PPC64) || arch(Mips) || arch(Sparc) || arch(Arm)
cpp-options: -DALIGNED_MEMORY
Expand Down