changeset 50162:6baea276a985

rhg: use generic DestArr in hash_mangle This simplifies code a bit more, but comes with an extra memory copy in case [destlen == dest_vec.len()]. This is probably fine, but a follow-up change is removing that too.
author Arseniy Alekseyev <aalekseyev@janestreet.com>
date Thu, 16 Feb 2023 18:46:44 +0000
parents 5d7ba99da3b8
children 11661326b410
files rust/hg-core/src/revlog/path_encode.rs
diffstat 1 files changed, 2 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/rust/hg-core/src/revlog/path_encode.rs	Thu Feb 16 18:45:23 2023 +0000
+++ b/rust/hg-core/src/revlog/path_encode.rs	Thu Feb 16 18:46:44 2023 +0000
@@ -545,8 +545,7 @@
         src[s..].iter().rposition(|b| *b == b'.').map(|i| i + s)
     };
 
-    let mut dest_vec = vec![0; MAXSTOREPATHLEN];
-    let mut dest = Dest::create(&mut dest_vec);
+    let mut dest : DestArr<MAXSTOREPATHLEN> = DestArr::create();
     dest.write_bytes(b"dh/");
 
     if let Some(last_slash) = last_slash {
@@ -590,13 +589,7 @@
     if let Some(l) = last_dot {
         dest.write_bytes(&src[l..]);
     }
-    let destlen = dest.len;
-    if destlen == dest_vec.len() {
-        dest_vec
-    } else {
-        // sometimes the path are shorter than MAXSTOREPATHLEN
-        dest_vec[..destlen].to_vec()
-    }
+    dest.contents().to_vec()
 }
 
 fn hash_encode(src: &[u8]) -> Vec<u8> {