Skip to content

Commit 7e1ec0d

Browse files
newrengitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4a5e74f commit 7e1ec0d

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

tree-diff.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -259,19 +259,12 @@ static void show_entry(struct diff_options *opt, const char *prefix, struct tree
259259
}
260260
}
261261

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)
263263
{
264-
int all_interesting = 0;
265264
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;
275268
if (!show) {
276269
update_tree_entry(t);
277270
continue;
@@ -286,14 +279,20 @@ static void skip_uninteresting(struct tree_desc *t, const char *base, int basele
286279
int diff_tree(struct tree_desc *t1, struct tree_desc *t2, const char *base, struct diff_options *opt)
287280
{
288281
int baselen = strlen(base);
282+
int all_t1_interesting = 0;
283+
int all_t2_interesting = 0;
289284

290285
for (;;) {
291286
if (DIFF_OPT_TST(opt, QUICK) &&
292287
DIFF_OPT_TST(opt, HAS_CHANGES))
293288
break;
294289
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);
297296
}
298297
if (!t1->size) {
299298
if (!t2->size)

0 commit comments

Comments
 (0)