Skip to content

Commit

Permalink
Inline various simple emit_* and read_* methods in Decoder.
Browse files Browse the repository at this point in the history
Mostly, these are the ones whose body just contains `f(self)`.
  • Loading branch information
nnethercote committed Feb 18, 2020
1 parent c02d689 commit e761f3a
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/libserialize/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub trait Encoder {
fn emit_str(&mut self, v: &str) -> Result<(), Self::Error>;

// Compound types:
#[inline]
fn emit_enum<F>(&mut self, _name: &str, f: F) -> Result<(), Self::Error>
where
F: FnOnce(&mut Self) -> Result<(), Self::Error>,
Expand All @@ -57,6 +58,7 @@ pub trait Encoder {
f(self)
}

#[inline]
fn emit_enum_variant_arg<F>(&mut self, _a_idx: usize, f: F) -> Result<(), Self::Error>
where
F: FnOnce(&mut Self) -> Result<(), Self::Error>,
Expand Down Expand Up @@ -89,13 +91,15 @@ pub trait Encoder {
self.emit_enum_variant_arg(f_idx, f)
}

#[inline]
fn emit_struct<F>(&mut self, _name: &str, _len: usize, f: F) -> Result<(), Self::Error>
where
F: FnOnce(&mut Self) -> Result<(), Self::Error>,
{
f(self)
}

#[inline]
fn emit_struct_field<F>(
&mut self,
_f_name: &str,
Expand All @@ -108,13 +112,15 @@ pub trait Encoder {
f(self)
}

#[inline]
fn emit_tuple<F>(&mut self, _len: usize, f: F) -> Result<(), Self::Error>
where
F: FnOnce(&mut Self) -> Result<(), Self::Error>,
{
f(self)
}

#[inline]
fn emit_tuple_arg<F>(&mut self, _idx: usize, f: F) -> Result<(), Self::Error>
where
F: FnOnce(&mut Self) -> Result<(), Self::Error>,
Expand Down Expand Up @@ -164,6 +170,7 @@ pub trait Encoder {
f(self)
}

#[inline]
fn emit_seq_elt<F>(&mut self, _idx: usize, f: F) -> Result<(), Self::Error>
where
F: FnOnce(&mut Self) -> Result<(), Self::Error>,
Expand All @@ -179,13 +186,15 @@ pub trait Encoder {
f(self)
}

#[inline]
fn emit_map_elt_key<F>(&mut self, _idx: usize, f: F) -> Result<(), Self::Error>
where
F: FnOnce(&mut Self) -> Result<(), Self::Error>,
{
f(self)
}

#[inline]
fn emit_map_elt_val<F>(&mut self, _idx: usize, f: F) -> Result<(), Self::Error>
where
F: FnOnce(&mut Self) -> Result<(), Self::Error>,
Expand Down Expand Up @@ -218,13 +227,15 @@ pub trait Decoder {
fn read_str(&mut self) -> Result<Cow<'_, str>, Self::Error>;

// Compound types:
#[inline]
fn read_enum<T, F>(&mut self, _name: &str, f: F) -> Result<T, Self::Error>
where
F: FnOnce(&mut Self) -> Result<T, Self::Error>,
{
f(self)
}

#[inline]
fn read_enum_variant<T, F>(&mut self, _names: &[&str], mut f: F) -> Result<T, Self::Error>
where
F: FnMut(&mut Self, usize) -> Result<T, Self::Error>,
Expand All @@ -233,6 +244,7 @@ pub trait Decoder {
f(self, disr)
}

#[inline]
fn read_enum_variant_arg<T, F>(&mut self, _a_idx: usize, f: F) -> Result<T, Self::Error>
where
F: FnOnce(&mut Self) -> Result<T, Self::Error>,
Expand All @@ -259,13 +271,15 @@ pub trait Decoder {
self.read_enum_variant_arg(f_idx, f)
}

#[inline]
fn read_struct<T, F>(&mut self, _s_name: &str, _len: usize, f: F) -> Result<T, Self::Error>
where
F: FnOnce(&mut Self) -> Result<T, Self::Error>,
{
f(self)
}

#[inline]
fn read_struct_field<T, F>(
&mut self,
_f_name: &str,
Expand All @@ -278,13 +292,15 @@ pub trait Decoder {
f(self)
}

#[inline]
fn read_tuple<T, F>(&mut self, _len: usize, f: F) -> Result<T, Self::Error>
where
F: FnOnce(&mut Self) -> Result<T, Self::Error>,
{
f(self)
}

#[inline]
fn read_tuple_arg<T, F>(&mut self, _a_idx: usize, f: F) -> Result<T, Self::Error>
where
F: FnOnce(&mut Self) -> Result<T, Self::Error>,
Expand Down Expand Up @@ -328,6 +344,7 @@ pub trait Decoder {
f(self, len)
}

#[inline]
fn read_seq_elt<T, F>(&mut self, _idx: usize, f: F) -> Result<T, Self::Error>
where
F: FnOnce(&mut Self) -> Result<T, Self::Error>,
Expand All @@ -343,13 +360,15 @@ pub trait Decoder {
f(self, len)
}

#[inline]
fn read_map_elt_key<T, F>(&mut self, _idx: usize, f: F) -> Result<T, Self::Error>
where
F: FnOnce(&mut Self) -> Result<T, Self::Error>,
{
f(self)
}

#[inline]
fn read_map_elt_val<T, F>(&mut self, _idx: usize, f: F) -> Result<T, Self::Error>
where
F: FnOnce(&mut Self) -> Result<T, Self::Error>,
Expand Down

0 comments on commit e761f3a

Please sign in to comment.