commit d249a794ca47cb4e3abe494dcde80767d84b8632 parent 15a7fe19cf9759d28e401debfe138a42525e0be9 Author: Jared Tobin <jared@jtobin.io> Date: Tue, 25 Feb 2025 08:10:23 +0400 lib: minor bytestring optimization Diffstat:
M | lib/Crypto/KDF/PBKDF.hs | | | 10 | ++++++++-- |
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/lib/Crypto/KDF/PBKDF.hs b/lib/Crypto/KDF/PBKDF.hs @@ -25,6 +25,7 @@ import Data.Bits ((.>>.), (.&.)) import qualified Data.Bits as B import qualified Data.ByteString as BS import qualified Data.ByteString.Builder as BSB +import qualified Data.ByteString.Builder.Extra as BE import Data.Word (Word32, Word64) -- NB following synonym really only exists to make haddocks more @@ -105,8 +106,13 @@ derive prf p s c dklen | i == l = let t = f i fin = BS.take r t - in BS.toStrict . BSB.toLazyByteString $ - acc <> BSB.byteString fin + in BS.toStrict $ + if dklen <= 128 + then BE.toLazyByteStringWith + (BE.safeStrategy 128 BE.smallChunkSize) mempty $ + acc <> BSB.byteString fin + else BSB.toLazyByteString $ + acc <> BSB.byteString fin | otherwise = let t = f i nacc = acc <> BSB.byteString t