core/ser: replace write_vec with write_bytes, drop a bunch of clones

This commit is contained in:
Merope Riddle 2016-10-31 22:24:43 +00:00
parent bc38016385
commit 630c4eb6fb
2 changed files with 7 additions and 7 deletions

View file

@ -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())
}
}

View file

@ -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<u8>) -> 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<u8>) -> 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(())
}