Skip to content

Commit ffd4f0f

Browse files
committed
avoid binary search if there is nothing to find (#470)
Even though failing is cheap, it's not free and can be done a million times.
1 parent b8f2f8b commit ffd4f0f

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

gitoxide-core/src/hours.rs

+13-9
Original file line numberDiff line numberDiff line change
@@ -361,15 +361,19 @@ fn estimate_hours(commits: &[(u32, actor::SignatureRef<'static>)], stats: &[(u32
361361
email: author.email,
362362
hours: FIRST_COMMIT_ADDITION_IN_MINUTES / 60.0 + hours_for_commits,
363363
num_commits: commits.len() as u32,
364-
stats: commits.iter().map(|t| &t.0).fold(Stats::default(), |mut acc, id| {
365-
match stats.binary_search_by(|t| t.0.cmp(id)) {
366-
Ok(idx) => {
367-
acc.add(&stats[idx].1);
368-
acc
369-
}
370-
Err(_) => acc,
371-
}
372-
}),
364+
stats: (!stats.is_empty())
365+
.then(|| {
366+
commits.iter().map(|t| &t.0).fold(Stats::default(), |mut acc, id| {
367+
match stats.binary_search_by(|t| t.0.cmp(id)) {
368+
Ok(idx) => {
369+
acc.add(&stats[idx].1);
370+
acc
371+
}
372+
Err(_) => acc,
373+
}
374+
})
375+
})
376+
.unwrap_or_default(),
373377
}
374378
}
375379

0 commit comments

Comments
 (0)