Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Miscellaneous inlining improvements #69256

Merged
merged 3 commits into from
Feb 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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