From 51243007f67019d0d57b6cfaff2aec3191afa180 Mon Sep 17 00:00:00 2001 From: edef Date: Fri, 30 Dec 2022 13:53:23 +0000 Subject: refactor(tvix/store): make nixbase32 reversal more idiomatic Change-Id: Ibe550f9573b0f45ee95453b50c7510e49b07c719 Reviewed-on: https://cl.tvl.fyi/c/depot/+/7685 Reviewed-by: tazjin Reviewed-by: flokli Tested-by: BuildkiteCI Reviewed-by: sterni --- tvix/store/src/nixbase32.rs | 11 ++++------- 1 file 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 = 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, 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. -- cgit 1.4.1