about summary refs log tree commit diff
path: root/tvix/store/src/nixbase32.rs
diff options
context:
space:
mode:
authoredef <edef@edef.eu>2022-12-30T13·53+0000
committeredef <edef@edef.eu>2022-12-30T16·40+0000
commit51243007f67019d0d57b6cfaff2aec3191afa180 (patch)
treeeb63eda0b7aa558149ab271c63d357a25b71e839 /tvix/store/src/nixbase32.rs
parent60bdf619a38f05f8a8815feffc562b0e5c40143f (diff)
refactor(tvix/store): make nixbase32 reversal more idiomatic r/5556
Change-Id: Ibe550f9573b0f45ee95453b50c7510e49b07c719
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7685
Reviewed-by: tazjin <tazjin@tvl.su>
Reviewed-by: flokli <flokli@flokli.de>
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
Diffstat (limited to 'tvix/store/src/nixbase32.rs')
-rw-r--r--tvix/store/src/nixbase32.rs11
1 files changed, 4 insertions, 7 deletions
diff --git a/tvix/store/src/nixbase32.rs b/tvix/store/src/nixbase32.rs
index 8be9f1b6ea19..070b677583ff 100644
--- a/tvix/store/src/nixbase32.rs
+++ b/tvix/store/src/nixbase32.rs
@@ -36,8 +36,7 @@ impl Nixbase32Encoding {
     /// Returns encoded input
     pub fn encode(&self, input: &[u8]) -> String {
         // Reverse the input, reading in the bytes in reverse order.
-        let mut reversed = Vec::with_capacity(input.len());
-        reversed.extend(input.iter().rev());
+        let reversed: Vec<u8> = input.iter().cloned().rev().collect();
         self.encoding.encode(&reversed)
     }
 
@@ -45,11 +44,9 @@ impl Nixbase32Encoding {
     /// Check [data_encoding::Encoding::encode] for the error cases.
     pub fn decode(&self, input: &[u8]) -> Result<Vec<u8>, DecodeError> {
         // Decode first, then reverse the bytes of the output.
-        let output = self.encoding.decode(input)?;
-
-        let mut reversed = Vec::with_capacity(output.len());
-        reversed.extend(output.iter().rev());
-        Ok(reversed)
+        let mut output = self.encoding.decode(&input)?;
+        output.reverse();
+        Ok(output)
     }
 
     /// Returns the decoded length of an input of length len.