changeset 50161:5d7ba99da3b8

rhg: in path_encode, make DestArr generic over its size
author Arseniy Alekseyev <aalekseyev@janestreet.com>
date Thu, 16 Feb 2023 18:45:23 +0000
parents 5ce53ff6133a
children 6baea276a985
files rust/hg-core/src/revlog/path_encode.rs
diffstat 1 files changed, 8 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/rust/hg-core/src/revlog/path_encode.rs	Thu Feb 16 18:41:06 2023 +0000
+++ b/rust/hg-core/src/revlog/path_encode.rs	Thu Feb 16 18:45:23 2023 +0000
@@ -47,15 +47,15 @@
 
 const MAXENCODE: usize = 4096 * 4;
 
-struct DestArr {
-    buf: [u8; MAXENCODE],
+struct DestArr<const N: usize> {
+    buf: [u8; N],
     pub len: usize,
 }
 
-impl DestArr {
+impl<const N: usize> DestArr<N> {
     pub fn create() -> Self {
         DestArr {
-            buf: [0; MAXENCODE],
+            buf: [0; N],
             len: 0,
         }
     }
@@ -65,7 +65,7 @@
     }
 }
 
-impl Sink for DestArr {
+impl<const N: usize> Sink for DestArr<N> {
     fn write_byte(&mut self, c: u8) {
         self.buf[self.len] = c;
         self.len += 1;
@@ -600,9 +600,9 @@
 }
 
 fn hash_encode(src: &[u8]) -> Vec<u8> {
-    let mut dired = DestArr::create();
-    let mut lowered = DestArr::create();
-    let mut auxed = DestArr::create();
+    let mut dired: DestArr<MAXENCODE> = DestArr::create();
+    let mut lowered: DestArr<MAXENCODE> = DestArr::create();
+    let mut auxed: DestArr<MAXENCODE> = DestArr::create();
     let baselen = (src.len() - 5) * 3;
     if baselen >= MAXENCODE {
         panic!("path_encode::hash_encore: string too long: {}", baselen)