Use collect
for decoding more collection types.
This commit is contained in:
parent
5f69ca62f2
commit
2db1d59830
1 changed files with 6 additions and 40 deletions
|
@ -578,13 +578,7 @@ where
|
||||||
{
|
{
|
||||||
fn decode(d: &mut D) -> BTreeMap<K, V> {
|
fn decode(d: &mut D) -> BTreeMap<K, V> {
|
||||||
let len = d.read_usize();
|
let len = d.read_usize();
|
||||||
let mut map = BTreeMap::new();
|
(0..len).map(|_| (Decodable::decode(d), Decodable::decode(d))).collect()
|
||||||
for _ in 0..len {
|
|
||||||
let key = Decodable::decode(d);
|
|
||||||
let val = Decodable::decode(d);
|
|
||||||
map.insert(key, val);
|
|
||||||
}
|
|
||||||
map
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -606,11 +600,7 @@ where
|
||||||
{
|
{
|
||||||
fn decode(d: &mut D) -> BTreeSet<T> {
|
fn decode(d: &mut D) -> BTreeSet<T> {
|
||||||
let len = d.read_usize();
|
let len = d.read_usize();
|
||||||
let mut set = BTreeSet::new();
|
(0..len).map(|_| Decodable::decode(d)).collect()
|
||||||
for _ in 0..len {
|
|
||||||
set.insert(Decodable::decode(d));
|
|
||||||
}
|
|
||||||
set
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -637,14 +627,7 @@ where
|
||||||
{
|
{
|
||||||
fn decode(d: &mut D) -> HashMap<K, V, S> {
|
fn decode(d: &mut D) -> HashMap<K, V, S> {
|
||||||
let len = d.read_usize();
|
let len = d.read_usize();
|
||||||
let state = Default::default();
|
(0..len).map(|_| (Decodable::decode(d), Decodable::decode(d))).collect()
|
||||||
let mut map = HashMap::with_capacity_and_hasher(len, state);
|
|
||||||
for _ in 0..len {
|
|
||||||
let key = Decodable::decode(d);
|
|
||||||
let val = Decodable::decode(d);
|
|
||||||
map.insert(key, val);
|
|
||||||
}
|
|
||||||
map
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -668,12 +651,7 @@ where
|
||||||
{
|
{
|
||||||
fn decode(d: &mut D) -> HashSet<T, S> {
|
fn decode(d: &mut D) -> HashSet<T, S> {
|
||||||
let len = d.read_usize();
|
let len = d.read_usize();
|
||||||
let state = Default::default();
|
(0..len).map(|_| Decodable::decode(d)).collect()
|
||||||
let mut set = HashSet::with_capacity_and_hasher(len, state);
|
|
||||||
for _ in 0..len {
|
|
||||||
set.insert(Decodable::decode(d));
|
|
||||||
}
|
|
||||||
set
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -700,14 +678,7 @@ where
|
||||||
{
|
{
|
||||||
fn decode(d: &mut D) -> indexmap::IndexMap<K, V, S> {
|
fn decode(d: &mut D) -> indexmap::IndexMap<K, V, S> {
|
||||||
let len = d.read_usize();
|
let len = d.read_usize();
|
||||||
let state = Default::default();
|
(0..len).map(|_| (Decodable::decode(d), Decodable::decode(d))).collect()
|
||||||
let mut map = indexmap::IndexMap::with_capacity_and_hasher(len, state);
|
|
||||||
for _ in 0..len {
|
|
||||||
let key = Decodable::decode(d);
|
|
||||||
let val = Decodable::decode(d);
|
|
||||||
map.insert(key, val);
|
|
||||||
}
|
|
||||||
map
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -731,12 +702,7 @@ where
|
||||||
{
|
{
|
||||||
fn decode(d: &mut D) -> indexmap::IndexSet<T, S> {
|
fn decode(d: &mut D) -> indexmap::IndexSet<T, S> {
|
||||||
let len = d.read_usize();
|
let len = d.read_usize();
|
||||||
let state = Default::default();
|
(0..len).map(|_| Decodable::decode(d)).collect()
|
||||||
let mut set = indexmap::IndexSet::with_capacity_and_hasher(len, state);
|
|
||||||
for _ in 0..len {
|
|
||||||
set.insert(Decodable::decode(d));
|
|
||||||
}
|
|
||||||
set
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue