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:
Joey Hess 2025-01-22 12:34:54 -04:00
parent 6211e2af4a
commit f17ec601c4
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
4 changed files with 47 additions and 26 deletions

View file

@ -112,8 +112,8 @@ relatedTemplate f
{- Some filesystems like FAT have issues with filenames
- ending in ".", so avoid truncating a filename to end
- that way. -}
toOsPath $ B.dropWhileEnd (== dot) $ toRawFilePath $
truncateFilePath (len - templateAddedLength) (fromRawFilePath f)
toOsPath $ B.dropWhileEnd (== dot) $
truncateFilePath (len - templateAddedLength) f
| otherwise = toOsPath f
where
len = B.length f