simplify and speed up Utility.FileSystemEncoding

This eliminates the distinction between decodeBS and decodeBS', encodeBS
and encodeBS', etc. The old implementation truncated at NUL, and the
primed versions had to do extra work to avoid that problem. The new
implementation does not truncate at NUL, and is also a lot faster.
(Benchmarked at 2x faster for decodeBS and 3x for encodeBS; more for the
primed versions.)

Note that filepath-bytestring 1.4.2.1.8 contains the same optimisation,
and upgrading to it will speed up to/fromRawFilePath.

AFAIK, nothing relied on the old behavior of truncating at NUL. Some
code used the faster versions in places where I was sure there would not
be a NUL. So this change is unlikely to break anything.

Also, moved s2w8 and w82s out of the module, as they do not involve
filesystem encoding really.

Sponsored-by: Shae Erisson on Patreon
This commit is contained in:
Joey Hess 2021-08-10 20:45:02 -04:00
parent a38b724bfa
commit fa62c98910
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
55 changed files with 138 additions and 217 deletions

View file

@ -292,7 +292,7 @@ verifyLocationLog' key ai present u updatestatus = do
fix InfoMissing
warning $
"** Based on the location log, " ++
decodeBS' (actionItemDesc ai) ++
decodeBS (actionItemDesc ai) ++
"\n** was expected to be present, " ++
"but its content is missing."
return False
@ -332,7 +332,7 @@ verifyRequiredContent key ai@(ActionItemAssociatedFile afile _) = case afile of
missingrequired <- Remote.prettyPrintUUIDs "missingrequired" missinglocs
warning $
"** Required content " ++
decodeBS' (actionItemDesc ai) ++
decodeBS (actionItemDesc ai) ++
" is missing from these repositories:\n" ++
missingrequired
return False
@ -406,7 +406,7 @@ checkKeySizeOr bad key file ai = case fromKey keySize key of
badsize a b = do
msg <- bad key
warning $ concat
[ decodeBS' (actionItemDesc ai)
[ decodeBS (actionItemDesc ai)
, ": Bad file size ("
, compareSizes storageUnits True a b
, "); "
@ -424,11 +424,11 @@ checkKeyUpgrade backend key ai (AssociatedFile (Just file)) =
case Types.Backend.canUpgradeKey backend of
Just a | a key -> do
warning $ concat
[ decodeBS' (actionItemDesc ai)
[ decodeBS (actionItemDesc ai)
, ": Can be upgraded to an improved key format. "
, "You can do so by running: git annex migrate --backend="
, decodeBS (formatKeyVariety (fromKey keyVariety key)) ++ " "
, decodeBS' file
, decodeBS file
]
return True
_ -> return True
@ -475,7 +475,7 @@ checkBackendOr bad backend key file ai =
unless ok $ do
msg <- bad key
warning $ concat
[ decodeBS' (actionItemDesc ai)
[ decodeBS (actionItemDesc ai)
, ": Bad file content; "
, msg
]
@ -503,7 +503,7 @@ checkInodeCache key content mic ai = case mic of
Nothing -> noop
Just ic' -> whenM (compareInodeCaches ic ic') $ do
warning $ concat
[ decodeBS' (actionItemDesc ai)
[ decodeBS (actionItemDesc ai)
, ": Stale or missing inode cache; updating."
]
Database.Keys.addInodeCaches key [ic]