Skip to content

Commit

Permalink
speed up piece by avoiding iteration (#2213)
Browse files Browse the repository at this point in the history
* speed up piece

* review fix

* remove out of bound check
  • Loading branch information
zhiqiangxu authored Nov 9, 2023
1 parent d4eba10 commit 01345d4
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions crates/sc-consensus-subspace-rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -764,15 +764,12 @@ where
}
};

let indices = archived_segment
.segment_header
.segment_index()
.segment_piece_indexes();
let pieces = &archived_segment.pieces;
for (piece_index, piece) in indices.into_iter().zip(pieces.iter()) {
if requested_piece_index == piece_index {
return Ok(Some(piece.to_vec()));
}
if requested_piece_index.segment_index() == archived_segment.segment_header.segment_index()
{
return Ok(Some(
pieces[requested_piece_index.position() as usize].to_vec(),
));
}

Ok(None)
Expand Down

0 comments on commit 01345d4

Please sign in to comment.