diff options
author | Matthias Beyer <matthias.beyer@atos.net> | 2021-06-21 12:38:07 +0200 |
---|---|---|
committer | Matthias Beyer <matthias.beyer@atos.net> | 2021-08-18 10:10:29 +0200 |
commit | 0c310bab9e4df023acc0fe006d1e25ee07687c87 (patch) | |
tree | 31aa010af30faaa7836e529071b4b2b6031619f4 | |
parent | 0bd69dc366916a25f077fc2de2ffa0a57bbae63d (diff) |
Refactor: Calculate number of dependency for allocating HashMaps
After this refactoring, the number of dependencies is calculated _before_ the
hashmaps for the artifacts/errors are allocated, so that we allocate
approximately the right amount of memory.
Signed-off-by: Matthias Beyer <matthias.beyer@atos.net>
-rw-r--r-- | src/orchestrator/orchestrator.rs | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/orchestrator/orchestrator.rs b/src/orchestrator/orchestrator.rs index 0e548e3..fc15494 100644 --- a/src/orchestrator/orchestrator.rs +++ b/src/orchestrator/orchestrator.rs @@ -559,12 +559,13 @@ impl<'a> JobTask<'a> { self.jobdef.dependencies.iter().map(|u| u.to_string()).collect::<Vec<String>>() }); + let dep_len = self.jobdef.dependencies.len(); // A list of job run results from dependencies that were received from the tasks for the // dependencies - let mut received_dependencies: HashMap<Uuid, Vec<ProducedArtifact>> = HashMap::new(); + let mut received_dependencies: HashMap<Uuid, Vec<ProducedArtifact>> = HashMap::with_capacity(dep_len); // A list of errors that were received from the tasks for the dependencies - let mut received_errors: HashMap<Uuid, Error> = HashMap::with_capacity(self.jobdef.dependencies.len()); + let mut received_errors: HashMap<Uuid, Error> = HashMap::with_capacity(dep_len); // Helper function to check whether all UUIDs are in a list of UUIDs let all_dependencies_are_in = |dependency_uuids: &[Uuid], list: &HashMap<Uuid, Vec<_>>| { @@ -582,7 +583,7 @@ impl<'a> JobTask<'a> { self.jobdef.job.package().name(), self.jobdef.job.package().version(), received_dependencies.iter().filter(|(rd_uuid, _)| self.jobdef.dependencies.contains(rd_uuid)).count(), - self.jobdef.dependencies.len()) + dep_len) }); trace!("[{}]: Updated bar", self.jobdef.job.uuid()); |