Skip to content

Commit 2a7a3a1

Browse files
committed
Auto merge of #69256 - nnethercote:misc-inlining, r=<try>
Miscellaneous inlining improvements These commits inline some hot functions that aren't currently inlined, for some speed wins. r? @Centril
2 parents 0176a9e + e761f3a commit 2a7a3a1

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

src/libcore/str/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1499,7 +1499,7 @@ fn contains_nonascii(x: usize) -> bool {
14991499

15001500
/// Walks through `v` checking that it's a valid UTF-8 sequence,
15011501
/// returning `Ok(())` in that case, or, if it is invalid, `Err(err)`.
1502-
#[inline]
1502+
#[inline(always)]
15031503
fn run_utf8_validation(v: &[u8]) -> Result<(), Utf8Error> {
15041504
let mut index = 0;
15051505
let len = v.len();

src/librustc_span/symbol.rs

+2
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,7 @@ impl Encodable for Symbol {
993993
}
994994

995995
impl Decodable for Symbol {
996+
#[inline]
996997
fn decode<D: Decoder>(d: &mut D) -> Result<Symbol, D::Error> {
997998
Ok(Symbol::intern(&d.read_str()?))
998999
}
@@ -1031,6 +1032,7 @@ impl Interner {
10311032
}
10321033
}
10331034

1035+
#[inline]
10341036
pub fn intern(&mut self, string: &str) -> Symbol {
10351037
if let Some(&name) = self.names.get(string) {
10361038
return name;

src/libserialize/serialize.rs

+19
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ pub trait Encoder {
3636
fn emit_str(&mut self, v: &str) -> Result<(), Self::Error>;
3737

3838
// Compound types:
39+
#[inline]
3940
fn emit_enum<F>(&mut self, _name: &str, f: F) -> Result<(), Self::Error>
4041
where
4142
F: FnOnce(&mut Self) -> Result<(), Self::Error>,
@@ -57,6 +58,7 @@ pub trait Encoder {
5758
f(self)
5859
}
5960

61+
#[inline]
6062
fn emit_enum_variant_arg<F>(&mut self, _a_idx: usize, f: F) -> Result<(), Self::Error>
6163
where
6264
F: FnOnce(&mut Self) -> Result<(), Self::Error>,
@@ -89,13 +91,15 @@ pub trait Encoder {
8991
self.emit_enum_variant_arg(f_idx, f)
9092
}
9193

94+
#[inline]
9295
fn emit_struct<F>(&mut self, _name: &str, _len: usize, f: F) -> Result<(), Self::Error>
9396
where
9497
F: FnOnce(&mut Self) -> Result<(), Self::Error>,
9598
{
9699
f(self)
97100
}
98101

102+
#[inline]
99103
fn emit_struct_field<F>(
100104
&mut self,
101105
_f_name: &str,
@@ -108,13 +112,15 @@ pub trait Encoder {
108112
f(self)
109113
}
110114

115+
#[inline]
111116
fn emit_tuple<F>(&mut self, _len: usize, f: F) -> Result<(), Self::Error>
112117
where
113118
F: FnOnce(&mut Self) -> Result<(), Self::Error>,
114119
{
115120
f(self)
116121
}
117122

123+
#[inline]
118124
fn emit_tuple_arg<F>(&mut self, _idx: usize, f: F) -> Result<(), Self::Error>
119125
where
120126
F: FnOnce(&mut Self) -> Result<(), Self::Error>,
@@ -164,6 +170,7 @@ pub trait Encoder {
164170
f(self)
165171
}
166172

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

189+
#[inline]
182190
fn emit_map_elt_key<F>(&mut self, _idx: usize, f: F) -> Result<(), Self::Error>
183191
where
184192
F: FnOnce(&mut Self) -> Result<(), Self::Error>,
185193
{
186194
f(self)
187195
}
188196

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

220229
// Compound types:
230+
#[inline]
221231
fn read_enum<T, F>(&mut self, _name: &str, f: F) -> Result<T, Self::Error>
222232
where
223233
F: FnOnce(&mut Self) -> Result<T, Self::Error>,
224234
{
225235
f(self)
226236
}
227237

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

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

274+
#[inline]
262275
fn read_struct<T, F>(&mut self, _s_name: &str, _len: usize, f: F) -> Result<T, Self::Error>
263276
where
264277
F: FnOnce(&mut Self) -> Result<T, Self::Error>,
265278
{
266279
f(self)
267280
}
268281

282+
#[inline]
269283
fn read_struct_field<T, F>(
270284
&mut self,
271285
_f_name: &str,
@@ -278,13 +292,15 @@ pub trait Decoder {
278292
f(self)
279293
}
280294

295+
#[inline]
281296
fn read_tuple<T, F>(&mut self, _len: usize, f: F) -> Result<T, Self::Error>
282297
where
283298
F: FnOnce(&mut Self) -> Result<T, Self::Error>,
284299
{
285300
f(self)
286301
}
287302

303+
#[inline]
288304
fn read_tuple_arg<T, F>(&mut self, _a_idx: usize, f: F) -> Result<T, Self::Error>
289305
where
290306
F: FnOnce(&mut Self) -> Result<T, Self::Error>,
@@ -328,6 +344,7 @@ pub trait Decoder {
328344
f(self, len)
329345
}
330346

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

363+
#[inline]
346364
fn read_map_elt_key<T, F>(&mut self, _idx: usize, f: F) -> Result<T, Self::Error>
347365
where
348366
F: FnOnce(&mut Self) -> Result<T, Self::Error>,
349367
{
350368
f(self)
351369
}
352370

371+
#[inline]
353372
fn read_map_elt_val<T, F>(&mut self, _idx: usize, f: F) -> Result<T, Self::Error>
354373
where
355374
F: FnOnce(&mut Self) -> Result<T, Self::Error>,

0 commit comments

Comments
 (0)