refactor: simplify code in rust version of path_encode
Moving the addition of '/' separator to the end of the loop makes the rest
of the logic much simpler because the first iteration is no longer special.
--- a/rust/hg-core/src/revlog/path_encode.rs Mon Feb 20 23:46:20 2023 +0100
+++ b/rust/hg-core/src/revlog/path_encode.rs Thu Feb 16 16:20:17 2023 +0000
@@ -543,25 +543,16 @@
memcopy(Some(&mut dest), &mut destlen, b"dh/");
if let Some(last_slash) = last_slash {
- let mut first = true;
for slice in src[..last_slash].split(|b| *b == b'/') {
let slice = &slice[..std::cmp::min(slice.len(), dirprefixlen)];
- if destlen + (slice.len() + if first { 0 } else { 1 })
- > maxshortdirslen + 3
- {
+ if destlen + slice.len() > maxshortdirslen + 3 {
break;
} else {
- if !first {
- charcopy(Some(&mut dest), &mut destlen, b'/')
- };
memcopy(Some(&mut dest), &mut destlen, slice);
if dest[destlen - 1] == b'.' || dest[destlen - 1] == b' ' {
dest[destlen - 1] = b'_'
}
}
- first = false;
- }
- if !first {
charcopy(Some(&mut dest), &mut destlen, b'/');
}
}