Skip to content

Commit

Permalink
Auto merge of #52697 - ljedrz:misc_data_structures, r=Mark-Simulacrum
Browse files Browse the repository at this point in the history
Simplify a few functions in rustc_data_structures

- drop `try!()` where it's superfluous
- change `try!()` to `?`
- squash a `push` with `push_str`
- refactor a push loop into an iterator
  • Loading branch information
bors committed Jul 30, 2018
2 parents e437841 + 86d0e9e commit 54628c8
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 11 deletions.
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);
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()
})
}
}

0 comments on commit 54628c8

Please sign in to comment.