Skip to content

Commit

Permalink
Merge pull request #644 from erickt/serde
Browse files Browse the repository at this point in the history
Minor serde micro-optimizations
  • Loading branch information
seanmonstar committed Sep 1, 2015
2 parents ca67013 + 3a3c8b6 commit 8dbc38c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 28 deletions.
31 changes: 4 additions & 27 deletions src/header/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,33 +332,10 @@ impl fmt::Debug for Headers {
#[cfg(feature = "serde-serialization")]
impl Serialize for Headers {
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error> where S: Serializer {
struct HeadersVisitor<'a> {
iter: HeadersItems<'a>,
len: usize,
}

impl<'a> ser::MapVisitor for HeadersVisitor<'a> {
fn visit<S>(&mut self, serializer: &mut S) -> Result<Option<()>, S::Error>
where S: Serializer {
match self.iter.next() {
Some(header_item) => {
try!(serializer.visit_map_elt(header_item.name(),
header_item.value_string()));
Ok(Some(()))
}
None => Ok(None),
}
}

fn len(&self) -> Option<usize> {
Some(self.len)
}
}

serializer.visit_map(HeadersVisitor {
iter: self.iter(),
len: self.len(),
})
serializer.visit_map(ser::impls::MapIteratorVisitor::new(
self.iter().map(|header| (header.name(), header.value_string())),
Some(self.len()),
))
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub struct RawStatus(pub u16, pub Cow<'static, str>);
#[cfg(feature = "serde-serialization")]
impl Serialize for RawStatus {
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error> where S: Serializer {
(self.0, self.1.clone().into_owned()).serialize(serializer)
(self.0, &self.1).serialize(serializer)
}
}

Expand Down

0 comments on commit 8dbc38c

Please sign in to comment.