Fossil SCM

Simplyfy/speed-up use of LOOK_??? flags. Rename LOOK_CR/LF to LOOK_ANY_CR/LF.

jan.nijtmans 2013-04-04 06:53 UTC trunk
Commit 468f1346594fbf427280df95c26c70d956939906
2 files changed +1 -1 +9 -15
+1 -1
--- src/checkin.c
+++ src/checkin.c
@@ -939,11 +939,11 @@
939939
if( fUnicode ){
940940
lookFlags = looks_like_utf16(p, bReverse, LOOK_NUL);
941941
}else{
942942
lookFlags = looks_like_utf8(p, LOOK_NUL);
943943
}
944
- fHasAnyCr = (lookFlags & LOOK_CR);
944
+ fHasAnyCr = (lookFlags & LOOK_ANY_CR);
945945
fBinary = (lookFlags & LOOK_BINARY);
946946
fHasLoneCrOnly = ((lookFlags & LOOK_EOL) == LOOK_LONE_CR);
947947
fHasCrLfOnly = ((lookFlags & LOOK_EOL) == LOOK_CRLF);
948948
if( fUnicode || fHasAnyCr || fBinary ){
949949
const char *zWarning;
950950
--- src/checkin.c
+++ src/checkin.c
@@ -939,11 +939,11 @@
939 if( fUnicode ){
940 lookFlags = looks_like_utf16(p, bReverse, LOOK_NUL);
941 }else{
942 lookFlags = looks_like_utf8(p, LOOK_NUL);
943 }
944 fHasAnyCr = (lookFlags & LOOK_CR);
945 fBinary = (lookFlags & LOOK_BINARY);
946 fHasLoneCrOnly = ((lookFlags & LOOK_EOL) == LOOK_LONE_CR);
947 fHasCrLfOnly = ((lookFlags & LOOK_EOL) == LOOK_CRLF);
948 if( fUnicode || fHasAnyCr || fBinary ){
949 const char *zWarning;
950
--- src/checkin.c
+++ src/checkin.c
@@ -939,11 +939,11 @@
939 if( fUnicode ){
940 lookFlags = looks_like_utf16(p, bReverse, LOOK_NUL);
941 }else{
942 lookFlags = looks_like_utf8(p, LOOK_NUL);
943 }
944 fHasAnyCr = (lookFlags & LOOK_ANY_CR);
945 fBinary = (lookFlags & LOOK_BINARY);
946 fHasLoneCrOnly = ((lookFlags & LOOK_EOL) == LOOK_LONE_CR);
947 fHasCrLfOnly = ((lookFlags & LOOK_EOL) == LOOK_CRLF);
948 if( fUnicode || fHasAnyCr || fBinary ){
949 const char *zWarning;
950
+9 -15
--- src/diff.c
+++ src/diff.c
@@ -70,21 +70,21 @@
7070
** Output flags for the looks_like_utf8() and looks_like_utf16() routines used
7171
** to convey status information about the blob content.
7272
*/
7373
#define LOOK_NONE ((int)0x00000000) /* Nothing special was found. */
7474
#define LOOK_NUL ((int)0x00000001) /* One or more NUL chars were found. */
75
-#define LOOK_CR ((int)0x00000002) /* One or more CR chars were found. */
7675
#define LOOK_LONE_CR ((int)0x00000004) /* An unpaired CR char was found. */
77
-#define LOOK_LF ((int)0x00000008) /* One or more LF chars were found. */
7876
#define LOOK_LONE_LF ((int)0x00000010) /* An unpaired LF char was found. */
7977
#define LOOK_CRLF ((int)0x00000020) /* One or more CR/LF pairs were found. */
8078
#define LOOK_LONG ((int)0x00000040) /* An over length line was found. */
8179
#define LOOK_ODD ((int)0x00000080) /* An odd number of bytes was found. */
8280
#define LOOK_SHORT ((int)0x00000100) /* Unable to perform full check. */
8381
#define LOOK_INVALID ((int)0x00000200) /* Invalid sequence was found. */
8482
#define LOOK_BINARY (LOOK_NUL | LOOK_LONG | LOOK_SHORT) /* May be binary. */
85
-#define LOOK_EOL (LOOK_LONE_CR | LOOK_LONE_LF | LOOK_CRLF) /* Line seps. */
83
+#define LOOK_ANY_CR (LOOK_LONE_CR | LOOK_CRLF) /* One or more CR chars were found. */
84
+#define LOOK_ANY_LF (LOOK_LONE_LF | LOOK_CRLF) /* One or more LF chars were found. */
85
+#define LOOK_EOL (LOOK_ANY_CR | LOOK_LONE_LF) /* Line seps. */
8686
#endif /* INTERFACE */
8787
8888
/*
8989
** Maximum length of a line in a text file, in bytes. (2**13 = 8192 bytes)
9090
*/
@@ -246,35 +246,32 @@
246246
if( n==0 ) return flags; /* Empty file -> text */
247247
c = *z;
248248
if( c==0 ){
249249
flags |= LOOK_NUL; /* NUL character in a file -> binary */
250250
}else if( c=='\r' ){
251
- flags |= LOOK_CR;
252251
if( n<=1 || z[1]!='\n' ){
253252
flags |= LOOK_LONE_CR; /* More chars, next char is not LF */
254253
}
255254
}
256255
j = (c!='\n');
257
- if( !j ) flags |= (LOOK_LF | LOOK_LONE_LF); /* Found LF as first char */
256
+ if( !j ) flags |= LOOK_LONE_LF; /* Found LF as first char */
258257
while( !(flags&stopFlags) && --n>0 ){
259258
int c2 = c;
260259
c = *++z; ++j;
261260
if( c==0 ){
262261
flags |= LOOK_NUL; /* NUL character in a file -> binary */
263262
}else if( c=='\n' ){
264
- flags |= LOOK_LF;
265263
if( c2=='\r' ){
266
- flags |= (LOOK_CR | LOOK_CRLF); /* Found LF preceded by CR */
264
+ flags |= LOOK_CRLF; /* Found LF preceded by CR */
267265
}else{
268266
flags |= LOOK_LONE_LF;
269267
}
270268
if( j>LENGTH_MASK ){
271269
flags |= LOOK_LONG; /* Very long line -> binary */
272270
}
273271
j = 0;
274272
}else if( c=='\r' ){
275
- flags |= LOOK_CR;
276273
if( n<=1 || z[1]!='\n' ){
277274
flags |= LOOK_LONE_CR; /* More chars, next char is not LF */
278275
}
279276
}
280277
}
@@ -360,17 +357,16 @@
360357
c = UTF16_SWAP(c);
361358
}
362359
if( c==0 ){
363360
flags |= LOOK_NUL; /* NUL character in a file -> binary */
364361
}else if( c=='\r' ){
365
- flags |= LOOK_CR;
366362
if( n<=sizeof(WCHAR_T) || UTF16_SWAP_IF(bReverse, z[1])!='\n' ){
367363
flags |= LOOK_LONE_CR; /* More chars, next char is not LF */
368364
}
369365
}
370366
j = (c!='\n');
371
- if( !j ) flags |= (LOOK_LF | LOOK_LONE_LF); /* Found LF as first char */
367
+ if( !j ) flags |= LOOK_LONE_LF; /* Found LF as first char */
372368
while( 1 ){
373369
int c2 = c;
374370
n -= sizeof(WCHAR_T);
375371
if( (flags&stopFlags) || n<sizeof(WCHAR_T) ) break;
376372
c = *++z;
@@ -379,22 +375,20 @@
379375
}
380376
++j;
381377
if( c==0 ){
382378
flags |= LOOK_NUL; /* NUL character in a file -> binary */
383379
}else if( c=='\n' ){
384
- flags |= LOOK_LF;
385380
if( c2=='\r' ){
386
- flags |= (LOOK_CR | LOOK_CRLF); /* Found LF preceded by CR */
381
+ flags |= LOOK_CRLF; /* Found LF preceded by CR */
387382
}else{
388383
flags |= LOOK_LONE_LF;
389384
}
390385
if( j>UTF16_LENGTH_MASK ){
391386
flags |= LOOK_LONG; /* Very long line -> binary */
392387
}
393388
j = 0;
394389
}else if( c=='\r' ){
395
- flags |= LOOK_CR;
396390
if( n<=sizeof(WCHAR_T) || UTF16_SWAP_IF(bReverse, z[1])!='\n' ){
397391
flags |= LOOK_LONE_CR; /* More chars, next char is not LF */
398392
}
399393
}
400394
}
@@ -2557,14 +2551,14 @@
25572551
fossil_print("Starts with UTF-16 BOM: %s\n",
25582552
fUtf16?(bRevUtf16?"reversed":"yes"):"no");
25592553
fossil_print("Looks like UTF-%s: %s\n",fUnicode?"16":"8",
25602554
(lookFlags&LOOK_BINARY)?"no":"yes");
25612555
fossil_print("Has flag LOOK_NUL: %s\n",(lookFlags&LOOK_NUL)?"yes":"no");
2562
- fossil_print("Has flag LOOK_CR: %s\n",(lookFlags&LOOK_CR)?"yes":"no");
2556
+ fossil_print("Has flag LOOK_CR: %s\n",(lookFlags&LOOK_ANY_CR)?"yes":"no");
25632557
fossil_print("Has flag LOOK_LONE_CR: %s\n",
25642558
(lookFlags&LOOK_LONE_CR)?"yes":"no");
2565
- fossil_print("Has flag LOOK_LF: %s\n",(lookFlags&LOOK_LF)?"yes":"no");
2559
+ fossil_print("Has flag LOOK_LF: %s\n",(lookFlags&LOOK_ANY_LF)?"yes":"no");
25662560
fossil_print("Has flag LOOK_LONE_LF: %s\n",
25672561
(lookFlags&LOOK_LONE_LF)?"yes":"no");
25682562
fossil_print("Has flag LOOK_CRLF: %s\n",(lookFlags&LOOK_CRLF)?"yes":"no");
25692563
fossil_print("Has flag LOOK_LONG: %s\n",(lookFlags&LOOK_LONG)?"yes":"no");
25702564
fossil_print("Has flag LOOK_INVALID: %s\n",
25712565
--- src/diff.c
+++ src/diff.c
@@ -70,21 +70,21 @@
70 ** Output flags for the looks_like_utf8() and looks_like_utf16() routines used
71 ** to convey status information about the blob content.
72 */
73 #define LOOK_NONE ((int)0x00000000) /* Nothing special was found. */
74 #define LOOK_NUL ((int)0x00000001) /* One or more NUL chars were found. */
75 #define LOOK_CR ((int)0x00000002) /* One or more CR chars were found. */
76 #define LOOK_LONE_CR ((int)0x00000004) /* An unpaired CR char was found. */
77 #define LOOK_LF ((int)0x00000008) /* One or more LF chars were found. */
78 #define LOOK_LONE_LF ((int)0x00000010) /* An unpaired LF char was found. */
79 #define LOOK_CRLF ((int)0x00000020) /* One or more CR/LF pairs were found. */
80 #define LOOK_LONG ((int)0x00000040) /* An over length line was found. */
81 #define LOOK_ODD ((int)0x00000080) /* An odd number of bytes was found. */
82 #define LOOK_SHORT ((int)0x00000100) /* Unable to perform full check. */
83 #define LOOK_INVALID ((int)0x00000200) /* Invalid sequence was found. */
84 #define LOOK_BINARY (LOOK_NUL | LOOK_LONG | LOOK_SHORT) /* May be binary. */
85 #define LOOK_EOL (LOOK_LONE_CR | LOOK_LONE_LF | LOOK_CRLF) /* Line seps. */
 
 
86 #endif /* INTERFACE */
87
88 /*
89 ** Maximum length of a line in a text file, in bytes. (2**13 = 8192 bytes)
90 */
@@ -246,35 +246,32 @@
246 if( n==0 ) return flags; /* Empty file -> text */
247 c = *z;
248 if( c==0 ){
249 flags |= LOOK_NUL; /* NUL character in a file -> binary */
250 }else if( c=='\r' ){
251 flags |= LOOK_CR;
252 if( n<=1 || z[1]!='\n' ){
253 flags |= LOOK_LONE_CR; /* More chars, next char is not LF */
254 }
255 }
256 j = (c!='\n');
257 if( !j ) flags |= (LOOK_LF | LOOK_LONE_LF); /* Found LF as first char */
258 while( !(flags&stopFlags) && --n>0 ){
259 int c2 = c;
260 c = *++z; ++j;
261 if( c==0 ){
262 flags |= LOOK_NUL; /* NUL character in a file -> binary */
263 }else if( c=='\n' ){
264 flags |= LOOK_LF;
265 if( c2=='\r' ){
266 flags |= (LOOK_CR | LOOK_CRLF); /* Found LF preceded by CR */
267 }else{
268 flags |= LOOK_LONE_LF;
269 }
270 if( j>LENGTH_MASK ){
271 flags |= LOOK_LONG; /* Very long line -> binary */
272 }
273 j = 0;
274 }else if( c=='\r' ){
275 flags |= LOOK_CR;
276 if( n<=1 || z[1]!='\n' ){
277 flags |= LOOK_LONE_CR; /* More chars, next char is not LF */
278 }
279 }
280 }
@@ -360,17 +357,16 @@
360 c = UTF16_SWAP(c);
361 }
362 if( c==0 ){
363 flags |= LOOK_NUL; /* NUL character in a file -> binary */
364 }else if( c=='\r' ){
365 flags |= LOOK_CR;
366 if( n<=sizeof(WCHAR_T) || UTF16_SWAP_IF(bReverse, z[1])!='\n' ){
367 flags |= LOOK_LONE_CR; /* More chars, next char is not LF */
368 }
369 }
370 j = (c!='\n');
371 if( !j ) flags |= (LOOK_LF | LOOK_LONE_LF); /* Found LF as first char */
372 while( 1 ){
373 int c2 = c;
374 n -= sizeof(WCHAR_T);
375 if( (flags&stopFlags) || n<sizeof(WCHAR_T) ) break;
376 c = *++z;
@@ -379,22 +375,20 @@
379 }
380 ++j;
381 if( c==0 ){
382 flags |= LOOK_NUL; /* NUL character in a file -> binary */
383 }else if( c=='\n' ){
384 flags |= LOOK_LF;
385 if( c2=='\r' ){
386 flags |= (LOOK_CR | LOOK_CRLF); /* Found LF preceded by CR */
387 }else{
388 flags |= LOOK_LONE_LF;
389 }
390 if( j>UTF16_LENGTH_MASK ){
391 flags |= LOOK_LONG; /* Very long line -> binary */
392 }
393 j = 0;
394 }else if( c=='\r' ){
395 flags |= LOOK_CR;
396 if( n<=sizeof(WCHAR_T) || UTF16_SWAP_IF(bReverse, z[1])!='\n' ){
397 flags |= LOOK_LONE_CR; /* More chars, next char is not LF */
398 }
399 }
400 }
@@ -2557,14 +2551,14 @@
2557 fossil_print("Starts with UTF-16 BOM: %s\n",
2558 fUtf16?(bRevUtf16?"reversed":"yes"):"no");
2559 fossil_print("Looks like UTF-%s: %s\n",fUnicode?"16":"8",
2560 (lookFlags&LOOK_BINARY)?"no":"yes");
2561 fossil_print("Has flag LOOK_NUL: %s\n",(lookFlags&LOOK_NUL)?"yes":"no");
2562 fossil_print("Has flag LOOK_CR: %s\n",(lookFlags&LOOK_CR)?"yes":"no");
2563 fossil_print("Has flag LOOK_LONE_CR: %s\n",
2564 (lookFlags&LOOK_LONE_CR)?"yes":"no");
2565 fossil_print("Has flag LOOK_LF: %s\n",(lookFlags&LOOK_LF)?"yes":"no");
2566 fossil_print("Has flag LOOK_LONE_LF: %s\n",
2567 (lookFlags&LOOK_LONE_LF)?"yes":"no");
2568 fossil_print("Has flag LOOK_CRLF: %s\n",(lookFlags&LOOK_CRLF)?"yes":"no");
2569 fossil_print("Has flag LOOK_LONG: %s\n",(lookFlags&LOOK_LONG)?"yes":"no");
2570 fossil_print("Has flag LOOK_INVALID: %s\n",
2571
--- src/diff.c
+++ src/diff.c
@@ -70,21 +70,21 @@
70 ** Output flags for the looks_like_utf8() and looks_like_utf16() routines used
71 ** to convey status information about the blob content.
72 */
73 #define LOOK_NONE ((int)0x00000000) /* Nothing special was found. */
74 #define LOOK_NUL ((int)0x00000001) /* One or more NUL chars were found. */
 
75 #define LOOK_LONE_CR ((int)0x00000004) /* An unpaired CR char was found. */
 
76 #define LOOK_LONE_LF ((int)0x00000010) /* An unpaired LF char was found. */
77 #define LOOK_CRLF ((int)0x00000020) /* One or more CR/LF pairs were found. */
78 #define LOOK_LONG ((int)0x00000040) /* An over length line was found. */
79 #define LOOK_ODD ((int)0x00000080) /* An odd number of bytes was found. */
80 #define LOOK_SHORT ((int)0x00000100) /* Unable to perform full check. */
81 #define LOOK_INVALID ((int)0x00000200) /* Invalid sequence was found. */
82 #define LOOK_BINARY (LOOK_NUL | LOOK_LONG | LOOK_SHORT) /* May be binary. */
83 #define LOOK_ANY_CR (LOOK_LONE_CR | LOOK_CRLF) /* One or more CR chars were found. */
84 #define LOOK_ANY_LF (LOOK_LONE_LF | LOOK_CRLF) /* One or more LF chars were found. */
85 #define LOOK_EOL (LOOK_ANY_CR | LOOK_LONE_LF) /* Line seps. */
86 #endif /* INTERFACE */
87
88 /*
89 ** Maximum length of a line in a text file, in bytes. (2**13 = 8192 bytes)
90 */
@@ -246,35 +246,32 @@
246 if( n==0 ) return flags; /* Empty file -> text */
247 c = *z;
248 if( c==0 ){
249 flags |= LOOK_NUL; /* NUL character in a file -> binary */
250 }else if( c=='\r' ){
 
251 if( n<=1 || z[1]!='\n' ){
252 flags |= LOOK_LONE_CR; /* More chars, next char is not LF */
253 }
254 }
255 j = (c!='\n');
256 if( !j ) flags |= LOOK_LONE_LF; /* Found LF as first char */
257 while( !(flags&stopFlags) && --n>0 ){
258 int c2 = c;
259 c = *++z; ++j;
260 if( c==0 ){
261 flags |= LOOK_NUL; /* NUL character in a file -> binary */
262 }else if( c=='\n' ){
 
263 if( c2=='\r' ){
264 flags |= LOOK_CRLF; /* Found LF preceded by CR */
265 }else{
266 flags |= LOOK_LONE_LF;
267 }
268 if( j>LENGTH_MASK ){
269 flags |= LOOK_LONG; /* Very long line -> binary */
270 }
271 j = 0;
272 }else if( c=='\r' ){
 
273 if( n<=1 || z[1]!='\n' ){
274 flags |= LOOK_LONE_CR; /* More chars, next char is not LF */
275 }
276 }
277 }
@@ -360,17 +357,16 @@
357 c = UTF16_SWAP(c);
358 }
359 if( c==0 ){
360 flags |= LOOK_NUL; /* NUL character in a file -> binary */
361 }else if( c=='\r' ){
 
362 if( n<=sizeof(WCHAR_T) || UTF16_SWAP_IF(bReverse, z[1])!='\n' ){
363 flags |= LOOK_LONE_CR; /* More chars, next char is not LF */
364 }
365 }
366 j = (c!='\n');
367 if( !j ) flags |= LOOK_LONE_LF; /* Found LF as first char */
368 while( 1 ){
369 int c2 = c;
370 n -= sizeof(WCHAR_T);
371 if( (flags&stopFlags) || n<sizeof(WCHAR_T) ) break;
372 c = *++z;
@@ -379,22 +375,20 @@
375 }
376 ++j;
377 if( c==0 ){
378 flags |= LOOK_NUL; /* NUL character in a file -> binary */
379 }else if( c=='\n' ){
 
380 if( c2=='\r' ){
381 flags |= LOOK_CRLF; /* Found LF preceded by CR */
382 }else{
383 flags |= LOOK_LONE_LF;
384 }
385 if( j>UTF16_LENGTH_MASK ){
386 flags |= LOOK_LONG; /* Very long line -> binary */
387 }
388 j = 0;
389 }else if( c=='\r' ){
 
390 if( n<=sizeof(WCHAR_T) || UTF16_SWAP_IF(bReverse, z[1])!='\n' ){
391 flags |= LOOK_LONE_CR; /* More chars, next char is not LF */
392 }
393 }
394 }
@@ -2557,14 +2551,14 @@
2551 fossil_print("Starts with UTF-16 BOM: %s\n",
2552 fUtf16?(bRevUtf16?"reversed":"yes"):"no");
2553 fossil_print("Looks like UTF-%s: %s\n",fUnicode?"16":"8",
2554 (lookFlags&LOOK_BINARY)?"no":"yes");
2555 fossil_print("Has flag LOOK_NUL: %s\n",(lookFlags&LOOK_NUL)?"yes":"no");
2556 fossil_print("Has flag LOOK_CR: %s\n",(lookFlags&LOOK_ANY_CR)?"yes":"no");
2557 fossil_print("Has flag LOOK_LONE_CR: %s\n",
2558 (lookFlags&LOOK_LONE_CR)?"yes":"no");
2559 fossil_print("Has flag LOOK_LF: %s\n",(lookFlags&LOOK_ANY_LF)?"yes":"no");
2560 fossil_print("Has flag LOOK_LONE_LF: %s\n",
2561 (lookFlags&LOOK_LONE_LF)?"yes":"no");
2562 fossil_print("Has flag LOOK_CRLF: %s\n",(lookFlags&LOOK_CRLF)?"yes":"no");
2563 fossil_print("Has flag LOOK_LONG: %s\n",(lookFlags&LOOK_LONG)?"yes":"no");
2564 fossil_print("Has flag LOOK_INVALID: %s\n",
2565

Keyboard Shortcuts

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