Drop support for GHC<9.2 and text<2.0, remove all CPP

This commit is contained in:
Andrew Martin 2024-02-02 20:45:21 -05:00 committed by GitHub
parent a5cdbf965f
commit 0a79b2d0e9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 20 additions and 83 deletions

View file

@ -5,6 +5,12 @@ Note: Prior to version 0.3.4.0, this library was named
`small-bytearray-builder` is now just a compatibility shim `small-bytearray-builder` is now just a compatibility shim
to ease the migration process. to ease the migration process.
## 0.3.16.1 -- 2024-??-??
* Remove all CPP
* Drop support for GHC < 9.4
* Drop support for text < 2.0
## 0.3.16.0 -- 2024-01-29 ## 0.3.16.0 -- 2024-01-29
* Add `wordPaddedDec3`. * Add `wordPaddedDec3`.

View file

@ -1,6 +1,6 @@
cabal-version: 2.2 cabal-version: 2.2
name: bytebuild name: bytebuild
version: 0.3.16.0 version: 0.3.16.1
synopsis: Build byte arrays synopsis: Build byte arrays
description: description:
This is similar to the builder facilities provided by This is similar to the builder facilities provided by
@ -50,7 +50,7 @@ library
reexported-modules: reexported-modules:
Data.Bytes.Chunks Data.Bytes.Chunks
build-depends: build-depends:
, base >=4.12.0.0 && <4.20 , base >=4.17.0.0 && <4.20
, byteslice >=0.2.6 && <0.3 , byteslice >=0.2.6 && <0.3
, bytestring >=0.10.8.2 && <0.13 , bytestring >=0.10.8.2 && <0.13
, haskell-src-meta >=0.8.13 , haskell-src-meta >=0.8.13
@ -103,7 +103,7 @@ test-suite test
, tasty >=1.2.3 && <1.6 , tasty >=1.2.3 && <1.6
, tasty-hunit >=0.10.0.2 && <0.11 , tasty-hunit >=0.10.0.2 && <0.11
, tasty-quickcheck >=0.10.1 && <0.11 , tasty-quickcheck >=0.10.1 && <0.11
, text >=1.2 && <2.2 , text >=2.0 && <2.2
, vector , vector
, wide-word >=0.1.0.9 && <0.2 , wide-word >=0.1.0.9 && <0.2

View file

