Skip to content
Snippets Groups Projects
Commit 5e6d3e34 authored by vlorentz's avatar vlorentz
Browse files

origin-contributor: Free HashMap entries for nodes with no predecessors

parent c9c65170
No related branches found
No related tags found
No related merge requests found
Pipeline #11500 canceled
......@@ -3,7 +3,7 @@
// License: GNU General Public License version 3, or any later version
// See top-level LICENSE file for more information
use std::collections::HashMap;
use std::collections::hash_map::{Entry, HashMap};
use std::path::PathBuf;
use anyhow::{bail, Context, Result};
......@@ -190,11 +190,17 @@ where
let mut node_contributors = ContributorSet::default();
for succ in graph.successors(node) {
// If 'node' is a revision, then 'succ' is its parent revision
node_contributors.merge(
contributors
.get(&succ)
.expect("Parent's contributors are not initialized"),
);
let Entry::Occupied(entry) = contributors.entry(succ) else {
panic!("Parent's contributors are not initialized");
};
node_contributors.merge(entry.get());
*pending_predecessors
.get_mut(&succ)
.expect("successor has no pending predecessors") -= 1;
if *pending_predecessors.get(&succ).unwrap() == 0 {
// this value won't be read again, free it
entry.remove_entry();
}
}
node_contributors
};
......@@ -276,6 +282,11 @@ where
)
}
}
if num_predecessors == 0 {
// This set won't be needed by any other node, we can free it from memory
contributors.remove(&node);
}
}
Ok(())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment