aboutsummaryrefslogtreecommitdiffstats
path: root/ui-ssdiff.c
diff options
context:
space:
mode:
authorGravatar Lars Hjemli <hjemli@gmail.com>2012-01-04 01:06:58 (JST)
committerGravatar Lars Hjemli <hjemli@gmail.com>2012-01-04 01:06:58 (JST)
commit04254fa903701943bd45a479a952cc213a5b112a (patch)
tree5ae865f0cae8505cb54d3360baa256fc684e3bbc /ui-ssdiff.c
parentd96d2c98ebc4c2d3765f5b35c4142e0e828a421b (diff)
parentf2ced535e9f2c2ada7f184735a07a1190a9d810f (diff)
downloadcgit-04254fa903701943bd45a479a952cc213a5b112a.zip
cgit-04254fa903701943bd45a479a952cc213a5b112a.tar.gz
Merge branch 'stable'
Diffstat (limited to 'ui-ssdiff.c')
-rw-r--r--ui-ssdiff.c33
1 files changed, 31 insertions, 2 deletions
diff --git a/ui-ssdiff.c b/ui-ssdiff.c
index 2481585..9fb5b11 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
6extern int use_ssdiff; 7extern int use_ssdiff;
7 8
8static int current_old_line, current_new_line; 9static int current_old_line, current_new_line;
10static int **L = NULL;
9 11
10struct deferred_lines { 12struct deferred_lines {
11 int line_no; 13 int line_no;
@@ -16,16 +18,42 @@ struct deferred_lines {
16static struct deferred_lines *deferred_old, *deferred_old_last; 18static struct deferred_lines *deferred_old, *deferred_old_last;
17static struct deferred_lines *deferred_new, *deferred_new_last; 19static struct deferred_lines *deferred_new, *deferred_new_last;
18 20
21static void create_or_reset_lcs_table()
22{
23 int i;
24
25 if (L != NULL) {
26 memset(*L, 0, sizeof(*L) * 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
19static char *longest_common_subsequence(char *A, char *B) 40static 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]; 45 int tmp1, tmp2, length;
25 int tmp1, tmp2;
26 int lcs_length; 46 int lcs_length;
27 char *result; 47 char *result;
28 48
49 length = (m + 1) * (n + 1);
50
51 // We bail if the lines are too long
52 if (length > MAX_SSDIFF_SIZE)
53 return NULL;
54
55 create_or_reset_lcs_table();
56
29 for (i = m; i >= 0; i--) { 57 for (i = m; i >= 0; i--) {
30 for (j = n; j >= 0; j--) { 58 for (j = n; j >= 0; j--) {
31 if (A[i] == '\0' || B[j] == '\0') { 59 if (A[i] == '\0' || B[j] == '\0') {
@@ -59,6 +87,7 @@ static char *longest_common_subsequence(char *A, char *B)
59 j += 1; 87 j += 1;
60 } 88 }
61 } 89 }
90
62 return result; 91 return result;
63} 92}
64 93