Skip to content

Commit 8227f34

Browse files
committed
perf: Cache commit counts
1 parent ac704e6 commit 8227f34

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/git/repo.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ pub struct GitRepo {
124124
commits: std::cell::RefCell<std::collections::HashMap<git2::Oid, std::rc::Rc<Commit>>>,
125125
interned_strings: std::cell::RefCell<std::collections::HashSet<std::rc::Rc<str>>>,
126126
bases: std::cell::RefCell<std::collections::HashMap<(git2::Oid, git2::Oid), Option<git2::Oid>>>,
127+
counts: std::cell::RefCell<std::collections::HashMap<(git2::Oid, git2::Oid), Option<usize>>>,
127128
}
128129

129130
impl GitRepo {
@@ -135,6 +136,7 @@ impl GitRepo {
135136
commits: Default::default(),
136137
interned_strings: Default::default(),
137138
bases: Default::default(),
139+
counts: Default::default(),
138140
}
139141
}
140142

@@ -289,6 +291,14 @@ impl GitRepo {
289291
return Some(0);
290292
}
291293

294+
*self
295+
.counts
296+
.borrow_mut()
297+
.entry((base_id, head_id))
298+
.or_insert_with(|| self.commit_count_raw(base_id, head_id))
299+
}
300+
301+
fn commit_count_raw(&self, base_id: git2::Oid, head_id: git2::Oid) -> Option<usize> {
292302
let merge_base_id = self.merge_base(base_id, head_id)?;
293303
if merge_base_id != base_id {
294304
return None;

0 commit comments

Comments
 (0)