From 9d80be62f99e8fb1a147149ad48c9ccd2f35706b Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Thu, 6 Jun 2019 10:50:33 +0100 Subject: [PATCH] Simplify Memo::to_utf8 implementation --- zcash_primitives/src/note_encryption.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/zcash_primitives/src/note_encryption.rs b/zcash_primitives/src/note_encryption.rs index dd1bf91..e4886b3 100644 --- a/zcash_primitives/src/note_encryption.rs +++ b/zcash_primitives/src/note_encryption.rs @@ -123,13 +123,11 @@ impl Memo { pub fn to_utf8(&self) -> Option> { // Check if it is a text or binary memo if self.0[0] < 0xF5 { - // Drop trailing zeroes - let mut data = &self.0[..]; - while let Some((0, next)) = data.split_last() { - data = next; - } // Check if it is valid UTF8 - Some(str::from_utf8(data).map(|memo| memo.to_owned())) + Some(str::from_utf8(&self.0).map(|memo| { + // Drop trailing zeroes + memo.trim_end_matches(char::from(0)).to_owned() + })) } else { None }