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.

drh 2022-01-22 13:49 trunk
Commit 2dad4158dbf0d92bbbf96a9d24a684a6e416d9d7120ad09998ecbd01f04ef711
1 file changed +8 -11
+8 -11
--- src/diff.c
+++ src/diff.c
@@ -121,11 +121,11 @@
121121
*/
122122
typedef struct DLine DLine;
123123
struct DLine {
124124
const char *z; /* The text of the line */
125125
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 */
127127
unsigned short n; /* number of bytes */
128128
unsigned int iNext; /* 1+(Index of next line with same the same hash) */
129129
130130
/* an array of DLine elements serves two purposes. The fields
131131
** above are one per line of input text. But each entry is also
@@ -245,17 +245,17 @@
245245
k = nn;
246246
if( diffFlags & DIFF_STRIP_EOLCR ){
247247
if( k>0 && z[k-1]=='\r' ){ k--; }
248248
}
249249
a[i].n = k;
250
- s = 0;
251250
if( diffFlags & DIFF_IGNORE_EOLWS ){
252251
while( k>0 && fossil_isspace(z[k-1]) ){ k--; }
253252
}
253
+ for(s=0; s<k && z[s]<=' '; s++){}
254
+ a[i].indent = s;
254255
if( (diffFlags & DIFF_IGNORE_ALLWS)==DIFF_IGNORE_ALLWS ){
255256
int numws = 0;
256
- while( s<k && fossil_isspace(z[s]) ){ s++; }
257257
for(h=0, x=s; x<k; x++){
258258
char c = z[x];
259259
if( fossil_isspace(c) ){
260260
++numws;
261261
}else{
@@ -264,19 +264,18 @@
264264
}
265265
k -= numws;
266266
}else{
267267
int k2 = k & ~0x7;
268268
u64 m;
269
- for(h=0, x=s; x<k2; x += 8){
269
+ for(h=x=0; x<k2; x += 8){
270270
memcpy(&m, z+x, 8);
271271
h = (h^m)*9000000000000000041LL;
272272
}
273273
m = 0;
274274
memcpy(&m, z+x, k-k2);
275275
h ^= m;
276276
}
277
- a[i].indent = s;
278277
a[i].h = h = ((h%281474976710597LL)<<LENGTH_MASK_SZ) | (k-s);
279278
h2 = h % nLine;
280279
a[i].iNext = a[h2].iHash;
281280
a[h2].iHash = i+1;
282281
z += nn+1; n -= nn+1;
@@ -1748,17 +1747,15 @@
17481747
int score; /* Final score. 0..100 */
17491748
unsigned char c; /* Character being examined */
17501749
unsigned char aFirst[256]; /* aFirst[X] = index in zB[] of first char X */
17511750
unsigned char aNext[252]; /* aNext[i] = index in zB[] of next zB[i] char */
17521751
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;
17581756
while( nA>0 && (unsigned char)zA[nA-1]<=' ' ){ nA--; }
1759
- while( nB>0 && (unsigned char)zB[0]<=' ' ){ nB--; zB++; }
17601757
while( nB>0 && (unsigned char)zB[nB-1]<=' ' ){ nB--; }
17611758
if( nA>250 ) nA = 250;
17621759
if( nB>250 ) nB = 250;
17631760
avg = (nA+nB)/2;
17641761
if( avg==0 ) return 0;
17651762
--- 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

Keyboard Shortcuts

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