changeset 50158:0d2ec486d95c

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.
author Arseniy Alekseyev <aalekseyev@janestreet.com>
date Thu, 16 Feb 2023 16:20:17 +0000
parents fbb4c7117cf1
children 96d31efd21f7
files rust/hg-core/src/revlog/path_encode.rs
diffstat 1 files changed, 1 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- 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'/');
         }
     }