diff options
Diffstat (limited to 'ui-ssdiff.c')
-rw-r--r-- | ui-ssdiff.c | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/ui-ssdiff.c b/ui-ssdiff.c index 2481585..0cff4b8 100644 --- a/ui-ssdiff.c +++ b/ui-ssdiff.c | |||
@@ -2,10 +2,12 @@ | |||
2 | #include "html.h" | 2 | #include "html.h" |
3 | #include "ui-shared.h" | 3 | #include "ui-shared.h" |
4 | #include "ui-diff.h" | 4 | #include "ui-diff.h" |
5 | #include "ui-ssdiff.h" | ||
5 | 6 | ||
6 | extern int use_ssdiff; | 7 | extern int use_ssdiff; |
7 | 8 | ||
8 | static int current_old_line, current_new_line; | 9 | static int current_old_line, current_new_line; |
10 | static int **L = NULL; | ||
9 | 11 | ||
10 | struct deferred_lines { | 12 | struct deferred_lines { |
11 | int line_no; | 13 | int line_no; |
@@ -16,16 +18,40 @@ struct deferred_lines { | |||
16 | static struct deferred_lines *deferred_old, *deferred_old_last; | 18 | static struct deferred_lines *deferred_old, *deferred_old_last; |
17 | static struct deferred_lines *deferred_new, *deferred_new_last; | 19 | static struct deferred_lines *deferred_new, *deferred_new_last; |
18 | 20 | ||
21 | static void create_or_reset_lcs_table() | ||
22 | { | ||
23 | int i; | ||
24 | |||
25 | if (L != NULL) { | ||
26 | memset(*L, 0, sizeof(int) * MAX_SSDIFF_SIZE); | ||
27 | return; | ||
28 | } | ||
29 | |||
30 | // xcalloc will die if we ran out of memory; | ||
31 | // not very helpful for debugging | ||
32 | L = (int**)xcalloc(MAX_SSDIFF_M, sizeof(int *)); | ||
33 | *L = (int*)xcalloc(MAX_SSDIFF_SIZE, sizeof(int)); | ||
34 | |||
35 | for (i = 1; i < MAX_SSDIFF_M; i++) { | ||
36 | L[i] = *L + i * MAX_SSDIFF_N; | ||
37 | } | ||
38 | } | ||
39 | |||
19 | static char *longest_common_subsequence(char *A, char *B) | 40 | static char *longest_common_subsequence(char *A, char *B) |
20 | { | 41 | { |
21 | int i, j, ri; | 42 | int i, j, ri; |
22 | int m = strlen(A); | 43 | int m = strlen(A); |
23 | int n = strlen(B); | 44 | int n = strlen(B); |
24 | int L[m + 1][n + 1]; | ||
25 | int tmp1, tmp2; | 45 | int tmp1, tmp2; |
26 | int lcs_length; | 46 | int lcs_length; |
27 | char *result; | 47 | char *result; |
28 | 48 | ||
49 | // We bail if the lines are too long | ||
50 | if (m >= MAX_SSDIFF_M || n >= MAX_SSDIFF_N) | ||
51 | return NULL; | ||
52 | |||
53 | create_or_reset_lcs_table(); | ||
54 | |||
29 | for (i = m; i >= 0; i--) { | 55 | for (i = m; i >= 0; i--) { |
30 | for (j = n; j >= 0; j--) { | 56 | for (j = n; j >= 0; j--) { |
31 | if (A[i] == '\0' || B[j] == '\0') { | 57 | if (A[i] == '\0' || B[j] == '\0') { |
@@ -59,6 +85,7 @@ static char *longest_common_subsequence(char *A, char *B) | |||
59 | j += 1; | 85 | j += 1; |
60 | } | 86 | } |
61 | } | 87 | } |
88 | |||
62 | return result; | 89 | return result; |
63 | } | 90 | } |
64 | 91 | ||