Show More
@@ -802,6 +802,14 b' static void xdl_bug(const char *msg)' | |||||
802 | } |
|
802 | } | |
803 |
|
803 | |||
804 | /* |
|
804 | /* | |
|
805 | * For indentation heuristic, skip searching for better slide position after | |||
|
806 | * checking MAX_BORING lines without finding an improvement. This defends the | |||
|
807 | * indentation heuristic logic against pathological cases. The value is not | |||
|
808 | * picked scientifically but should be good enough. | |||
|
809 | */ | |||
|
810 | #define MAX_BORING 100 | |||
|
811 | ||||
|
812 | /* | |||
805 | * Move back and forward change groups for a consistent and pretty diff output. |
|
813 | * Move back and forward change groups for a consistent and pretty diff output. | |
806 | * This also helps in finding joinable change groups and reducing the diff |
|
814 | * This also helps in finding joinable change groups and reducing the diff | |
807 | * size. |
|
815 | * size. | |
@@ -897,19 +905,43 b' int xdl_change_compact(xdfile_t *xdf, xd' | |||||
897 | long shift, best_shift = -1; |
|
905 | long shift, best_shift = -1; | |
898 | struct split_score best_score; |
|
906 | struct split_score best_score; | |
899 |
|
907 | |||
900 | for (shift = earliest_end; shift <= g.end; shift++) { |
|
908 | /* | |
|
909 | * This is O(N * MAX_BLANKS) (N = shift-able lines). | |||
|
910 | * Even with MAX_BLANKS bounded to a small value, a | |||
|
911 | * large N could still make this loop take several | |||
|
912 | * times longer than the main diff algorithm. The | |||
|
913 | * "boring" value is to help cut down N to something | |||
|
914 | * like (MAX_BORING + groupsize). | |||
|
915 | * | |||
|
916 | * Scan from bottom to top. So we can exit the loop | |||
|
917 | * without compromising the assumption "for a same best | |||
|
918 | * score, pick the bottommost shift". | |||
|
919 | */ | |||
|
920 | int boring = 0; | |||
|
921 | for (shift = g.end; shift >= earliest_end; shift--) { | |||
901 | struct split_measurement m; |
|
922 | struct split_measurement m; | |
902 | struct split_score score = {0, 0}; |
|
923 | struct split_score score = {0, 0}; | |
|
924 | int cmp; | |||
903 |
|
925 | |||
904 | measure_split(xdf, shift, &m); |
|
926 | measure_split(xdf, shift, &m); | |
905 | score_add_split(&m, &score); |
|
927 | score_add_split(&m, &score); | |
906 | measure_split(xdf, shift - groupsize, &m); |
|
928 | measure_split(xdf, shift - groupsize, &m); | |
907 | score_add_split(&m, &score); |
|
929 | score_add_split(&m, &score); | |
908 | if (best_shift == -1 || |
|
930 | ||
909 | score_cmp(&score, &best_score) <= 0) { |
|
931 | if (best_shift == -1) { | |
|
932 | cmp = -1; | |||
|
933 | } else { | |||
|
934 | cmp = score_cmp(&score, &best_score); | |||
|
935 | } | |||
|
936 | if (cmp < 0) { | |||
|
937 | boring = 0; | |||
910 | best_score.effective_indent = score.effective_indent; |
|
938 | best_score.effective_indent = score.effective_indent; | |
911 | best_score.penalty = score.penalty; |
|
939 | best_score.penalty = score.penalty; | |
912 | best_shift = shift; |
|
940 | best_shift = shift; | |
|
941 | } else { | |||
|
942 | boring += 1; | |||
|
943 | if (boring >= MAX_BORING) | |||
|
944 | break; | |||
913 | } |
|
945 | } | |
914 | } |
|
946 | } | |
915 |
|
947 |
General Comments 0
You need to be logged in to leave comments.
Login now