From: Joey Hess Date: Mon, 15 Sep 2025 17:49:14 +0000 (-0400) Subject: small optimisation X-Git-Tag: archive/raspbian/10.20251029-1+rpi1~1^2~3^2~111 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=829223a6e7838f77af3006413db23c3f62e072f9;p=git-annex.git small optimisation --- diff --git a/Utility/Tmp.hs b/Utility/Tmp.hs index df6673eadd..332b949048 100644 --- a/Utility/Tmp.hs +++ b/Utility/Tmp.hs @@ -126,17 +126,20 @@ relatedTemplate' f {- Some filesystems like FAT have issues with filenames - ending in ".", and others like VFAT don't allow a - filename to end with trailing whitespace, so avoid - - truncating a filename to end that way. -} - fixend p = - {- B.dropWhileEnd doesn't take wide characters - - into account, but is fast, so use it to check - - the common case. -} - let p' = B.dropWhileEnd disallowed p - in if p' == p - then p - else toRawFilePath $ reverse $ + - truncating a filename to end that way. + - + - Checking with unsnoc for the path to end with a disallowed + - character doesn't take wide characters into account, + - so will have false positives, but it is fast. + -} + fixend p = case B.unsnoc p of + Just (_, c) | disallowed c -> + -- Convert to String to take wide characters into + -- account. + toRawFilePath $ reverse $ dropWhile (disallowed . fromIntegral . ord) $ reverse $ fromRawFilePath p + _ -> p dot = fromIntegral (ord '.') disallowed c = c == dot || isSpace (chr (fromIntegral c)) #else