Inline pragmas for better LEB encoding perf
This commit is contained in:
parent
dde5a9b07d
commit
5fb3bdbeaa
3 changed files with 16 additions and 0 deletions
|
@ -1162,14 +1162,17 @@ int64LEB128 = word64LEB128 . toZigzag64
|
|||
|
||||
-- | Encode a machine-sized word with LEB-128.
|
||||
wordLEB128 :: Word -> Builder
|
||||
{-# inline wordLEB128 #-}
|
||||
wordLEB128 w = fromBounded Nat.constant (Bounded.wordLEB128 w)
|
||||
|
||||
-- | Encode a 32-bit word with LEB-128.
|
||||
word32LEB128 :: Word32 -> Builder
|
||||
{-# inline word32LEB128 #-}
|
||||
word32LEB128 w = fromBounded Nat.constant (Bounded.word32LEB128 w)
|
||||
|
||||
-- | Encode a 64-bit word with LEB-128.
|
||||
word64LEB128 :: Word64 -> Builder
|
||||
{-# inline word64LEB128 #-}
|
||||
word64LEB128 w = fromBounded Nat.constant (Bounded.word64LEB128 w)
|
||||
|
||||
-- | Encode a signed arbitrary-precision integer as decimal.
|
||||
|
|
|
@ -851,14 +851,17 @@ ascii8 (C# c0) (C# c1) (C# c2) (C# c3) (C# c4) (C# c5) (C# c6) (C# c7) = Unsafe.
|
|||
|
||||
-- | Encode a machine-sized word with LEB-128.
|
||||
wordLEB128 :: Word -> Builder 10
|
||||
{-# inline wordLEB128 #-}
|
||||
wordLEB128 (W# w) = lebCommon (W# w)
|
||||
|
||||
-- | Encode a 32-bit word with LEB-128.
|
||||
word32LEB128 :: Word32 -> Builder 5
|
||||
{-# inline word32LEB128 #-}
|
||||
word32LEB128 (W32# w) = lebCommon (W# (C.word32ToWord# w))
|
||||
|
||||
-- | Encode a 64-bit word with LEB-128.
|
||||
word64LEB128 :: Word64 -> Builder 10
|
||||
{-# inline word64LEB128 #-}
|
||||
word64LEB128 (W64# w) = lebCommon (W# w)
|
||||
|
||||
lebCommon :: Word -> Builder n
|
||||
|
|
10
test/Main.hs
10
test/Main.hs
|
@ -255,6 +255,16 @@ tests = testGroup "Tests"
|
|||
runConcat 1 (naturalDec y)
|
||||
===
|
||||
pack (show y)
|
||||
, testGroup "leb128-encoding"
|
||||
[ THU.testCase "16" $
|
||||
Chunks.concat (run 16 (word64LEB128 16))
|
||||
@=?
|
||||
Latin1.fromString "\x10"
|
||||
, THU.testCase "deadbeef-smile" $ do
|
||||
let inp = Latin1.fromString "\xDE\xAD\xBE\xEF"
|
||||
(Chunks.concat . run 16) (sevenEightSmile inp)
|
||||
@=?Latin1.fromString "\x6F\x2B\x37\x6E\x0F"
|
||||
]
|
||||
, testGroup "seven/eight encoding"
|
||||
[ THU.testCase "deadbeef" $ do
|
||||
let inp = Latin1.fromString "\xDE\xAD\xBE\xEF"
|
||||
|
|
Loading…
Reference in a new issue