Skip to content

Mark libserialize functions as inline #53393

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 21, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 15 additions & 17 deletions src/libserialize/collection_impls.rs
Original file line number Diff line number Diff line change
@@ -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();
1 change: 1 addition & 0 deletions src/libserialize/leb128.rs
Original file line number Diff line number Diff line change
@@ -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))
}
3 changes: 3 additions & 0 deletions src/libserialize/opaque.rs
Original file line number Diff line number Diff line change
@@ -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> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The #[inline]s on things like this and write_signed_leb128 seem definitely good, though 👍

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()
}
7 changes: 4 additions & 3 deletions src/libserialize/serialize.rs
Original file line number Diff line number Diff line change
@@ -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);