Skip to content

Commit

Permalink
use flat_map instead of map + flatten (availproject#189)
Browse files Browse the repository at this point in the history
  • Loading branch information
Leouarz authored Jul 27, 2023
1 parent 8b3df03 commit 5f61d8d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
13 changes: 5 additions & 8 deletions pallets/system/src/submitted_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,8 @@ where
I: Iterator<Item = &'a OpaqueExtrinsic>,
{
let metrics = Metrics::new_shared();
let submitted_data = opaque_itr
.map(|ext| extract_and_inspect::<E>(ext, Rc::clone(&metrics)))
.flatten();
let submitted_data =
opaque_itr.flat_map(|ext| extract_and_inspect::<E>(ext, Rc::clone(&metrics)));

root(submitted_data, Rc::clone(&metrics))
}
Expand All @@ -97,7 +96,7 @@ where
I: Iterator<Item = C>,
{
let metrics = Metrics::new_shared();
let submitted_data = calls.map(|c| F::filter(c, Rc::clone(&metrics))).flatten();
let submitted_data = calls.flat_map(|c| F::filter(c, Rc::clone(&metrics)));
root(submitted_data, Rc::clone(&metrics))
}

Expand Down Expand Up @@ -167,8 +166,7 @@ where
{
let metrics = Metrics::new_shared();
let submitted_data = app_extrinsics
.map(|ext| extract_and_inspect::<E>(ext, Rc::clone(&metrics)))
.flatten()
.flat_map(|ext| extract_and_inspect::<E>(ext, Rc::clone(&metrics)))
.collect::<Vec<_>>();

proof(submitted_data, data_index, Rc::clone(&metrics))
Expand All @@ -190,8 +188,7 @@ where
{
let metrics = Metrics::new_shared();
let submitted_data = calls
.map(|c| F::filter(c, Rc::clone(&metrics)))
.flatten()
.flat_map(|c| F::filter(c, Rc::clone(&metrics)))
.collect::<Vec<_>>();

proof(submitted_data, data_index, Rc::clone(&metrics))
Expand Down
3 changes: 1 addition & 2 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,7 @@ impl submitted_data::Filter<RuntimeCall> for Runtime {
fn process_calls(calls: Vec<RuntimeCall>, metrics: &submitted_data::RcMetrics) -> Vec<Vec<u8>> {
calls
.into_iter()
.map(|call| Self::filter(call, Rc::clone(metrics)))
.flatten()
.flat_map(|call| Self::filter(call, Rc::clone(metrics)))
.collect()
}
}
Expand Down

0 comments on commit 5f61d8d

Please sign in to comment.