@matheusbsbs / matheus-bagliano / commits / 7e1ec0d415
Fork 0

diff_tree(): Skip skip_uninteresting() when all remaining paths interesting

In 1d848f6 (tree_entry_interesting(): allow it to say "everything is interesting" 2007-03-21), both show_tree() and skip_uninteresting() were modified to determine if all remaining tree entries were interesting. However, the latter returns as soon as it finds the first interesting path, without any way to signal to its caller (namely, diff_tree()) that all remaining paths are interesting, making these extra checks useless. Pass whether all remaining entries are interesting back to diff_tree(), and whenever they are, have diff_tree() skip subsequent calls to skip_uninteresting(). With this change, I measure speedups of 3-4% for the commands $ git rev-list --quiet HEAD -- Documentation/ $ git rev-list --quiet HEAD -- t/ in git.git. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Elijah Newren committed Aug 26, 2010 at 00:21 UTC 7e1ec0d415dbea96d4ec6995c00cb66cdff7ceff
1 file changed +12 -13
tree-diff.c
+12 -13
@@ -259,19 +259,12 @@ static void show_entry(struct diff_options *opt, const char *prefix, struct tree
259 }
260 }
261
262 -static void skip_uninteresting(struct tree_desc *t, const char *base, int baselen, struct diff_options *opt)
262 +static void skip_uninteresting(struct tree_desc *t, const char *base, int baselen, struct diff_options *opt, int *all_interesting)
263 {
264 - int all_interesting = 0;
264 while (t->size) {
266 - int show;
267 -
268 - if (all_interesting)
269 - show = 1;
270 - else {
271 - show = tree_entry_interesting(t, base, baselen, opt);
272 - if (show == 2)
273 - all_interesting = 1;
274 - }
265 + int show = tree_entry_interesting(t, base, baselen, opt);
266 + if (show == 2)
267 + *all_interesting = 1;
268 if (!show) {
269 update_tree_entry(t);
270 continue;
@@ -286,14 +279,20 @@ static void skip_uninteresting(struct tree_desc *t, const char *base, int basele
279 int diff_tree(struct tree_desc *t1, struct tree_desc *t2, const char *base, struct diff_options *opt)
280 {
281 int baselen = strlen(base);
282 + int all_t1_interesting = 0;
283 + int all_t2_interesting = 0;
284
285 for (;;) {
286 if (DIFF_OPT_TST(opt, QUICK) &&
287 DIFF_OPT_TST(opt, HAS_CHANGES))
288 break;
289 if (opt->nr_paths) {
295 - skip_uninteresting(t1, base, baselen, opt);
296 - skip_uninteresting(t2, base, baselen, opt);
290 + if (!all_t1_interesting)
291 + skip_uninteresting(t1, base, baselen, opt,
292 + &all_t1_interesting);
293 + if (!all_t2_interesting)
294 + skip_uninteresting(t2, base, baselen, opt,
295 + &all_t2_interesting);
296 }
297 if (!t1->size) {
298 if (!t2->size)