Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 2 additions & 3 deletions src/librustc_data_structures/accumulate_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ impl<A> Encodable for AccumulateVec<A>
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
s.emit_seq(self.len(), |s| {
for (i, e) in self.iter().enumerate() {
try!(s.emit_seq_elt(i, |s| e.encode(s)));
s.emit_seq_elt(i, |s| e.encode(s))?;
}
Ok(())
})
Expand All @@ -236,8 +236,7 @@ impl<A> Decodable for AccumulateVec<A>
A::Element: Decodable {
fn decode<D: Decoder>(d: &mut D) -> Result<AccumulateVec<A>, D::Error> {
d.read_seq(|d, len| {
Ok(try!((0..len).map(|i| d.read_seq_elt(i, |d| Decodable::decode(d))).collect()))
(0..len).map(|i| d.read_seq_elt(i, |d| Decodable::decode(d))).collect()
})
}
}

3 changes: 1 addition & 2 deletions src/librustc_data_structures/bitslice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ pub fn bits_to_string(words: &[Word], bits: usize) -> String {
assert!(mask <= 0xFF);
let byte = v & mask;

result.push(sep);
result.push_str(&format!("{:02x}", byte));
result.push_str(&format!("{}{:02x}", sep, byte));

if remain <= 8 { break; }
v >>= 8;
Expand Down
8 changes: 2 additions & 6 deletions src/librustc_data_structures/small_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ impl<A> Encodable for SmallVec<A>
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
s.emit_seq(self.len(), |s| {
for (i, e) in self.iter().enumerate() {
try!(s.emit_seq_elt(i, |s| e.encode(s)));
s.emit_seq_elt(i, |s| e.encode(s))?;
}
Ok(())
})
Expand All @@ -209,11 +209,7 @@ impl<A> Decodable for SmallVec<A>
A::Element: Decodable {
fn decode<D: Decoder>(d: &mut D) -> Result<SmallVec<A>, D::Error> {
d.read_seq(|d, len| {
let mut vec = SmallVec::with_capacity(len);
Copy link
Contributor

Choose a reason for hiding this comment

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

I have a hunch that this was deliberately done for optimization

cc @nnethercote

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't have a good sense of how collect() works. Will it use size_hint from the range to pre-allocate an appropriate capacity?

Copy link
Member

Choose a reason for hiding this comment

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

It should, yes.

for i in 0..len {
vec.push(try!(d.read_seq_elt(i, |d| Decodable::decode(d))));
}
Ok(vec)
(0..len).map(|i| d.read_seq_elt(i, |d| Decodable::decode(d))).collect()
})
}
}