From 89a91b68569956c9164ac1e41e316f1becd2f0b4 Mon Sep 17 00:00:00 2001 From: coderofstuff <114628839+coderofstuff@users.noreply.github.com> Date: Fri, 6 Oct 2023 21:06:20 -0600 Subject: [PATCH] Code optimizations --- rpc/service/src/service.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/rpc/service/src/service.rs b/rpc/service/src/service.rs index d54d11d43..16e1b3ea7 100644 --- a/rpc/service/src/service.rs +++ b/rpc/service/src/service.rs @@ -553,7 +553,7 @@ impl RpcApi for RpcCoreService { (curr_daa_score - header.daa_score).checked_mul(1000).unwrap_or(u64::MAX) } else { // "next" header is the one that we processed last iteration - let next_header = headers.get(header_idx - 1).unwrap(); + let next_header = &headers[header_idx - 1]; let time_between_now_and_next = next_header.timestamp - header.timestamp; let score_between_now_and_request = curr_daa_score - header.daa_score; let score_between_now_and_next = next_header.daa_score - header.daa_score; @@ -575,11 +575,7 @@ impl RpcApi for RpcCoreService { } } - let mut timestamps = Vec::::new(); - - for curr_daa_score in request.daa_scores { - timestamps.push(daa_score_timestamp_map[&curr_daa_score]); - } + let timestamps = request.daa_scores.iter().map(|curr_daa_score| daa_score_timestamp_map[curr_daa_score]).collect(); Ok(GetDaaScoreTimestampEstimateResponse::new(timestamps)) }