From ab906179ccd6254f51f0d254479c9b211b0276b1 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 18 Feb 2020 15:42:11 +1100 Subject: [PATCH 1/3] Always inline `run_utf8_validation`. It only has two call sites, and the one within `from_utf8` is hot within rustc itself. --- src/libcore/str/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index 734b3ba7c6bba..a943e49c3e24d 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -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(); From c02d689a626d44e82f3769d8be1a842f2d211005 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 18 Feb 2020 16:00:58 +1100 Subject: [PATCH 2/3] Inline `Symbol::decode` and `Interner::intern`. --- src/librustc_span/symbol.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/librustc_span/symbol.rs b/src/librustc_span/symbol.rs index 1cc4a27788098..b7285cc94920c 100644 --- a/src/librustc_span/symbol.rs +++ b/src/librustc_span/symbol.rs @@ -993,6 +993,7 @@ impl Encodable for Symbol { } impl Decodable for Symbol { + #[inline] fn decode(d: &mut D) -> Result { Ok(Symbol::intern(&d.read_str()?)) } @@ -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; From e761f3af904b3c275bdebc73bb29ffc45384945d Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 18 Feb 2020 16:12:24 +1100 Subject: [PATCH 3/3] Inline various simple `emit_*` and `read_*` methods in `Decoder`. Mostly, these are the ones whose body just contains `f(self)`. --- src/libserialize/serialize.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/libserialize/serialize.rs b/src/libserialize/serialize.rs index 19283ffc43864..8c6548cd3c5b2 100644 --- a/src/libserialize/serialize.rs +++ b/src/libserialize/serialize.rs @@ -36,6 +36,7 @@ pub trait Encoder { fn emit_str(&mut self, v: &str) -> Result<(), Self::Error>; // Compound types: + #[inline] fn emit_enum(&mut self, _name: &str, f: F) -> Result<(), Self::Error> where F: FnOnce(&mut Self) -> Result<(), Self::Error>, @@ -57,6 +58,7 @@ pub trait Encoder { f(self) } + #[inline] fn emit_enum_variant_arg(&mut self, _a_idx: usize, f: F) -> Result<(), Self::Error> where F: FnOnce(&mut Self) -> Result<(), Self::Error>, @@ -89,6 +91,7 @@ pub trait Encoder { self.emit_enum_variant_arg(f_idx, f) } + #[inline] fn emit_struct(&mut self, _name: &str, _len: usize, f: F) -> Result<(), Self::Error> where F: FnOnce(&mut Self) -> Result<(), Self::Error>, @@ -96,6 +99,7 @@ pub trait Encoder { f(self) } + #[inline] fn emit_struct_field( &mut self, _f_name: &str, @@ -108,6 +112,7 @@ pub trait Encoder { f(self) } + #[inline] fn emit_tuple(&mut self, _len: usize, f: F) -> Result<(), Self::Error> where F: FnOnce(&mut Self) -> Result<(), Self::Error>, @@ -115,6 +120,7 @@ pub trait Encoder { f(self) } + #[inline] fn emit_tuple_arg(&mut self, _idx: usize, f: F) -> Result<(), Self::Error> where F: FnOnce(&mut Self) -> Result<(), Self::Error>, @@ -164,6 +170,7 @@ pub trait Encoder { f(self) } + #[inline] fn emit_seq_elt(&mut self, _idx: usize, f: F) -> Result<(), Self::Error> where F: FnOnce(&mut Self) -> Result<(), Self::Error>, @@ -179,6 +186,7 @@ pub trait Encoder { f(self) } + #[inline] fn emit_map_elt_key(&mut self, _idx: usize, f: F) -> Result<(), Self::Error> where F: FnOnce(&mut Self) -> Result<(), Self::Error>, @@ -186,6 +194,7 @@ pub trait Encoder { f(self) } + #[inline] fn emit_map_elt_val(&mut self, _idx: usize, f: F) -> Result<(), Self::Error> where F: FnOnce(&mut Self) -> Result<(), Self::Error>, @@ -218,6 +227,7 @@ pub trait Decoder { fn read_str(&mut self) -> Result, Self::Error>; // Compound types: + #[inline] fn read_enum(&mut self, _name: &str, f: F) -> Result where F: FnOnce(&mut Self) -> Result, @@ -225,6 +235,7 @@ pub trait Decoder { f(self) } + #[inline] fn read_enum_variant(&mut self, _names: &[&str], mut f: F) -> Result where F: FnMut(&mut Self, usize) -> Result, @@ -233,6 +244,7 @@ pub trait Decoder { f(self, disr) } + #[inline] fn read_enum_variant_arg(&mut self, _a_idx: usize, f: F) -> Result where F: FnOnce(&mut Self) -> Result, @@ -259,6 +271,7 @@ pub trait Decoder { self.read_enum_variant_arg(f_idx, f) } + #[inline] fn read_struct(&mut self, _s_name: &str, _len: usize, f: F) -> Result where F: FnOnce(&mut Self) -> Result, @@ -266,6 +279,7 @@ pub trait Decoder { f(self) } + #[inline] fn read_struct_field( &mut self, _f_name: &str, @@ -278,6 +292,7 @@ pub trait Decoder { f(self) } + #[inline] fn read_tuple(&mut self, _len: usize, f: F) -> Result where F: FnOnce(&mut Self) -> Result, @@ -285,6 +300,7 @@ pub trait Decoder { f(self) } + #[inline] fn read_tuple_arg(&mut self, _a_idx: usize, f: F) -> Result where F: FnOnce(&mut Self) -> Result, @@ -328,6 +344,7 @@ pub trait Decoder { f(self, len) } + #[inline] fn read_seq_elt(&mut self, _idx: usize, f: F) -> Result where F: FnOnce(&mut Self) -> Result, @@ -343,6 +360,7 @@ pub trait Decoder { f(self, len) } + #[inline] fn read_map_elt_key(&mut self, _idx: usize, f: F) -> Result where F: FnOnce(&mut Self) -> Result, @@ -350,6 +368,7 @@ pub trait Decoder { f(self) } + #[inline] fn read_map_elt_val(&mut self, _idx: usize, f: F) -> Result where F: FnOnce(&mut Self) -> Result,