Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use Vec::with_capacity avoid realloc mem #1471

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion abci/src/application/kvstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ impl Application for KeyValueStoreApp {
}

fn finalize_block(&self, request: RequestFinalizeBlock) -> ResponseFinalizeBlock {
let mut events = Vec::new();
let mut events = Vec::with_capacity(request.txs.len());
for tx in request.txs {
let tx = std::str::from_utf8(&tx).unwrap();
let tx_parts = tx.split('=').collect::<Vec<&str>>();
Expand Down
2 changes: 1 addition & 1 deletion light-client/tests/model_based.rs
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ mod mbt {
}

fn model_based_test_batch(batch: ApalacheTestBatch) -> Vec<(String, String)> {
let mut res = Vec::new();
let mut res = Vec::with_capacity(batch.tests.len());
for test in batch.tests {
let tc = ApalacheTestCase {
model: batch.model.clone(),
Expand Down
3 changes: 2 additions & 1 deletion testgen/src/light_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ impl LightChain {
// TODO: like how does someone generate a chain with different validators at each height
pub fn default_with_length(num: u64) -> Self {
let mut last_block = LightBlock::new_default(1);
let mut light_blocks: Vec<LightBlock> = vec![last_block.clone()];
let mut light_blocks: Vec<LightBlock> = Vec::with_capacity(num as usize);
light_blocks.push(last_block.clone());

for _i in 2..=num {
// add "next" light block to the vector
Expand Down
1 change: 1 addition & 0 deletions testgen/src/tester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ impl Tester {
match batch(path, input) {
None => continue,
Some(tests) => {
res_tests.reserve_exact(tests.len());
for (name, input) in tests {
let test_path = path.to_string() + "/" + &name;
res_tests.push((test_path, input));
Expand Down
2 changes: 1 addition & 1 deletion tools/rpc-probe/src/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ async fn execute_parallel_interactions(
config: &PlanConfig,
interaction_sets: Vec<Vec<PlannedInteraction>>,
) -> Result<()> {
let mut handles = Vec::new();
let mut handles = Vec::with_capacity(interaction_sets.len());
for interactions in interaction_sets {
let mut inner_client = client.clone();
let inner_config = config.clone();
Expand Down