Skip to content

Commit

Permalink
use Vec::with_capacity avoid realloc
Browse files Browse the repository at this point in the history
  • Loading branch information
nkysggsy committed Dec 22, 2024
1 parent 9e3a4ea commit 43fc8b3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion fuel-merkle/src/binary/merkle_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ where
storage: StorageType,
leaves_count: u64,
) -> Result<Self, MerkleTreeError<StorageError>> {
let mut nodes = Vec::new();
let peaks = peak_positions(leaves_count).ok_or(MerkleTreeError::TooLarge)?;
let mut nodes = Vec::with_capacity(peaks.len());
for peak in peaks.iter() {
let key = peak.in_order_index();
let node = storage
Expand Down
6 changes: 3 additions & 3 deletions fuel-tx/src/transaction/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl CommonMetadata {
.collect_vec();

let mut offset = tx.inputs_offset();
let mut inputs_offset_at = Vec::new();
let mut inputs_offset_at = Vec::with_capacity(tx.inputs().len());
for (index, input) in tx.inputs().iter().enumerate() {
let i = offset;
offset = offset
Expand All @@ -91,7 +91,7 @@ impl CommonMetadata {
}

let mut offset = tx.outputs_offset();
let mut outputs_offset_at = Vec::new();
let mut outputs_offset_at = Vec::with_capacity(tx.outputs.len());
for (index, output) in tx.outputs().iter().enumerate() {
let i = offset;
offset = offset
Expand All @@ -101,7 +101,7 @@ impl CommonMetadata {
}

let mut offset = tx.witnesses_offset();
let mut witnesses_offset_at = Vec::new();
let mut witnesses_offset_at = Vec::with_capacity(tx.witness().len());
for (index, witnesses) in tx.witnesses().iter().enumerate() {
let i = offset;
offset = offset
Expand Down

0 comments on commit 43fc8b3

Please sign in to comment.