Skip to content

Commit 703a61b

Browse files
committed
Merge branch 'sb/indent-heuristic-optim' into pu
"git diff --indent-heuristic" had a bad corner case performance. * sb/indent-heuristic-optim: xdiff: reduce indent heuristic overhead
2 parents 21638c1 + 301ef85 commit 703a61b

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

xdiff/xdiffi.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,11 @@ static void measure_split(const xdfile_t *xdf, long split,
574574
*/
575575
#define INDENT_WEIGHT 60
576576

577+
/*
578+
* How far do we slide a hunk at most?
579+
*/
580+
#define INDENT_HEURISTIC_MAX_SLIDING 100
581+
577582
/*
578583
* Compute a badness score for the hypothetical split whose measurements are
579584
* stored in m. The weight factors were determined empirically using the tools and
@@ -886,7 +891,12 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) {
886891
long shift, best_shift = -1;
887892
struct split_score best_score;
888893

889-
for (shift = earliest_end; shift <= g.end; shift++) {
894+
shift = earliest_end;
895+
if (g.end - groupsize - 1 > shift)
896+
shift = g.end - groupsize - 1;
897+
if (g.end - INDENT_HEURISTIC_MAX_SLIDING > shift)
898+
shift = g.end - INDENT_HEURISTIC_MAX_SLIDING;
899+
for (; shift <= g.end; shift++) {
890900
struct split_measurement m;
891901
struct split_score score = {0, 0};
892902

0 commit comments

Comments
 (0)