ppad-base58 0.2.0 → 0.2.1
raw patch · 4 files changed
+22/−6 lines, 4 files
Files
- CHANGELOG +3/−0
- bench/Main.hs +3/−3
- lib/Data/ByteString/Base58.hs +15/−2
- ppad-base58.cabal +1/−1
CHANGELOG view
@@ -1,5 +1,8 @@ # Changelog +- 0.2.1 (2025-06-21)+ * Minor performance improvements and internal housekeeping.+ - 0.2.0 (2025-02-18) * The base58check encode and decode functions no longer treat version bytes (of which there may now be several) in any special fashion.
bench/Main.hs view
@@ -8,11 +8,11 @@ main :: IO () main = defaultMain [- base32+ base58 ] -base32 :: Benchmark-base32 = bgroup "ppad-base32" [+base58 :: Benchmark+base58 = bgroup "ppad-base58" [ bgroup "base58" [ bgroup "encode" [ bench "hello world" $ nf B58.encode "hello world"
lib/Data/ByteString/Base58.hs view
@@ -20,11 +20,24 @@ import Data.Bits ((.|.)) import qualified Data.ByteString as BS import qualified Data.ByteString.Unsafe as BU+import Data.Word (Word8) fi :: (Integral a, Num b) => a -> b fi = fromIntegral {-# INLINE fi #-} +-- word8 base58 character to word6 (ish)+word6 :: Word8 -> Maybe Word8+word6 c+ | c >= 49 && c <= 57 = pure $! c - 49 -- 1–9+ | c >= 65 && c <= 72 = pure $! c - 56 -- A–H+ | c >= 74 && c <= 78 = pure $! c - 57 -- J–N+ | c >= 80 && c <= 90 = pure $! c - 58 -- P–Z+ | c >= 97 && c <= 107 = pure $! c - 64 -- a–k+ | c >= 109 && c <= 122 = pure $! c - 65 -- m–z+ | otherwise = Nothing+{-# INLINE word6 #-}+ -- | Encode a base256 'ByteString' as base58. -- -- >>> encode "hello world"@@ -101,8 +114,8 @@ -- from base58 roll_base58 :: BS.ByteString -> Integer roll_base58 bs = BS.foldl' alg 0 bs where- alg !b !a = case BS.elemIndex a base58_charset of+ alg !b !a = case word6 a of Just w -> b * 58 + fi w Nothing ->- error "ppad-base58 (roll_base58): not a base58-encoded bytestring"+ error "ppad-base58 (roll_base58): internal error"
ppad-base58.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.0 name: ppad-base58-version: 0.2.0+version: 0.2.1 synopsis: base58 and base58check encoding/decoding. license: MIT license-file: LICENSE