Skip to content

Commit

Permalink
Inline Serializer::serialize_seq into serialize_bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Jul 11, 2023
1 parent 3ddda75 commit 55a7f5c
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/ser.rs
Expand Up @@ -187,10 +187,27 @@ where
format_escaped_str(&mut self.writer, &mut self.formatter, value).map_err(Error::io)
}

#[inline]
fn serialize_bytes(self, value: &[u8]) -> Result<()> {
use serde::ser::SerializeSeq;
let mut seq = tri!(self.serialize_seq(Some(value.len())));
tri!(self
.formatter
.begin_array(&mut self.writer)
.map_err(Error::io));
let mut seq = if value.is_empty() {
tri!(self
.formatter
.end_array(&mut self.writer)
.map_err(Error::io));
Compound::Map {
ser: self,
state: State::Empty,
}
} else {
Compound::Map {
ser: self,
state: State::First,
}
};
for byte in value {
tri!(seq.serialize_element(byte));
}
Expand Down

0 comments on commit 55a7f5c

Please sign in to comment.