Fossil SCM

Another minor performance enhancement on sbs diff.

drh 2012-02-07 20:04 trunk
Commit 3e3feb2dda2c95070e0d34dc7d5ec4304a914bf6
1 file changed +4 -5
+4 -5
--- src/diff.c
+++ src/diff.c
@@ -576,23 +576,22 @@
576576
if( nA>250 ) nA = 250;
577577
if( nB>250 ) nB = 250;
578578
avg = (nA+nB)/2;
579579
if( avg==0 ) return 0;
580580
memset(aFirst, 0, sizeof(aFirst));
581
- memset(aNext, 0, nB);
582581
zA--; zB--; /* Make both zA[] and zB[] 1-indexed */
583582
for(i=nB; i>0; i--){
584583
c = (unsigned char)zB[i];
585584
aNext[i] = aFirst[c];
586585
aFirst[c] = i;
587586
}
588587
best = 0;
589
- for(i=1; i<=nA; i++){
588
+ for(i=1; i<=nA-best; i++){
590589
c = (unsigned char)zA[i];
591
- for(j=aFirst[c]; j>0; j = aNext[j]){
592
- int limit = minInt(nA-i, nB-j)+1;
593
- for(k=1; k<limit && zA[k+i]==zB[k+j]; k++){}
590
+ for(j=aFirst[c]; j>0 && j<nB-best; j = aNext[j]){
591
+ int limit = minInt(nA-i, nB-j);
592
+ for(k=1; k<=limit && zA[k+i]==zB[k+j]; k++){}
594593
if( k>best ) best = k;
595594
}
596595
}
597596
score = (best>avg) ? 0 : (avg - best)*100/avg;
598597
599598
--- src/diff.c
+++ src/diff.c
@@ -576,23 +576,22 @@
576 if( nA>250 ) nA = 250;
577 if( nB>250 ) nB = 250;
578 avg = (nA+nB)/2;
579 if( avg==0 ) return 0;
580 memset(aFirst, 0, sizeof(aFirst));
581 memset(aNext, 0, nB);
582 zA--; zB--; /* Make both zA[] and zB[] 1-indexed */
583 for(i=nB; i>0; i--){
584 c = (unsigned char)zB[i];
585 aNext[i] = aFirst[c];
586 aFirst[c] = i;
587 }
588 best = 0;
589 for(i=1; i<=nA; i++){
590 c = (unsigned char)zA[i];
591 for(j=aFirst[c]; j>0; j = aNext[j]){
592 int limit = minInt(nA-i, nB-j)+1;
593 for(k=1; k<limit && zA[k+i]==zB[k+j]; k++){}
594 if( k>best ) best = k;
595 }
596 }
597 score = (best>avg) ? 0 : (avg - best)*100/avg;
598
599
--- src/diff.c
+++ src/diff.c
@@ -576,23 +576,22 @@
576 if( nA>250 ) nA = 250;
577 if( nB>250 ) nB = 250;
578 avg = (nA+nB)/2;
579 if( avg==0 ) return 0;
580 memset(aFirst, 0, sizeof(aFirst));
 
581 zA--; zB--; /* Make both zA[] and zB[] 1-indexed */
582 for(i=nB; i>0; i--){
583 c = (unsigned char)zB[i];
584 aNext[i] = aFirst[c];
585 aFirst[c] = i;
586 }
587 best = 0;
588 for(i=1; i<=nA-best; i++){
589 c = (unsigned char)zA[i];
590 for(j=aFirst[c]; j>0 && j<nB-best; j = aNext[j]){
591 int limit = minInt(nA-i, nB-j);
592 for(k=1; k<=limit && zA[k+i]==zB[k+j]; k++){}
593 if( k>best ) best = k;
594 }
595 }
596 score = (best>avg) ? 0 : (avg - best)*100/avg;
597
598

Keyboard Shortcuts

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