Rewrite iterator processing using unzip
Co-authored-by: Jane Lusby <jlusby42@gmail.com>
This commit is contained in:
parent
91476535d3
commit
d64c2976e3
|
@ -115,21 +115,15 @@ impl AdjustedDifficulty {
|
||||||
{
|
{
|
||||||
let candidate_height = (previous_block_height + 1).expect("next block height is valid");
|
let candidate_height = (previous_block_height + 1).expect("next block height is valid");
|
||||||
|
|
||||||
// unzip would be a lot nicer here, but we can't satisfy its trait bounds
|
let (relevant_difficulty_thresholds, relevant_times) = context
|
||||||
let context: Vec<_> = context
|
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.take(POW_AVERAGING_WINDOW + POW_MEDIAN_BLOCK_SPAN)
|
.take(POW_AVERAGING_WINDOW + POW_MEDIAN_BLOCK_SPAN)
|
||||||
.collect();
|
.unzip::<_, _, Vec<_>, Vec<_>>();
|
||||||
let relevant_difficulty_thresholds = context
|
|
||||||
.iter()
|
let relevant_difficulty_thresholds = relevant_difficulty_thresholds
|
||||||
.map(|pair| pair.0)
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
.try_into()
|
.try_into()
|
||||||
.expect("not enough context: difficulty adjustment needs at least 28 (PoWAveragingWindow + PoWMedianBlockSpan) headers");
|
.expect("not enough context: difficulty adjustment needs at least 28 (PoWAveragingWindow + PoWMedianBlockSpan) headers");
|
||||||
let relevant_times = context
|
let relevant_times = relevant_times
|
||||||
.iter()
|
|
||||||
.map(|pair| pair.1)
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
.try_into()
|
.try_into()
|
||||||
.expect("not enough context: difficulty adjustment needs at least 28 (PoWAveragingWindow + PoWMedianBlockSpan) headers");
|
.expect("not enough context: difficulty adjustment needs at least 28 (PoWAveragingWindow + PoWMedianBlockSpan) headers");
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue