Skip to content

Commit

Permalink
Inline SerializeSeq::end into serialize_bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Jul 11, 2023
1 parent 1b72f2b commit 0e2c949
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,20 +188,15 @@ where
}

fn serialize_bytes(self, value: &[u8]) -> Result<()> {
use serde::ser::SerializeSeq;
tri!(self
.formatter
.begin_array(&mut self.writer)
.map_err(Error::io));
let seq = if value.is_empty() {
if value.is_empty() {
tri!(self
.formatter
.end_array(&mut self.writer)
.map_err(Error::io));
Compound::Map {
ser: self,
state: State::Empty,
}
} else {
let mut state = State::First;
for byte in value {
Expand All @@ -216,9 +211,12 @@ where
.end_array_value(&mut self.writer)
.map_err(Error::io));
}
Compound::Map { ser: self, state }
};
seq.end()
tri!(self
.formatter
.end_array(&mut self.writer)
.map_err(Error::io));
}
Ok(())
}

#[inline]
Expand Down

0 comments on commit 0e2c949

Please sign in to comment.