Skip to content

Commit

Permalink
Implement tag omission optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
Dirbaio committed Jun 27, 2021
1 parent c29543a commit 7495528
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
7 changes: 2 additions & 5 deletions decoder/src/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,11 @@ impl<'t, 'b> Decoder<'t, 'b> {
&mut self,
num_elements: usize,
) -> Result<Vec<FormatSliceElement<'t>>, DecodeError> {
if num_elements == 0 {
return Ok(vec![]);
}
let format = self.get_format()?;
let is_enum = format.contains('|');

let mut elements = Vec::with_capacity(num_elements);
for i in 0..num_elements {
let format = self.get_format()?;
let is_enum = format.contains('|');
let format = if is_enum {
self.get_variant(format)?
} else {
Expand Down
10 changes: 6 additions & 4 deletions src/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,11 @@ pub fn isize(b: isize) {
}

/// Implementation detail
pub fn fmt_slice(values: &[impl Format]) {
pub fn fmt_slice<T: Format>(values: &[T]) {
usize(values.len());
istr(T::_format_tag());
for value in values {
fmt(value);
value._format_data();
}
}

Expand Down Expand Up @@ -349,9 +350,10 @@ pub fn u8_array(a: &[u8]) {
}

// NOTE: This is passed `&[u8; N]` – it's just coerced to a slice.
pub fn fmt_array(a: &[impl Format]) {
pub fn fmt_array<T: Format>(a: &[T]) {
istr(T::_format_tag());
for value in a {
fmt(value);
value._format_data();
}
}

Expand Down
6 changes: 1 addition & 5 deletions src/impls/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,7 @@ where

#[inline]
fn _format_data(&self) {
export::usize(self.len());
for value in self {
export::istr(T::_format_tag());
value._format_data();
}
export::fmt_slice(self);
}
}

Expand Down

0 comments on commit 7495528

Please sign in to comment.