Skip to content
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

Mark libserialize functions as inline #53393

Merged
merged 2 commits into from
Aug 21, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
16 changes: 16 additions & 0 deletions src/libserialize/collection_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use std::sync::Arc;
impl<
T: Encodable
> Encodable for LinkedList<T> {
#[inline]
Copy link
Member

Choose a reason for hiding this comment

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

I thought #[inline] was unnecessary on generic methods?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IIRC, ever since multiple codegen units, it can matter. I forget.

Copy link
Member

Choose a reason for hiding this comment

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

Here's the discussion I remembered: #52704

fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
s.emit_seq(self.len(), |s| {
for (i, e) in self.iter().enumerate() {
Expand All @@ -31,6 +32,7 @@ impl<
}

impl<T:Decodable> Decodable for LinkedList<T> {
#[inline]
fn decode<D: Decoder>(d: &mut D) -> Result<LinkedList<T>, D::Error> {
d.read_seq(|d, len| {
let mut list = LinkedList::new();
Expand All @@ -43,6 +45,7 @@ impl<T:Decodable> Decodable for LinkedList<T> {
}

impl<T: Encodable> Encodable for VecDeque<T> {
#[inline]
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
s.emit_seq(self.len(), |s| {
for (i, e) in self.iter().enumerate() {
Expand All @@ -54,6 +57,7 @@ impl<T: Encodable> Encodable for VecDeque<T> {
}

impl<T:Decodable> Decodable for VecDeque<T> {
#[inline]
fn decode<D: Decoder>(d: &mut D) -> Result<VecDeque<T>, D::Error> {
d.read_seq(|d, len| {
let mut deque: VecDeque<T> = VecDeque::new();
Expand All @@ -69,6 +73,7 @@ impl<
K: Encodable + PartialEq + Ord,
V: Encodable
> Encodable for BTreeMap<K, V> {
#[inline]
fn encode<S: Encoder>(&self, e: &mut S) -> Result<(), S::Error> {
e.emit_map(self.len(), |e| {
let mut i = 0;
Expand All @@ -86,6 +91,7 @@ impl<
K: Decodable + PartialEq + Ord,
V: Decodable
> Decodable for BTreeMap<K, V> {
#[inline]
fn decode<D: Decoder>(d: &mut D) -> Result<BTreeMap<K, V>, D::Error> {
d.read_map(|d, len| {
let mut map = BTreeMap::new();
Expand All @@ -102,6 +108,7 @@ impl<
impl<
T: Encodable + PartialEq + Ord
> Encodable for BTreeSet<T> {
#[inline]
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
s.emit_seq(self.len(), |s| {
let mut i = 0;
Expand All @@ -117,6 +124,7 @@ impl<
impl<
T: Decodable + PartialEq + Ord
> Decodable for BTreeSet<T> {
#[inline]
fn decode<D: Decoder>(d: &mut D) -> Result<BTreeSet<T>, D::Error> {
d.read_seq(|d, len| {
let mut set = BTreeSet::new();
Expand All @@ -133,6 +141,7 @@ impl<K, V, S> Encodable for HashMap<K, V, S>
V: Encodable,
S: BuildHasher,
{
#[inline]
fn encode<E: Encoder>(&self, e: &mut E) -> Result<(), E::Error> {
e.emit_map(self.len(), |e| {
let mut i = 0;
Expand All @@ -151,6 +160,7 @@ impl<K, V, S> Decodable for HashMap<K, V, S>
V: Decodable,
S: BuildHasher + Default,
{
#[inline]
fn decode<D: Decoder>(d: &mut D) -> Result<HashMap<K, V, S>, D::Error> {
d.read_map(|d, len| {
let state = Default::default();
Expand All @@ -169,6 +179,7 @@ impl<T, S> Encodable for HashSet<T, S>
where T: Encodable + Hash + Eq,
S: BuildHasher,
{
#[inline]
fn encode<E: Encoder>(&self, s: &mut E) -> Result<(), E::Error> {
s.emit_seq(self.len(), |s| {
let mut i = 0;
Expand All @@ -185,6 +196,7 @@ impl<T, S> Decodable for HashSet<T, S>
where T: Decodable + Hash + Eq,
S: BuildHasher + Default,
{
#[inline]
fn decode<D: Decoder>(d: &mut D) -> Result<HashSet<T, S>, D::Error> {
d.read_seq(|d, len| {
let state = Default::default();
Expand All @@ -198,6 +210,7 @@ impl<T, S> Decodable for HashSet<T, S>
}

impl<T: Encodable> Encodable for Rc<[T]> {
#[inline]
fn encode<E: Encoder>(&self, s: &mut E) -> Result<(), E::Error> {
s.emit_seq(self.len(), |s| {
for (index, e) in self.iter().enumerate() {
Expand All @@ -209,6 +222,7 @@ impl<T: Encodable> Encodable for Rc<[T]> {
}

impl<T: Decodable> Decodable for Rc<[T]> {
#[inline]
fn decode<D: Decoder>(d: &mut D) -> Result<Rc<[T]>, D::Error> {
d.read_seq(|d, len| {
let mut vec = Vec::with_capacity(len);
Expand All @@ -221,6 +235,7 @@ impl<T: Decodable> Decodable for Rc<[T]> {
}

impl<T: Encodable> Encodable for Arc<[T]> {
#[inline]
fn encode<E: Encoder>(&self, s: &mut E) -> Result<(), E::Error> {
s.emit_seq(self.len(), |s| {
for (index, e) in self.iter().enumerate() {
Expand All @@ -232,6 +247,7 @@ impl<T: Encodable> Encodable for Arc<[T]> {
}

impl<T: Decodable> Decodable for Arc<[T]> {
#[inline]
fn decode<D: Decoder>(d: &mut D) -> Result<Arc<[T]>, D::Error> {
d.read_seq(|d, len| {
let mut vec = Vec::with_capacity(len);
Expand Down
1 change: 1 addition & 0 deletions src/libserialize/leb128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
3 changes: 3 additions & 0 deletions src/libserialize/opaque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ impl Encoder {
self.data
}

#[inline]
pub fn emit_raw_bytes(&mut self, s: &[u8]) {
self.data.extend_from_slice(s);
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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()
}
Expand Down
Loading