Skip to content

Commit 9d73408

Browse files
authored
chore: use itertools::collect_vec to simplify some collections (#6518)
1 parent 46ac35d commit 9d73408

File tree

23 files changed

+44
-43
lines changed

23 files changed

+44
-43
lines changed

src/blocks/chain4u.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ impl Chain4UInner {
237237
})
238238
.unique()
239239
.map(|it| &self.ident2header[it])
240-
.collect::<Vec<_>>();
240+
.collect_vec();
241241

242242
let parent_tipset =
243243
match Tipset::new(parents.iter().map(|it| &self.ident2header[*it]).cloned()) {
@@ -315,10 +315,7 @@ impl Chain4UInner {
315315

316316
// Miner
317317
////////
318-
let sibling_miner_addresses = siblings
319-
.iter()
320-
.map(|it| it.miner_address)
321-
.collect::<Vec<_>>();
318+
let sibling_miner_addresses = siblings.iter().map(|it| it.miner_address).collect_vec();
322319
assert!(sibling_miner_addresses.iter().all_unique());
323320
match header.miner_address.inner {
324321
None => {

src/blocks/tipset.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl TipsetKey {
102102
self.to_cids()
103103
.into_iter()
104104
.map(terse_cid)
105-
.collect::<Vec<_>>()
105+
.collect_vec()
106106
.join(", ")
107107
}
108108

@@ -127,7 +127,7 @@ impl fmt::Display for TipsetKey {
127127
.to_cids()
128128
.into_iter()
129129
.map(|cid| cid.to_string())
130-
.collect::<Vec<_>>()
130+
.collect_vec()
131131
.join(", ");
132132
write!(f, "[{s}]")
133133
}

src/chain/store/tipset_tracker.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ impl<DB: Blockstore> TipsetTracker<DB> {
115115
#[cfg(test)]
116116
mod test {
117117
use crate::db::MemoryDB;
118+
use itertools::Itertools as _;
118119

119120
use super::*;
120121

@@ -140,12 +141,7 @@ mod test {
140141

141142
tipset_tracker.prune_entries(head_epoch);
142143

143-
let keys = tipset_tracker
144-
.entries
145-
.lock()
146-
.keys()
147-
.cloned()
148-
.collect::<Vec<_>>();
144+
let keys = tipset_tracker.entries.lock().keys().cloned().collect_vec();
149145

150146
assert_eq!(
151147
keys,

src/chain_sync/chain_follower.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,9 +1037,9 @@ mod tests {
10371037
.map(|v| {
10381038
v.into_iter()
10391039
.map(|ts| ts.weight().to_i64().unwrap_or(0))
1040-
.collect()
1040+
.collect_vec()
10411041
})
1042-
.collect::<Vec<Vec<_>>>();
1042+
.collect_vec();
10431043

10441044
// Both chains should start at the same tipset
10451045
assert_eq!(chains, vec![vec![1, 3], vec![1, 2]]);

src/chain_sync/tipset_syncer.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,7 @@ impl TipsetSyncerError {
8484
/// Concatenate all validation error messages into one comma separated
8585
/// version.
8686
fn concat(errs: NonEmpty<TipsetSyncerError>) -> Self {
87-
let msg = errs
88-
.iter()
89-
.map(|e| e.to_string())
90-
.collect::<Vec<_>>()
91-
.join(", ");
87+
let msg = errs.iter().map(|e| e.to_string()).collect_vec().join(", ");
9288

9389
TipsetSyncerError::Validation(msg)
9490
}

src/cli/humantoken.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ mod parse {
107107
use crate::shim::econ::TokenAmount;
108108
use anyhow::{anyhow, bail};
109109
use bigdecimal::{BigDecimal, ParseBigDecimalError};
110+
use itertools::Itertools as _;
110111
use nom::{
111112
IResult, Parser,
112113
bytes::complete::tag,
@@ -207,7 +208,7 @@ mod parse {
207208
.chain(scale.units)
208209
.map(move |prefix| (*prefix, scale))
209210
})
210-
.collect::<Vec<_>>();
211+
.collect_vec();
211212
scales.sort_by_key(|(prefix, _)| std::cmp::Reverse(*prefix));
212213

213214
for (prefix, scale) in scales {

src/cli/subcommands/mpool_cmd.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ mod tests {
285285
use crate::message::{Message, SignedMessage};
286286
use crate::message_pool::tests::create_smsg;
287287
use crate::shim::crypto::SignatureType;
288+
use itertools::Itertools as _;
288289
use std::borrow::BorrowMut;
289290

290291
#[test]
@@ -300,7 +301,7 @@ mod tests {
300301
smsg_vec.push(msg);
301302
}
302303

303-
let smsg_json_vec = smsg_vec.clone().into_iter().collect::<Vec<_>>();
304+
let smsg_json_vec = smsg_vec.clone().into_iter().collect_vec();
304305

305306
// No filtering is set up
306307
let smsg_filtered: Vec<SignedMessage> = filter_messages(smsg_json_vec, None, &None, &None)

src/cli_shared/cli/completion_cmd.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use crate::wallet::subcommands::Cli as ForestWalletCli;
77
use ahash::HashMap;
88
use clap::{Command, CommandFactory};
99
use clap_complete::aot::{Shell, generate};
10+
use itertools::Itertools as _;
1011

1112
/// Completion Command for generating shell completions for the CLI
1213
#[derive(Debug, clap::Args)]
@@ -29,7 +30,7 @@ impl CompletionCommand {
2930
("forest-tool".to_string(), ForestToolCli::command()),
3031
]);
3132

32-
let valid_binaries = bin_cmd_map.keys().cloned().collect::<Vec<_>>();
33+
let valid_binaries = bin_cmd_map.keys().cloned().collect_vec();
3334
let binaries = self.binaries.unwrap_or_else(|| valid_binaries.clone());
3435

3536
for b in binaries {

src/db/parity_db.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ mod test {
397397
use super::*;
398398
use crate::db::{BlockstoreWriteOpsSubscribable, tests::db_utils::parity::TempParityDB};
399399
use fvm_ipld_encoding::IPLD_RAW;
400+
use itertools::Itertools as _;
400401
use nom::AsBytes;
401402
use std::ops::Deref;
402403

@@ -502,7 +503,7 @@ mod test {
502503
entry.push(255);
503504
entry
504505
})
505-
.collect::<Vec<Vec<u8>>>();
506+
.collect_vec();
506507

507508
let cids = [
508509
Cid::new_v1(DAG_CBOR, MultihashCode::Blake2b256.digest(&data[0])),

src/lotus_json/actors/params/miner_params.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use fil_actors_shared::v16::reward::FilterEstimate;
1414
use fvm_ipld_encoding::{BytesDe, RawBytes};
1515
use fvm_shared4::deal::DealID;
1616
use fvm_shared4::sector::RegisteredUpdateProof;
17+
use itertools::Itertools as _;
1718
use num::BigInt;
1819
use pastey::paste;
1920
use schemars::JsonSchema;
@@ -2401,7 +2402,7 @@ macro_rules! impl_lotus_json_for_miner_prove_commit_sectors3_params {
24012402
p.notify
24022403
.into_iter()
24032404
.map(|n| n.into_lotus_json())
2404-
.collect::<Vec<_>>()
2405+
.collect_vec()
24052406
),
24062407
}).collect(),
24072408
}).collect(),
@@ -2527,7 +2528,7 @@ macro_rules! impl_lotus_json_for_miner_prove_replica_updates3_params {
25272528
p.notify
25282529
.into_iter()
25292530
.map(|n| n.into_lotus_json())
2530-
.collect::<Vec<_>>()
2531+
.collect_vec()
25312532
),
25322533
}).collect(),
25332534
}).collect(),
@@ -3156,7 +3157,7 @@ macro_rules! impl_lotus_json_for_miner_sector_activation_manifest {
31563157
self.notify
31573158
.into_iter()
31583159
.map(|n| n.into_lotus_json())
3159-
.collect::<Vec<_>>()
3160+
.collect_vec()
31603161
),
31613162
}
31623163
}

0 commit comments

Comments
 (0)