未验证 提交 b21e956f 编写于 作者: K kennytm

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.
......@@ -17,9 +17,7 @@
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 @@ fn decode<D: Decoder>(d: &mut D) -> Result<VecDeque<T>, D::Error> {
}
}
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 @@ fn encode<S: Encoder>(&self, e: &mut S) -> Result<(), S::Error> {
}
}
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 @@ fn decode<D: Decoder>(d: &mut D) -> Result<BTreeMap<K, V>, D::Error> {
}
}
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 @@ fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
}
}
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();
......
......@@ -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))
}
......
......@@ -31,6 +31,7 @@ pub fn into_inner(self) -> Vec<u8> {
self.data
}
#[inline]
pub fn emit_raw_bytes(&mut self, s: &[u8]) {
self.data.extend_from_slice(s);
}
......@@ -193,6 +194,7 @@ pub fn advance(&mut self, bytes: usize) {
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 @@ fn read_str(&mut self) -> Result<Cow<str>, Self::Error> {
Ok(Cow::Borrowed(s))
}
#[inline]
fn error(&mut self, err: &str) -> Self::Error {
err.to_string()
}
......
......@@ -119,6 +119,7 @@ fn emit_option<F>(&mut self, f: F) -> Result<(), Self::Error>
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 @@ fn decode<D: Decoder>(d: &mut D) -> Result<Box<[T]>, D::Error> {
}
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 @@ fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
}
}
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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册