optimize truncateFilePath
Often the filepath will be all ascii, or mostly so, and this optimisation makes a file that has an ascii suffix of sufficient length be roundtrip converted between String and ByteString only once, rather than once per character. Sponsored-by: Graham Spencer
This commit is contained in:
parent
6211e2af4a
commit
f17ec601c4
4 changed files with 47 additions and 26 deletions
|
@ -29,12 +29,12 @@ import Data.Word
|
|||
genKeyName :: String -> S.ShortByteString
|
||||
genKeyName s
|
||||
-- Avoid making keys longer than the length of a SHA256 checksum.
|
||||
| bytelen > sha256len = S.toShort $ encodeBS $
|
||||
truncateFilePath (sha256len - md5len - 1) s' ++ "-" ++
|
||||
show (md5 bl)
|
||||
| otherwise = S.toShort $ encodeBS s'
|
||||
| bytelen > sha256len = S.toShort $
|
||||
truncateFilePath (sha256len - md5len - 1) s'
|
||||
<> "-" <> encodeBS (show (md5 bl))
|
||||
| otherwise = S.toShort s'
|
||||
where
|
||||
s' = preSanitizeKeyName s
|
||||
s' = encodeBS $ preSanitizeKeyName s
|
||||
bl = encodeBL s
|
||||
bytelen = fromIntegral $ L.length bl
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue