From 44b4a6c8599d8988c82e3932a7a1cf3a38f377c3 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Tue, 11 Jul 2023 16:03:21 -0700 Subject: [PATCH] Simplify serialize_bytes --- src/ser.rs | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/src/ser.rs b/src/ser.rs index 0f422d182..bcf11d4ac 100644 --- a/src/ser.rs +++ b/src/ser.rs @@ -192,31 +192,22 @@ where .formatter .begin_array(&mut self.writer) .map_err(Error::io)); - if value.is_empty() { + let mut first = true; + for byte in value { tri!(self .formatter - .end_array(&mut self.writer) + .begin_array_value(&mut self.writer, first) .map_err(Error::io)); - } else { - let mut state = State::First; - for byte in value { - tri!(self - .formatter - .begin_array_value(&mut self.writer, state == State::First) - .map_err(Error::io)); - state = State::Rest; - tri!(byte.serialize(&mut *self)); - tri!(self - .formatter - .end_array_value(&mut self.writer) - .map_err(Error::io)); - } + tri!(byte.serialize(&mut *self)); tri!(self .formatter - .end_array(&mut self.writer) + .end_array_value(&mut self.writer) .map_err(Error::io)); + first = false; } - Ok(()) + self.formatter + .end_array(&mut self.writer) + .map_err(Error::io) } #[inline]