@ -1,4 +1,3 @@
{-# language CPP #-}
{-# language BangPatterns #-} {-# language BangPatterns #-}
{-# language DataKinds #-} {-# language DataKinds #-}
{-# language DuplicateRecordFields #-} {-# language DuplicateRecordFields #-}
@ -30,10 +29,8 @@ module Data.Bytes.Builder
, insert , insert
, byteArray , byteArray
, shortByteString , shortByteString
#if MIN_VERSION_text(2,0,0)
, textUtf8 , textUtf8
, textJsonString , textJsonString
#endif
, shortTextUtf8 , shortTextUtf8
, shortTextJsonString , shortTextJsonString
, cstring , cstring
@ -196,11 +193,9 @@ import qualified Data.Text.Short as TS
import qualified GHC.Exts as Exts import qualified GHC.Exts as Exts
import qualified Op as Op import qualified Op as Op
#if MIN_VERSION_text(2,0,0)
import Data.Text (Text) import Data.Text (Text)
import qualified Data.Text.Internal as I import qualified Data.Text.Internal as I
import qualified Data.Text.Array as A import qualified Data.Text.Array as A
#endif
-- | Run a builder. -- | Run a builder.
run :: run ::
@ -837,12 +832,10 @@ shortTextUtf8 a =
let ba = shortTextToByteArray a let ba = shortTextToByteArray a
in bytes (Bytes ba 0 (PM.sizeofByteArray ba)) in bytes (Bytes ba 0 (PM.sizeofByteArray ba))
#if MIN_VERSION_text(2,0,0)
-- | Create a builder from text. The text will be UTF-8 encoded. -- | Create a builder from text. The text will be UTF-8 encoded.
textUtf8 :: Text -> Builder textUtf8 :: Text -> Builder
textUtf8 (I.Text (A.ByteArray b) off len) = textUtf8 (I.Text (A.ByteArray b) off len) =
bytes (Bytes (ByteArray b) off len) bytes (Bytes (ByteArray b) off len)
#endif
-- | Create a builder from text. The text will be UTF-8 encoded, -- | Create a builder from text. The text will be UTF-8 encoded,
-- and JSON special characters will be escaped. Additionally, the -- and JSON special characters will be escaped. Additionally, the
@ -858,11 +851,9 @@ shortTextJsonString a =
!(I# len) = PM.sizeofByteArray (ByteArray ba) !(I# len) = PM.sizeofByteArray (ByteArray ba)
in slicedUtf8TextJson ba 0# len in slicedUtf8TextJson ba 0# len
#if MIN_VERSION_text(2,0,0)
textJsonString :: Text -> Builder textJsonString :: Text -> Builder
{-# inline textJsonString #-} {-# inline textJsonString #-}
textJsonString (I.Text (A.ByteArray ba) (I# off) (I# len)) = slicedUtf8TextJson ba off len textJsonString (I.Text (A.ByteArray ba) (I# off) (I# len)) = slicedUtf8TextJson ba off len
#endif
-- | Encodes an unsigned 64-bit integer as decimal. -- | Encodes an unsigned 64-bit integer as decimal.
-- This encoding never starts with a zero unless the -- This encoding never starts with a zero unless the

View file

@ -1,4 +1,3 @@
{-# language CPP #-}
{-# language BangPatterns #-} {-# language BangPatterns #-}
{-# language BinaryLiterals #-} {-# language BinaryLiterals #-}
{-# language DataKinds #-} {-# language DataKinds #-}
@ -241,12 +240,7 @@ doubleDec (D# d) = Builder (\arr off0 s0 -> doubleDec# d arr off0 s0)
-- | Requires up to 19 bytes. Encodes an unsigned 64-bit integer as decimal. -- | Requires up to 19 bytes. Encodes an unsigned 64-bit integer as decimal.
-- This encoding never starts with a zero unless the argument was zero. -- This encoding never starts with a zero unless the argument was zero.
word64Dec :: Word64 -> Builder 19 word64Dec :: Word64 -> Builder 19
word64Dec (W64# w) = wordCommonDec# word64Dec (W64# w) = wordCommonDec# (word64ToWord# w)
#if MIN_VERSION_base(4,17,0)
(word64ToWord# w)
#else
w
#endif
-- | Requires up to 10 bytes. Encodes an unsigned 32-bit integer as decimal. -- | Requires up to 10 bytes. Encodes an unsigned 32-bit integer as decimal.
-- This encoding never starts with a zero unless the argument was zero. -- This encoding never starts with a zero unless the argument was zero.
@ -281,12 +275,7 @@ wordDec (W# w) = wordCommonDec# w
-- Negative numbers are preceded by a minus sign. Positive numbers -- Negative numbers are preceded by a minus sign. Positive numbers
-- are not preceded by anything. -- are not preceded by anything.
int64Dec :: Int64 -> Builder 20 int64Dec :: Int64 -> Builder 20
int64Dec (I64# w) = intCommonDec# int64Dec (I64# w) = intCommonDec# (int64ToInt# w)
#if MIN_VERSION_base(4,17,0)
(int64ToInt# w)
#else
w
#endif
-- | Requires up to 11 bytes. Encodes a signed 32-bit integer as decimal. -- | Requires up to 11 bytes. Encodes a signed 32-bit integer as decimal.
-- This encoding never starts with a zero unless the argument was zero. -- This encoding never starts with a zero unless the argument was zero.
@ -342,12 +331,7 @@ wordCommonDec# w# = Unsafe.construct $ \arr off0 -> if w /= 0
writeByteArray arr off0 (c2w '0') writeByteArray arr off0 (c2w '0')
pure (off0 + 1) pure (off0 + 1)
where where
w = W64# w = W64# (wordToWord64# w#)
#if MIN_VERSION_base(4,17,0)
(wordToWord64# w#)
#else
w#
#endif
internalWordLoop :: MutableByteArray s -> Int -> Word -> ST s Int internalWordLoop :: MutableByteArray s -> Int -> Word -> ST s Int
{-# inline internalWordLoop #-} {-# inline internalWordLoop #-}
@ -379,12 +363,7 @@ intCommonDec# w# = Unsafe.construct $ \arr off0 -> case compare w 0 of
writeByteArray arr off0 (c2w '-') writeByteArray arr off0 (c2w '-')
internalWordLoop arr (off0 + 1) (fromIntegral (negate w)) internalWordLoop arr (off0 + 1) (fromIntegral (negate w))
where where
w = I64# w = I64# (intToInt64# w#)
#if MIN_VERSION_base(4,17,0)
(intToInt64# w#)
#else
w#
#endif
-- Convert a number between 0 and 16 to the ASCII -- Convert a number between 0 and 16 to the ASCII
-- representation of its hexadecimal character. -- representation of its hexadecimal character.
@ -456,25 +435,14 @@ word128PaddedUpperHex (Word128 w64 w0) =
-- uppercase for the alphabetical digits. For example, this encodes the -- uppercase for the alphabetical digits. For example, this encodes the
-- number 1022 as @00000000000003FE@. -- number 1022 as @00000000000003FE@.
word64PaddedUpperHex :: Word64 -> Builder 16 word64PaddedUpperHex :: Word64 -> Builder 16
word64PaddedUpperHex (W64# w) = word64PaddedUpperHex# word64PaddedUpperHex (W64# w) = word64PaddedUpperHex# (word64ToWord# w)
#if MIN_VERSION_base(4,17,0)
(word64ToWord# w)
#else
w
#endif
-- | Requires exactly 16 bytes. Encodes a 64-bit unsigned integer as -- | Requires exactly 16 bytes. Encodes a 64-bit unsigned integer as
-- hexadecimal, zero-padding the encoding to 16 digits. This uses -- hexadecimal, zero-padding the encoding to 16 digits. This uses
-- lowercase for the alphabetical digits. For example, this encodes the -- lowercase for the alphabetical digits. For example, this encodes the
-- number 1022 as @00000000000003fe@. -- number 1022 as @00000000000003fe@.
word64PaddedLowerHex :: Word64 -> Builder 16 word64PaddedLowerHex :: Word64 -> Builder 16
word64PaddedLowerHex (W64# w) = word64PaddedLowerHex# word64PaddedLowerHex (W64# w) = word64PaddedLowerHex# (word64ToWord# w)
#if MIN_VERSION_base(4,17,0)
(word64ToWord# w)
#else
w
#endif
-- | Requires exactly 12 bytes. Discards the upper 16 bits of a -- | Requires exactly 12 bytes. Discards the upper 16 bits of a
-- 64-bit unsigned integer and then encodes the lower 48 bits as -- 64-bit unsigned integer and then encodes the lower 48 bits as
@ -482,12 +450,7 @@ word64PaddedLowerHex (W64# w) = word64PaddedLowerHex#
-- lowercase for the alphabetical digits. For example, this encodes the -- lowercase for the alphabetical digits. For example, this encodes the
-- number 1022 as @0000000003fe@. -- number 1022 as @0000000003fe@.
word48PaddedLowerHex :: Word64 -> Builder 12 word48PaddedLowerHex :: Word64 -> Builder 12
word48PaddedLowerHex (W64# w) = word48PaddedLowerHex# word48PaddedLowerHex (W64# w) = word48PaddedLowerHex# (word64ToWord# w)
#if MIN_VERSION_base(4,17,0)
(word64ToWord# w)
#else
w
#endif
-- | Requires exactly 8 bytes. Encodes a 32-bit unsigned integer as -- | Requires exactly 8 bytes. Encodes a 32-bit unsigned integer as
-- hexadecimal, zero-padding the encoding to 8 digits. This uses -- hexadecimal, zero-padding the encoding to 8 digits. This uses
@ -920,13 +883,7 @@ word32Vlq (W32# w) = vlqCommon (W# (C.word32ToWord# w))
-- | Encode a 64-bit word with VLQ (also known as VByte, Varint, VInt). -- | Encode a 64-bit word with VLQ (also known as VByte, Varint, VInt).
word64Vlq :: Word64 -> Builder 10 word64Vlq :: Word64 -> Builder 10
{-# inline word64Vlq #-} {-# inline word64Vlq #-}
word64Vlq (W64# w) = vlqCommon (W# word64Vlq (W64# w) = vlqCommon (W# (word64ToWord# w))
#if MIN_VERSION_base(4,17,0)
(word64ToWord# w)
#else
w
#endif
)
-- | Encode a machine-sized word with LEB-128. -- | Encode a machine-sized word with LEB-128.
wordLEB128 :: Word -> Builder 10 wordLEB128 :: Word -> Builder 10
@ -946,13 +903,7 @@ word32LEB128 (W32# w) = lebCommon (W# (C.word32ToWord# w))
-- | Encode a 64-bit word with LEB-128. -- | Encode a 64-bit word with LEB-128.
word64LEB128 :: Word64 -> Builder 10 word64LEB128 :: Word64 -> Builder 10
{-# inline word64LEB128 #-} {-# inline word64LEB128 #-}
word64LEB128 (W64# w) = lebCommon (W# word64LEB128 (W64# w) = lebCommon (W# (word64ToWord# w))
#if MIN_VERSION_base(4,17,0)
(word64ToWord# w)
#else
w
#endif
)
vlqCommon :: Word -> Builder n vlqCommon :: Word -> Builder n
vlqCommon !w = case w of vlqCommon !w = case w of
@ -1043,12 +994,7 @@ char c
byteFourFour w = (0b00111111 .&. w) .|. 0b10000000 byteFourFour w = (0b00111111 .&. w) .|. 0b10000000
int64BE :: Int64 -> Builder 8 int64BE :: Int64 -> Builder 8
int64BE (I64# i) = word64BE (W64# ( int64BE (I64# i) = word64BE (W64# ( wordToWord64# (int2Word# (int64ToInt# i))))
#if MIN_VERSION_base(4,17,0)
wordToWord64# (int2Word# (int64ToInt# i))))
#else
int2Word# i))
#endif
int32BE :: Int32 -> Builder 4 int32BE :: Int32 -> Builder 4
int32BE (I32# i) = word32BE (W32# (C.wordToWord32# (int2Word# (C.int32ToInt# i)))) int32BE (I32# i) = word32BE (W32# (C.wordToWord32# (int2Word# (C.int32ToInt# i))))
@ -1057,13 +1003,7 @@ int16BE :: Int16 -> Builder 2
int16BE (I16# i) = word16BE (W16# (C.wordToWord16# (int2Word# (C.int16ToInt# i)))) int16BE (I16# i) = word16BE (W16# (C.wordToWord16# (int2Word# (C.int16ToInt# i))))
int64LE :: Int64 -> Builder 8 int64LE :: Int64 -> Builder 8
int64LE (I64# i) = word64LE (W64# ( int64LE (I64# i) = word64LE (W64# ( wordToWord64# (int2Word# (int64ToInt# i))))
#if MIN_VERSION_base(4,17,0)
wordToWord64# (int2Word# (int64ToInt# i))))
#else
int2Word# i))
#endif
int32LE :: Int32 -> Builder 4 int32LE :: Int32 -> Builder 4
int32LE (I32# i) = word32LE (W32# (C.wordToWord32# (int2Word# (C.int32ToInt# i)))) int32LE (I32# i) = word32LE (W32# (C.wordToWord32# (int2Word# (C.int32ToInt# i))))