Skip to content

Commit

Permalink
imp: use Vec::with_capacity avoid realloc mem (#123)
Browse files Browse the repository at this point in the history
* use Vec::with_capacity avoid realloc mem

* imp: imp

---------

Co-authored-by: srdtrk <[email protected]>
  • Loading branch information
nkysg and srdtrk authored Nov 1, 2024
1 parent d5b686f commit 622dd39
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions packages/utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@ use tendermint::merkle::proof::ProofOps;
pub fn convert_tm_to_ics_merkle_proof(
tm_proof: &ProofOps,
) -> Result<MerkleProof, prost::DecodeError> {
let mut proofs = Vec::new();

for op in &tm_proof.ops {
let mut parsed = CommitmentProof { proof: None };
let mut proofs = Vec::with_capacity(tm_proof.ops.len());

for (i, op) in tm_proof.ops.iter().enumerate() {
let mut parsed = CommitmentProof::default();
prost::Message::merge(&mut parsed, op.data.as_slice())?;

proofs.push(parsed);
proofs[i] = parsed;
}

Ok(MerkleProof { proofs })
Expand Down

0 comments on commit 622dd39

Please sign in to comment.