From 804068c01b82caf67a89f4fdcf3af43b97263881 Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Wed, 24 Feb 2016 14:36:00 +0000 Subject: [PATCH] Move some #0018 issues to #0030, #0031, one minor "improvement" --- src/detail/sum.rs | 13 +++++-------- src/util.rs | 2 +- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/detail/sum.rs b/src/detail/sum.rs index a19f25a..87ee35a 100644 --- a/src/detail/sum.rs +++ b/src/detail/sum.rs @@ -17,7 +17,7 @@ pub const BYTES: usize = 32; const BYTES_U8: u8 = BYTES as u8; -// #0018: when simd is stable, it could be used +// #0031: when simd is stable, it could be used // use simd::u8x16; /// A convenient way to manage and manipulate a checksum. /// @@ -49,12 +49,9 @@ impl Sum { pub fn load(arr: &[u8]) -> Sum { assert_eq!(arr.len(), BYTES); // Sum { s1: u8x16::load(&arr, 0), s2: u8x16::load(&arr, 16) } - // #0018 : how to do a fixed-size array copy? - let mut result = Sum::zero(); - for i in 0..BYTES { - result.s[i] = arr[i]; - } - result + let mut s = [0u8; BYTES]; + s.clone_from_slice(arr); + Sum{ s: s } } /// Write the checksum bytes to a stream @@ -127,7 +124,7 @@ const HEX_CHARS : &'static [u8; 16] = b"0123456789ABCDEF"; impl<'a> ops::BitXor for &'a Sum { type Output = Sum; fn bitxor(self, rhs: &'a Sum) -> Sum { - // #0018: optimise XOR operation + // #0031: optimise XOR operation let mut result = Sum::zero(); for i in 0..BYTES { result.s[i] = self.s[i] ^ rhs.s[i]; diff --git a/src/util.rs b/src/util.rs index 67c3b20..dd16ff1 100644 --- a/src/util.rs +++ b/src/util.rs @@ -47,7 +47,7 @@ impl<'a> fmt::Display for ByteFormatter<'a> { } else if *b == b'\'' { try!(write!(f, "\\\'")); } else if *b >= b' ' && *b <= b'~' { - // TODO: this is a horrible way to write a char! + // #0030: this is a horrible way to write a char! let v = vec![*b]; try!(write!(f, "{}", from_utf8(&v).unwrap())); } else {