From 630c4eb6fb7b8d2b04809c2fd5ded06d2e53a87e Mon Sep 17 00:00:00 2001 From: Merope Riddle Date: Mon, 31 Oct 2016 22:24:43 +0000 Subject: [PATCH] core/ser: replace `write_vec` with `write_bytes`, drop a bunch of clones --- core/src/core/transaction.rs | 6 +++--- core/src/ser.rs | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/core/src/core/transaction.rs b/core/src/core/transaction.rs index a250cb90e..5af9ccd79 100644 --- a/core/src/core/transaction.rs +++ b/core/src/core/transaction.rs @@ -41,7 +41,7 @@ pub struct TxProof { impl Writeable for TxProof { fn write(&self, writer: &mut Writer) -> Result<(), ser::Error> { try!(writer.write_fixed_bytes(&self.remainder)); - writer.write_vec(&mut self.sig.clone()) + writer.write_bytes(&self.sig) } } @@ -71,7 +71,7 @@ impl Writeable for Transaction { fn write(&self, writer: &mut Writer) -> Result<(), ser::Error> { ser_multiwrite!(writer, [write_u64, self.fee], - [write_vec, &mut self.zerosig.clone()], + [write_bytes, &self.zerosig], [write_u64, self.inputs.len() as u64], [write_u64, self.outputs.len() as u64]); for inp in &self.inputs { @@ -304,7 +304,7 @@ pub enum Output { impl Writeable for Output { fn write(&self, writer: &mut Writer) -> Result<(), ser::Error> { try!(writer.write_fixed_bytes(&self.commitment().unwrap())); - writer.write_vec(&mut self.proof().unwrap().bytes().to_vec()) + writer.write_bytes(&mut self.proof().unwrap().bytes()) } } diff --git a/core/src/ser.rs b/core/src/ser.rs index e1f5e4e3e..a0e09c7a3 100644 --- a/core/src/ser.rs +++ b/core/src/ser.rs @@ -96,7 +96,7 @@ pub trait Writer { fn write_i64(&mut self, n: i64) -> Result<(), Error>; /// Writes a variable length `Vec`, the length of the `Vec` is encoded as a /// prefix. - fn write_vec(&mut self, vec: &mut Vec) -> Result<(), Error>; + fn write_bytes(&mut self, data: &[u8]) -> Result<(), Error>; /// Writes a fixed number of bytes from something that can turn itself into /// a `&[u8]`. The reader is expected to know the actual length on read. fn write_fixed_bytes(&mut self, b32: &AsFixedBytes) -> Result<(), Error>; @@ -249,9 +249,9 @@ impl<'a> Writer for BinWriter<'a> { } - fn write_vec(&mut self, vec: &mut Vec) -> Result<(), Error> { - try!(self.write_u64(vec.len() as u64)); - try!(self.sink.write_all(vec)); + fn write_bytes(&mut self, data: &[u8]) -> Result<(), Error> { + try!(self.write_u64(data.len() as u64)); + try!(self.sink.write_all(data)); Ok(()) }