Skip to content

Commit

Permalink
Mark libserialize functions as inline
Browse files Browse the repository at this point in the history
  • Loading branch information
BurntPizza committed Aug 15, 2018
1 parent 5db71db commit bc900f5
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/libserialize/collection_impls.rs
Expand Up @@ -20,6 +20,7 @@ use std::sync::Arc;
impl<
T: Encodable
> Encodable for LinkedList<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 @@ -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
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
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> {
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

0 comments on commit bc900f5

Please sign in to comment.