Fossil SCM

Short-circuit a rare pathological case in the diff generator to prevent it from taking too much time.

drh 2012-11-08 16:25 trunk
Commit 353438a83bf862cb680b25f5c24f51f59faf39d0
1 file changed +9
+9
--- src/diff.c
+++ src/diff.c
@@ -989,10 +989,19 @@
989989
}
990990
if( nRight==0 ){
991991
memset(aM, 1, nLeft);
992992
return aM;
993993
}
994
+
995
+ /* This algorithm is O(N**2). So if N is too big, bail out with a
996
+ ** simple (but stupid and ugly) result that doesn't take too long. */
997
+ if( nLeft*nRight>100000 ){
998
+ memset(aM, 3, nRight);
999
+ memset(aM+nRight, 1, nLeft);
1000
+ return aM;
1001
+ }
1002
+
9941003
if( nRight < (sizeof(aBuf)/sizeof(aBuf[0]))-1 ){
9951004
pToFree = 0;
9961005
a = aBuf;
9971006
}else{
9981007
a = pToFree = fossil_malloc( sizeof(a[0])*(nRight+1) );
9991008
--- src/diff.c
+++ src/diff.c
@@ -989,10 +989,19 @@
989 }
990 if( nRight==0 ){
991 memset(aM, 1, nLeft);
992 return aM;
993 }
 
 
 
 
 
 
 
 
 
994 if( nRight < (sizeof(aBuf)/sizeof(aBuf[0]))-1 ){
995 pToFree = 0;
996 a = aBuf;
997 }else{
998 a = pToFree = fossil_malloc( sizeof(a[0])*(nRight+1) );
999
--- src/diff.c
+++ src/diff.c
@@ -989,10 +989,19 @@
989 }
990 if( nRight==0 ){
991 memset(aM, 1, nLeft);
992 return aM;
993 }
994
995 /* This algorithm is O(N**2). So if N is too big, bail out with a
996 ** simple (but stupid and ugly) result that doesn't take too long. */
997 if( nLeft*nRight>100000 ){
998 memset(aM, 3, nRight);
999 memset(aM+nRight, 1, nLeft);
1000 return aM;
1001 }
1002
1003 if( nRight < (sizeof(aBuf)/sizeof(aBuf[0]))-1 ){
1004 pToFree = 0;
1005 a = aBuf;
1006 }else{
1007 a = pToFree = fossil_malloc( sizeof(a[0])*(nRight+1) );
1008

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button