Skip to content

Commit

Permalink
Auto merge of #69256 - nnethercote:misc-inlining, r=<try>
Browse files Browse the repository at this point in the history
Miscellaneous inlining improvements

These commits inline some hot functions that aren't currently inlined, for some speed wins.

r? @Centril
  • Loading branch information
bors committed Feb 18, 2020
2 parents 0176a9e + e761f3a commit 2a7a3a1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/libcore/str/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1499,7 +1499,7 @@ fn contains_nonascii(x: usize) -> bool {

/// Walks through `v` checking that it's a valid UTF-8 sequence,
/// returning `Ok(())` in that case, or, if it is invalid, `Err(err)`.
#[inline]
#[inline(always)]
fn run_utf8_validation(v: &[u8]) -> Result<(), Utf8Error> {
let mut index = 0;
let len = v.len();
Expand Down
2 changes: 2 additions & 0 deletions src/librustc_span/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,7 @@ impl Encodable for Symbol {
}

impl Decodable for Symbol {
#[inline]
fn decode<D: Decoder>(d: &mut D) -> Result<Symbol, D::Error> {
Ok(Symbol::intern(&d.read_str()?))
}
Expand Down Expand Up @@ -1031,6 +1032,7 @@ impl Interner {
}
}

#[inline]
pub fn intern(&mut self, string: &str) -> Symbol {
if let Some(&name) = self.names.get(string) {
return name;
Expand Down
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 2a7a3a1

Please sign in to comment.