Skip to content

Commit

Permalink
perf: reserve the result when running the tasks
Browse files Browse the repository at this point in the history
Signed-off-by: Amin Yahyaabadi <aminyahyaabadi74@gmail.com>
  • Loading branch information
aminya committed Dec 6, 2023
1 parent 3f3bc7f commit 1ba261c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool> {
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()));
Expand All @@ -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<T: Send + Sync + Clone + 'static>(&self, name: &str) -> Option<Arc<T>> {
self.dags.get(name).map(|dag| dag.get_result()).flatten()
self.dags.get(name).and_then(|dag| dag.get_result())
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/yaml/yaml_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 1ba261c

Please sign in to comment.