Rollup merge of #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.
This commit is contained in:
kennytm 2018-08-21 01:20:16 +08:00
commit b21e956f27
No known key found for this signature in database
GPG Key ID: FEF6C8051D0E013C
4 changed files with 23 additions and 20 deletions

View File

@ -17,9 +17,7 @@ use std::collections::{LinkedList, VecDeque, BTreeMap, BTreeSet, HashMap, HashSe
use std::rc::Rc;
use std::sync::Arc;
impl<
T: Encodable
> Encodable for LinkedList<T> {
impl<T: Encodable> Encodable for LinkedList<T> {
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
s.emit_seq(self.len(), |s| {
for (i, e) in self.iter().enumerate() {
@ -65,10 +63,10 @@ impl<T:Decodable> Decodable for VecDeque<T> {
}
}
impl<
K: Encodable + PartialEq + Ord,
V: Encodable
> Encodable for BTreeMap<K, V> {
impl<K, V> Encodable for BTreeMap<K, V>
where K: Encodable + PartialEq + Ord,
V: Encodable
{
fn encode<S: Encoder>(&self, e: &mut S) -> Result<(), S::Error> {
e.emit_map(self.len(), |e| {
let mut i = 0;
@ -82,10 +80,10 @@ impl<
}
}
impl<
K: Decodable + PartialEq + Ord,
V: Decodable
> Decodable for BTreeMap<K, V> {
impl<K, V> Decodable for BTreeMap<K, V>
where K: Decodable + PartialEq + Ord,
V: Decodable
{
fn decode<D: Decoder>(d: &mut D) -> Result<BTreeMap<K, V>, D::Error> {
d.read_map(|d, len| {
let mut map = BTreeMap::new();
@ -99,9 +97,9 @@ impl<
}
}
impl<
T: Encodable + PartialEq + Ord
> Encodable for BTreeSet<T> {
impl<T> Encodable for BTreeSet<T>
where T: Encodable + PartialEq + Ord
{
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
s.emit_seq(self.len(), |s| {
let mut i = 0;
@ -114,9 +112,9 @@ impl<
}
}
impl<
T: Decodable + PartialEq + Ord
> Decodable for BTreeSet<T> {
impl<T> Decodable for BTreeSet<T>
where T: Decodable + PartialEq + Ord
{
fn decode<D: Decoder>(d: &mut D) -> Result<BTreeSet<T>, D::Error> {
d.read_seq(|d, len| {
let mut set = BTreeSet::new();

View File

@ -118,6 +118,7 @@ pub fn write_signed_leb128_to<W>(mut value: i128, mut write: W)
}
}
#[inline]
pub fn write_signed_leb128(out: &mut Vec<u8>, value: i128) {
write_signed_leb128_to(value, |v| write_to_vec(out, v))
}

View File

@ -31,6 +31,7 @@ impl Encoder {
self.data
}
#[inline]
pub fn emit_raw_bytes(&mut self, s: &[u8]) {
self.data.extend_from_slice(s);
}
@ -193,6 +194,7 @@ impl<'a> Decoder<'a> {
self.position += bytes;
}
#[inline]
pub fn read_raw_bytes(&mut self, s: &mut [u8]) -> Result<(), String> {
let start = self.position;
let end = start + s.len();
@ -326,6 +328,7 @@ impl<'a> serialize::Decoder for Decoder<'a> {
Ok(Cow::Borrowed(s))
}
#[inline]
fn error(&mut self, err: &str) -> Self::Error {
err.to_string()
}

View File

@ -119,6 +119,7 @@ pub trait Encoder {
self.emit_enum("Option", f)
}
#[inline]
fn emit_option_none(&mut self) -> Result<(), Self::Error> {
self.emit_enum_variant("None", 0, 0, |_| Ok(()))
}
@ -560,14 +561,12 @@ impl< T: Decodable> Decodable for Box<[T]> {
}
impl<T:Encodable> Encodable for Rc<T> {
#[inline]
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
(**self).encode(s)
}
}
impl<T:Decodable> Decodable for Rc<T> {
#[inline]
fn decode<D: Decoder>(d: &mut D) -> Result<Rc<T>, D::Error> {
Ok(Rc::new(Decodable::decode(d)?))
}
@ -618,7 +617,9 @@ impl<'a, T:Encodable> Encodable for Cow<'a, [T]> where [T]: ToOwned<Owned = Vec<
}
}
impl<T:Decodable+ToOwned> Decodable for Cow<'static, [T]> where [T]: ToOwned<Owned = Vec<T>> {
impl<T:Decodable+ToOwned> Decodable for Cow<'static, [T]>
where [T]: ToOwned<Owned = Vec<T>>
{
fn decode<D: Decoder>(d: &mut D) -> Result<Cow<'static, [T]>, D::Error> {
d.read_seq(|d, len| {
let mut v = Vec::with_capacity(len);