Fossil SCM
Enhance the DLine.indent field so that it is always initialized to the number of space and control characters at the beginning of the line.
Commit
2dad4158dbf0d92bbbf96a9d24a684a6e416d9d7120ad09998ecbd01f04ef711
Parent
6eeb7ec10e32d90…
1 file changed
+8
-11
+8
-11
| --- src/diff.c | ||
| +++ src/diff.c | ||
| @@ -121,11 +121,11 @@ | ||
| 121 | 121 | */ |
| 122 | 122 | typedef struct DLine DLine; |
| 123 | 123 | struct DLine { |
| 124 | 124 | const char *z; /* The text of the line */ |
| 125 | 125 | u64 h; /* Hash of the line */ |
| 126 | - unsigned short indent; /* Indent of the line. Only !=0 with -w/-Z option */ | |
| 126 | + unsigned short indent; /* Index of first non-space, non-control char */ | |
| 127 | 127 | unsigned short n; /* number of bytes */ |
| 128 | 128 | unsigned int iNext; /* 1+(Index of next line with same the same hash) */ |
| 129 | 129 | |
| 130 | 130 | /* an array of DLine elements serves two purposes. The fields |
| 131 | 131 | ** above are one per line of input text. But each entry is also |
| @@ -245,17 +245,17 @@ | ||
| 245 | 245 | k = nn; |
| 246 | 246 | if( diffFlags & DIFF_STRIP_EOLCR ){ |
| 247 | 247 | if( k>0 && z[k-1]=='\r' ){ k--; } |
| 248 | 248 | } |
| 249 | 249 | a[i].n = k; |
| 250 | - s = 0; | |
| 251 | 250 | if( diffFlags & DIFF_IGNORE_EOLWS ){ |
| 252 | 251 | while( k>0 && fossil_isspace(z[k-1]) ){ k--; } |
| 253 | 252 | } |
| 253 | + for(s=0; s<k && z[s]<=' '; s++){} | |
| 254 | + a[i].indent = s; | |
| 254 | 255 | if( (diffFlags & DIFF_IGNORE_ALLWS)==DIFF_IGNORE_ALLWS ){ |
| 255 | 256 | int numws = 0; |
| 256 | - while( s<k && fossil_isspace(z[s]) ){ s++; } | |
| 257 | 257 | for(h=0, x=s; x<k; x++){ |
| 258 | 258 | char c = z[x]; |
| 259 | 259 | if( fossil_isspace(c) ){ |
| 260 | 260 | ++numws; |
| 261 | 261 | }else{ |
| @@ -264,19 +264,18 @@ | ||
| 264 | 264 | } |
| 265 | 265 | k -= numws; |
| 266 | 266 | }else{ |
| 267 | 267 | int k2 = k & ~0x7; |
| 268 | 268 | u64 m; |
| 269 | - for(h=0, x=s; x<k2; x += 8){ | |
| 269 | + for(h=x=0; x<k2; x += 8){ | |
| 270 | 270 | memcpy(&m, z+x, 8); |
| 271 | 271 | h = (h^m)*9000000000000000041LL; |
| 272 | 272 | } |
| 273 | 273 | m = 0; |
| 274 | 274 | memcpy(&m, z+x, k-k2); |
| 275 | 275 | h ^= m; |
| 276 | 276 | } |
| 277 | - a[i].indent = s; | |
| 278 | 277 | a[i].h = h = ((h%281474976710597LL)<<LENGTH_MASK_SZ) | (k-s); |
| 279 | 278 | h2 = h % nLine; |
| 280 | 279 | a[i].iNext = a[h2].iHash; |
| 281 | 280 | a[h2].iHash = i+1; |
| 282 | 281 | z += nn+1; n -= nn+1; |
| @@ -1748,17 +1747,15 @@ | ||
| 1748 | 1747 | int score; /* Final score. 0..100 */ |
| 1749 | 1748 | unsigned char c; /* Character being examined */ |
| 1750 | 1749 | unsigned char aFirst[256]; /* aFirst[X] = index in zB[] of first char X */ |
| 1751 | 1750 | unsigned char aNext[252]; /* aNext[i] = index in zB[] of next zB[i] char */ |
| 1752 | 1751 | |
| 1753 | - zA = pA->z; | |
| 1754 | - zB = pB->z; | |
| 1755 | - nA = pA->n; | |
| 1756 | - nB = pB->n; | |
| 1757 | - while( nA>0 && (unsigned char)zA[0]<=' ' ){ nA--; zA++; } | |
| 1752 | + zA = pA->z + pA->indent; | |
| 1753 | + zB = pB->z + pB->indent; | |
| 1754 | + nA = pA->n - pA->indent; | |
| 1755 | + nB = pB->n - pB->indent; | |
| 1758 | 1756 | while( nA>0 && (unsigned char)zA[nA-1]<=' ' ){ nA--; } |
| 1759 | - while( nB>0 && (unsigned char)zB[0]<=' ' ){ nB--; zB++; } | |
| 1760 | 1757 | while( nB>0 && (unsigned char)zB[nB-1]<=' ' ){ nB--; } |
| 1761 | 1758 | if( nA>250 ) nA = 250; |
| 1762 | 1759 | if( nB>250 ) nB = 250; |
| 1763 | 1760 | avg = (nA+nB)/2; |
| 1764 | 1761 | if( avg==0 ) return 0; |
| 1765 | 1762 |
| --- src/diff.c | |
| +++ src/diff.c | |
| @@ -121,11 +121,11 @@ | |
| 121 | */ |
| 122 | typedef struct DLine DLine; |
| 123 | struct DLine { |
| 124 | const char *z; /* The text of the line */ |
| 125 | u64 h; /* Hash of the line */ |
| 126 | unsigned short indent; /* Indent of the line. Only !=0 with -w/-Z option */ |
| 127 | unsigned short n; /* number of bytes */ |
| 128 | unsigned int iNext; /* 1+(Index of next line with same the same hash) */ |
| 129 | |
| 130 | /* an array of DLine elements serves two purposes. The fields |
| 131 | ** above are one per line of input text. But each entry is also |
| @@ -245,17 +245,17 @@ | |
| 245 | k = nn; |
| 246 | if( diffFlags & DIFF_STRIP_EOLCR ){ |
| 247 | if( k>0 && z[k-1]=='\r' ){ k--; } |
| 248 | } |
| 249 | a[i].n = k; |
| 250 | s = 0; |
| 251 | if( diffFlags & DIFF_IGNORE_EOLWS ){ |
| 252 | while( k>0 && fossil_isspace(z[k-1]) ){ k--; } |
| 253 | } |
| 254 | if( (diffFlags & DIFF_IGNORE_ALLWS)==DIFF_IGNORE_ALLWS ){ |
| 255 | int numws = 0; |
| 256 | while( s<k && fossil_isspace(z[s]) ){ s++; } |
| 257 | for(h=0, x=s; x<k; x++){ |
| 258 | char c = z[x]; |
| 259 | if( fossil_isspace(c) ){ |
| 260 | ++numws; |
| 261 | }else{ |
| @@ -264,19 +264,18 @@ | |
| 264 | } |
| 265 | k -= numws; |
| 266 | }else{ |
| 267 | int k2 = k & ~0x7; |
| 268 | u64 m; |
| 269 | for(h=0, x=s; x<k2; x += 8){ |
| 270 | memcpy(&m, z+x, 8); |
| 271 | h = (h^m)*9000000000000000041LL; |
| 272 | } |
| 273 | m = 0; |
| 274 | memcpy(&m, z+x, k-k2); |
| 275 | h ^= m; |
| 276 | } |
| 277 | a[i].indent = s; |
| 278 | a[i].h = h = ((h%281474976710597LL)<<LENGTH_MASK_SZ) | (k-s); |
| 279 | h2 = h % nLine; |
| 280 | a[i].iNext = a[h2].iHash; |
| 281 | a[h2].iHash = i+1; |
| 282 | z += nn+1; n -= nn+1; |
| @@ -1748,17 +1747,15 @@ | |
| 1748 | int score; /* Final score. 0..100 */ |
| 1749 | unsigned char c; /* Character being examined */ |
| 1750 | unsigned char aFirst[256]; /* aFirst[X] = index in zB[] of first char X */ |
| 1751 | unsigned char aNext[252]; /* aNext[i] = index in zB[] of next zB[i] char */ |
| 1752 | |
| 1753 | zA = pA->z; |
| 1754 | zB = pB->z; |
| 1755 | nA = pA->n; |
| 1756 | nB = pB->n; |
| 1757 | while( nA>0 && (unsigned char)zA[0]<=' ' ){ nA--; zA++; } |
| 1758 | while( nA>0 && (unsigned char)zA[nA-1]<=' ' ){ nA--; } |
| 1759 | while( nB>0 && (unsigned char)zB[0]<=' ' ){ nB--; zB++; } |
| 1760 | while( nB>0 && (unsigned char)zB[nB-1]<=' ' ){ nB--; } |
| 1761 | if( nA>250 ) nA = 250; |
| 1762 | if( nB>250 ) nB = 250; |
| 1763 | avg = (nA+nB)/2; |
| 1764 | if( avg==0 ) return 0; |
| 1765 |
| --- src/diff.c | |
| +++ src/diff.c | |
| @@ -121,11 +121,11 @@ | |
| 121 | */ |
| 122 | typedef struct DLine DLine; |
| 123 | struct DLine { |
| 124 | const char *z; /* The text of the line */ |
| 125 | u64 h; /* Hash of the line */ |
| 126 | unsigned short indent; /* Index of first non-space, non-control char */ |
| 127 | unsigned short n; /* number of bytes */ |
| 128 | unsigned int iNext; /* 1+(Index of next line with same the same hash) */ |
| 129 | |
| 130 | /* an array of DLine elements serves two purposes. The fields |
| 131 | ** above are one per line of input text. But each entry is also |
| @@ -245,17 +245,17 @@ | |
| 245 | k = nn; |
| 246 | if( diffFlags & DIFF_STRIP_EOLCR ){ |
| 247 | if( k>0 && z[k-1]=='\r' ){ k--; } |
| 248 | } |
| 249 | a[i].n = k; |
| 250 | if( diffFlags & DIFF_IGNORE_EOLWS ){ |
| 251 | while( k>0 && fossil_isspace(z[k-1]) ){ k--; } |
| 252 | } |
| 253 | for(s=0; s<k && z[s]<=' '; s++){} |
| 254 | a[i].indent = s; |
| 255 | if( (diffFlags & DIFF_IGNORE_ALLWS)==DIFF_IGNORE_ALLWS ){ |
| 256 | int numws = 0; |
| 257 | for(h=0, x=s; x<k; x++){ |
| 258 | char c = z[x]; |
| 259 | if( fossil_isspace(c) ){ |
| 260 | ++numws; |
| 261 | }else{ |
| @@ -264,19 +264,18 @@ | |
| 264 | } |
| 265 | k -= numws; |
| 266 | }else{ |
| 267 | int k2 = k & ~0x7; |
| 268 | u64 m; |
| 269 | for(h=x=0; x<k2; x += 8){ |
| 270 | memcpy(&m, z+x, 8); |
| 271 | h = (h^m)*9000000000000000041LL; |
| 272 | } |
| 273 | m = 0; |
| 274 | memcpy(&m, z+x, k-k2); |
| 275 | h ^= m; |
| 276 | } |
| 277 | a[i].h = h = ((h%281474976710597LL)<<LENGTH_MASK_SZ) | (k-s); |
| 278 | h2 = h % nLine; |
| 279 | a[i].iNext = a[h2].iHash; |
| 280 | a[h2].iHash = i+1; |
| 281 | z += nn+1; n -= nn+1; |
| @@ -1748,17 +1747,15 @@ | |
| 1747 | int score; /* Final score. 0..100 */ |
| 1748 | unsigned char c; /* Character being examined */ |
| 1749 | unsigned char aFirst[256]; /* aFirst[X] = index in zB[] of first char X */ |
| 1750 | unsigned char aNext[252]; /* aNext[i] = index in zB[] of next zB[i] char */ |
| 1751 | |
| 1752 | zA = pA->z + pA->indent; |
| 1753 | zB = pB->z + pB->indent; |
| 1754 | nA = pA->n - pA->indent; |
| 1755 | nB = pB->n - pB->indent; |
| 1756 | while( nA>0 && (unsigned char)zA[nA-1]<=' ' ){ nA--; } |
| 1757 | while( nB>0 && (unsigned char)zB[nB-1]<=' ' ){ nB--; } |
| 1758 | if( nA>250 ) nA = 250; |
| 1759 | if( nB>250 ) nB = 250; |
| 1760 | avg = (nA+nB)/2; |
| 1761 | if( avg==0 ) return 0; |
| 1762 |