Skip to content

Commit bc900f5

Browse files
committed
Mark libserialize functions as inline
1 parent 5db71db commit bc900f5

File tree

4 files changed

+123
-0
lines changed

4 files changed

+123
-0
lines changed

src/libserialize/collection_impls.rs

+16
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use std::sync::Arc;
2020
impl<
2121
T: Encodable
2222
> Encodable for LinkedList<T> {
23+
#[inline]
2324
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
2425
s.emit_seq(self.len(), |s| {
2526
for (i, e) in self.iter().enumerate() {
@@ -31,6 +32,7 @@ impl<
3132
}
3233

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

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

5659
impl<T:Decodable> Decodable for VecDeque<T> {
60+
#[inline]
5761
fn decode<D: Decoder>(d: &mut D) -> Result<VecDeque<T>, D::Error> {
5862
d.read_seq(|d, len| {
5963
let mut deque: VecDeque<T> = VecDeque::new();
@@ -69,6 +73,7 @@ impl<
6973
K: Encodable + PartialEq + Ord,
7074
V: Encodable
7175
> Encodable for BTreeMap<K, V> {
76+
#[inline]
7277
fn encode<S: Encoder>(&self, e: &mut S) -> Result<(), S::Error> {
7378
e.emit_map(self.len(), |e| {
7479
let mut i = 0;
@@ -86,6 +91,7 @@ impl<
8691
K: Decodable + PartialEq + Ord,
8792
V: Decodable
8893
> Decodable for BTreeMap<K, V> {
94+
#[inline]
8995
fn decode<D: Decoder>(d: &mut D) -> Result<BTreeMap<K, V>, D::Error> {
9096
d.read_map(|d, len| {
9197
let mut map = BTreeMap::new();
@@ -102,6 +108,7 @@ impl<
102108
impl<
103109
T: Encodable + PartialEq + Ord
104110
> Encodable for BTreeSet<T> {
111+
#[inline]
105112
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
106113
s.emit_seq(self.len(), |s| {
107114
let mut i = 0;
@@ -117,6 +124,7 @@ impl<
117124
impl<
118125
T: Decodable + PartialEq + Ord
119126
> Decodable for BTreeSet<T> {
127+
#[inline]
120128
fn decode<D: Decoder>(d: &mut D) -> Result<BTreeSet<T>, D::Error> {
121129
d.read_seq(|d, len| {
122130
let mut set = BTreeSet::new();
@@ -133,6 +141,7 @@ impl<K, V, S> Encodable for HashMap<K, V, S>
133141
V: Encodable,
134142
S: BuildHasher,
135143
{
144+
#[inline]
136145
fn encode<E: Encoder>(&self, e: &mut E) -> Result<(), E::Error> {
137146
e.emit_map(self.len(), |e| {
138147
let mut i = 0;
@@ -151,6 +160,7 @@ impl<K, V, S> Decodable for HashMap<K, V, S>
151160
V: Decodable,
152161
S: BuildHasher + Default,
153162
{
163+
#[inline]
154164
fn decode<D: Decoder>(d: &mut D) -> Result<HashMap<K, V, S>, D::Error> {
155165
d.read_map(|d, len| {
156166
let state = Default::default();
@@ -169,6 +179,7 @@ impl<T, S> Encodable for HashSet<T, S>
169179
where T: Encodable + Hash + Eq,
170180
S: BuildHasher,
171181
{
182+
#[inline]
172183
fn encode<E: Encoder>(&self, s: &mut E) -> Result<(), E::Error> {
173184
s.emit_seq(self.len(), |s| {
174185
let mut i = 0;
@@ -185,6 +196,7 @@ impl<T, S> Decodable for HashSet<T, S>
185196
where T: Decodable + Hash + Eq,
186197
S: BuildHasher + Default,
187198
{
199+
#[inline]
188200
fn decode<D: Decoder>(d: &mut D) -> Result<HashSet<T, S>, D::Error> {
189201
d.read_seq(|d, len| {
190202
let state = Default::default();
@@ -198,6 +210,7 @@ impl<T, S> Decodable for HashSet<T, S>
198210
}
199211

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

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

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

234249
impl<T: Decodable> Decodable for Arc<[T]> {
250+
#[inline]
235251
fn decode<D: Decoder>(d: &mut D) -> Result<Arc<[T]>, D::Error> {
236252
d.read_seq(|d, len| {
237253
let mut vec = Vec::with_capacity(len);

src/libserialize/leb128.rs

+1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ pub fn write_signed_leb128_to<W>(mut value: i128, mut write: W)
118118
}
119119
}
120120

121+
#[inline]
121122
pub fn write_signed_leb128(out: &mut Vec<u8>, value: i128) {
122123
write_signed_leb128_to(value, |v| write_to_vec(out, v))
123124
}

src/libserialize/opaque.rs

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ impl Encoder {
3131
self.data
3232
}
3333

34+
#[inline]
3435
pub fn emit_raw_bytes(&mut self, s: &[u8]) {
3536
self.data.extend_from_slice(s);
3637
}
@@ -193,6 +194,7 @@ impl<'a> Decoder<'a> {
193194
self.position += bytes;
194195
}
195196

197+
#[inline]
196198
pub fn read_raw_bytes(&mut self, s: &mut [u8]) -> Result<(), String> {
197199
let start = self.position;
198200
let end = start + s.len();
@@ -326,6 +328,7 @@ impl<'a> serialize::Decoder for Decoder<'a> {
326328
Ok(Cow::Borrowed(s))
327329
}
328330

331+
#[inline]
329332
fn error(&mut self, err: &str) -> Self::Error {
330333
err.to_string()
331334
}

0 commit comments

Comments
 (0)