rhg: in path_encode, make DestArr generic over its size
authorArseniy Alekseyev <aalekseyev@janestreet.com>
Thu, 16 Feb 2023 18:45:23 +0000
changeset 50161 5d7ba99da3b8
parent 50160 5ce53ff6133a
child 50162 6baea276a985
rhg: in path_encode, make DestArr generic over its size
rust/hg-core/src/revlog/path_encode.rs
--- 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)