double speed of keyFile

Optimising for the common case of nothing needing to be escaped, from 5.434 μs
to 1.727 μs.

In the uncommon case, it only runs around 70 ns slower.
This commit is contained in:
Joey Hess 2019-01-14 20:52:54 -04:00
parent 901fba3173
commit 1b6319a2c8
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38

View file

@ -514,7 +514,11 @@ keyFile :: Key -> FilePath
keyFile = fromRawFilePath . keyFile'
keyFile' :: Key -> RawFilePath
keyFile' = S8.concatMap esc . serializeKey'
keyFile' k =
let b = serializeKey' k
in if any (`S8.elem` b) ['&', '%', ':', '/']
then S8.concatMap esc b
else b
where
esc '&' = "&a"
esc '%' = "&s"