Skip to content

Commit b21e956

Browse files
committed
Rollup merge of rust-lang#53393 - BurntPizza:serialize-inlines, r=alexcrichton
Mark libserialize functions as inline Got to thinking: "what if that big pile of tiny functions isn't inlining as it should?" So a few `replace-regex` later the local perf run says this: <details> ![](https://i.imgur.com/gvdJEgG.png) </details> Not huge, but still a win, which is interesting. Want to verify with the real perf run, but I understand there's a backlog. I didn't notice any increase in compile time or binary sizes for rustc/libs.
2 parents f9e3af7 + 1540e8c commit b21e956

File tree

4 files changed

+23
-20
lines changed

4 files changed

+23
-20
lines changed

src/libserialize/collection_impls.rs

+15-17
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ use std::collections::{LinkedList, VecDeque, BTreeMap, BTreeSet, HashMap, HashSe
1717
use std::rc::Rc;
1818
use std::sync::Arc;
1919

20-
impl<
21-
T: Encodable
22-
> Encodable for LinkedList<T> {
20+
impl<T: Encodable> Encodable for LinkedList<T> {
2321
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
2422
s.emit_seq(self.len(), |s| {
2523
for (i, e) in self.iter().enumerate() {
@@ -65,10 +63,10 @@ impl<T:Decodable> Decodable for VecDeque<T> {
6563
}
6664
}
6765

68-
impl<
69-
K: Encodable + PartialEq + Ord,
70-
V: Encodable
71-
> Encodable for BTreeMap<K, V> {
66+
impl<K, V> Encodable for BTreeMap<K, V>
67+
where K: Encodable + PartialEq + Ord,
68+
V: Encodable
69+
{
7270
fn encode<S: Encoder>(&self, e: &mut S) -> Result<(), S::Error> {
7371
e.emit_map(self.len(), |e| {
7472
let mut i = 0;
@@ -82,10 +80,10 @@ impl<
8280
}
8381
}
8482

85-
impl<
86-
K: Decodable + PartialEq + Ord,
87-
V: Decodable
88-
> Decodable for BTreeMap<K, V> {
83+
impl<K, V> Decodable for BTreeMap<K, V>
84+
where K: Decodable + PartialEq + Ord,
85+
V: Decodable
86+
{
8987
fn decode<D: Decoder>(d: &mut D) -> Result<BTreeMap<K, V>, D::Error> {
9088
d.read_map(|d, len| {
9189
let mut map = BTreeMap::new();
@@ -99,9 +97,9 @@ impl<
9997
}
10098
}
10199

102-
impl<
103-
T: Encodable + PartialEq + Ord
104-
> Encodable for BTreeSet<T> {
100+
impl<T> Encodable for BTreeSet<T>
101+
where T: Encodable + PartialEq + Ord
102+
{
105103
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
106104
s.emit_seq(self.len(), |s| {
107105
let mut i = 0;
@@ -114,9 +112,9 @@ impl<
114112
}
115113
}
116114

117-
impl<
118-
T: Decodable + PartialEq + Ord
119-
> Decodable for BTreeSet<T> {
115+
impl<T> Decodable for BTreeSet<T>
116+
where T: Decodable + PartialEq + Ord
117+
{
120118
fn decode<D: Decoder>(d: &mut D) -> Result<BTreeSet<T>, D::Error> {
121119
d.read_seq(|d, len| {
122120
let mut set = BTreeSet::new();

src/libserialize/leb128.rs

+1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ pub fn write_signed_leb128_to<W>(mut value: i128, mut write: W)
118118
}
119119
}
120120

121+
#[inline]
121122
pub fn write_signed_leb128(out: &mut Vec<u8>, value: i128) {
122123
write_signed_leb128_to(value, |v| write_to_vec(out, v))
123124
}

src/libserialize/opaque.rs

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ impl Encoder {
3131
self.data
3232
}
3333

34+
#[inline]
3435
pub fn emit_raw_bytes(&mut self, s: &[u8]) {
3536
self.data.extend_from_slice(s);
3637
}
@@ -193,6 +194,7 @@ impl<'a> Decoder<'a> {
193194
self.position += bytes;
194195
}
195196

197+
#[inline]
196198
pub fn read_raw_bytes(&mut self, s: &mut [u8]) -> Result<(), String> {
197199
let start = self.position;
198200
let end = start + s.len();
@@ -326,6 +328,7 @@ impl<'a> serialize::Decoder for Decoder<'a> {
326328
Ok(Cow::Borrowed(s))
327329
}
328330

331+
#[inline]
329332
fn error(&mut self, err: &str) -> Self::Error {
330333
err.to_string()
331334
}

src/libserialize/serialize.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ pub trait Encoder {
119119
self.emit_enum("Option", f)
120120
}
121121

122+
#[inline]
122123
fn emit_option_none(&mut self) -> Result<(), Self::Error> {
123124
self.emit_enum_variant("None", 0, 0, |_| Ok(()))
124125
}
@@ -560,14 +561,12 @@ impl< T: Decodable> Decodable for Box<[T]> {
560561
}
561562

562563
impl<T:Encodable> Encodable for Rc<T> {
563-
#[inline]
564564
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
565565
(**self).encode(s)
566566
}
567567
}
568568

569569
impl<T:Decodable> Decodable for Rc<T> {
570-
#[inline]
571570
fn decode<D: Decoder>(d: &mut D) -> Result<Rc<T>, D::Error> {
572571
Ok(Rc::new(Decodable::decode(d)?))
573572
}
@@ -618,7 +617,9 @@ impl<'a, T:Encodable> Encodable for Cow<'a, [T]> where [T]: ToOwned<Owned = Vec<
618617
}
619618
}
620619

621-
impl<T:Decodable+ToOwned> Decodable for Cow<'static, [T]> where [T]: ToOwned<Owned = Vec<T>> {
620+
impl<T:Decodable+ToOwned> Decodable for Cow<'static, [T]>
621+
where [T]: ToOwned<Owned = Vec<T>>
622+
{
622623
fn decode<D: Decoder>(d: &mut D) -> Result<Cow<'static, [T]>, D::Error> {
623624
d.read_seq(|d, len| {
624625
let mut v = Vec::with_capacity(len);

0 commit comments

Comments
 (0)