From 86d0e9e1c765f434cc31933a970d1c1c1cfebea7 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Tue, 24 Jul 2018 15:29:31 +0200 Subject: [PATCH] Simplify a few functions in rustc_data_structures --- src/librustc_data_structures/accumulate_vec.rs | 5 ++--- src/librustc_data_structures/bitslice.rs | 3 +-- src/librustc_data_structures/small_vec.rs | 8 ++------ 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/src/librustc_data_structures/accumulate_vec.rs b/src/librustc_data_structures/accumulate_vec.rs index 2e8cca3f4f9bd..9423e6b3256c5 100644 --- a/src/librustc_data_structures/accumulate_vec.rs +++ b/src/librustc_data_structures/accumulate_vec.rs @@ -224,7 +224,7 @@ impl Encodable for AccumulateVec fn encode(&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(()) }) @@ -236,8 +236,7 @@ impl Decodable for AccumulateVec A::Element: Decodable { fn decode(d: &mut D) -> Result, 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() }) } } - diff --git a/src/librustc_data_structures/bitslice.rs b/src/librustc_data_structures/bitslice.rs index 79435aa398779..b8f191c2f57d8 100644 --- a/src/librustc_data_structures/bitslice.rs +++ b/src/librustc_data_structures/bitslice.rs @@ -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; diff --git a/src/librustc_data_structures/small_vec.rs b/src/librustc_data_structures/small_vec.rs index 83eb54fade177..4a72ab57fcc08 100644 --- a/src/librustc_data_structures/small_vec.rs +++ b/src/librustc_data_structures/small_vec.rs @@ -197,7 +197,7 @@ impl Encodable for SmallVec fn encode(&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(()) }) @@ -209,11 +209,7 @@ impl Decodable for SmallVec A::Element: Decodable { fn decode(d: &mut D) -> Result, 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() }) } }