From 1ba261c80b30cc970701561a2639f2c573a53250 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Wed, 6 Dec 2023 01:06:50 -0800 Subject: [PATCH] perf: reserve the result when running the tasks Signed-off-by: Amin Yahyaabadi --- src/engine/mod.rs | 4 ++-- src/yaml/yaml_parser.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/engine/mod.rs b/src/engine/mod.rs index f1ed347..219c839 100644 --- a/src/engine/mod.rs +++ b/src/engine/mod.rs @@ -81,7 +81,7 @@ impl Engine { /// Execute all the Dags in the Engine in sequence according to the order numbers of the Dags in /// the sequence from small to large. The return value is the execution status of all tasks. pub fn run_sequential(&mut self) -> Vec { - let mut res = Vec::new(); + let mut res = Vec::with_capacity(self.sequence.len()); for seq in 1..self.sequence.len() + 1 { let name = self.sequence.get(&seq).unwrap().clone(); res.push(self.run_dag(name.as_str())); @@ -91,7 +91,7 @@ impl Engine { /// Given the name of the Dag, get the execution result of the specified Dag. pub fn get_dag_result(&self, name: &str) -> Option> { - self.dags.get(name).map(|dag| dag.get_result()).flatten() + self.dags.get(name).and_then(|dag| dag.get_result()) } } diff --git a/src/yaml/yaml_parser.rs b/src/yaml/yaml_parser.rs index 1acba32..df17870 100644 --- a/src/yaml/yaml_parser.rs +++ b/src/yaml/yaml_parser.rs @@ -77,8 +77,8 @@ impl Parser for YamlParser { .as_hash() .ok_or(YamlTaskError::StartWordError)?; - let mut tasks = Vec::new(); - let mut map = HashMap::new(); + let mut tasks = Vec::with_capacity(yaml_tasks.len()); + let mut map = HashMap::with_capacity(yaml_tasks.len()); // Read tasks for (v, w) in yaml_tasks { let id = v.as_str().unwrap();