Fossil SCM

Approximately a 5x performance increase for diff with the -w (ignore whitespace) option.

drh 2022-01-23 00:31 diff-improvement
Commit fbdbc09b402b19de63889436358041870aa6efe2a9bca7dd16db345ed8e1538c
1 file changed +4 -2
+4 -2
--- src/diff.c
+++ src/diff.c
@@ -323,14 +323,16 @@
323323
/*
324324
** Return zero if two DLine elements are identical, ignoring
325325
** all whitespace. The indent field of pA/pB already points
326326
** to the first non-space character in the string.
327327
*/
328
-
329328
static int compare_dline_ignore_allws(const DLine *pA, const DLine *pB){
330
- int a = pA->indent, b = pB->indent;
331329
if( pA->h==pB->h ){
330
+ int a, b;
331
+ if( memcmp(pA->z, pB->z, pA->h&LENGTH_MASK)==0 ) return 0;
332
+ a = pA->indent;
333
+ b = pB->indent;
332334
while( a<pA->n || b<pB->n ){
333335
if( a<pA->n && b<pB->n && pA->z[a++] != pB->z[b++] ) return 1;
334336
while( a<pA->n && diff_isspace(pA->z[a])) ++a;
335337
while( b<pB->n && diff_isspace(pB->z[b])) ++b;
336338
}
337339
--- src/diff.c
+++ src/diff.c
@@ -323,14 +323,16 @@
323 /*
324 ** Return zero if two DLine elements are identical, ignoring
325 ** all whitespace. The indent field of pA/pB already points
326 ** to the first non-space character in the string.
327 */
328
329 static int compare_dline_ignore_allws(const DLine *pA, const DLine *pB){
330 int a = pA->indent, b = pB->indent;
331 if( pA->h==pB->h ){
 
 
 
 
332 while( a<pA->n || b<pB->n ){
333 if( a<pA->n && b<pB->n && pA->z[a++] != pB->z[b++] ) return 1;
334 while( a<pA->n && diff_isspace(pA->z[a])) ++a;
335 while( b<pB->n && diff_isspace(pB->z[b])) ++b;
336 }
337
--- src/diff.c
+++ src/diff.c
@@ -323,14 +323,16 @@
323 /*
324 ** Return zero if two DLine elements are identical, ignoring
325 ** all whitespace. The indent field of pA/pB already points
326 ** to the first non-space character in the string.
327 */
 
328 static int compare_dline_ignore_allws(const DLine *pA, const DLine *pB){
 
329 if( pA->h==pB->h ){
330 int a, b;
331 if( memcmp(pA->z, pB->z, pA->h&LENGTH_MASK)==0 ) return 0;
332 a = pA->indent;
333 b = pB->indent;
334 while( a<pA->n || b<pB->n ){
335 if( a<pA->n && b<pB->n && pA->z[a++] != pB->z[b++] ) return 1;
336 while( a<pA->n && diff_isspace(pA->z[a])) ++a;
337 while( b<pB->n && diff_isspace(pB->z[b])) ++b;
338 }
339

Keyboard Shortcuts

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