Fossil SCM

Use the strcspn() C-library routine to optimize the textLength() function in the Fossil-wiki formatter.

drh 2019-09-24 19:52 trunk
Commit 64a63468892a7ebb095adb5617d5163db8c59ec7d0ba91bcd498cb6d1ed7e65d
1 file changed +5 -13
+5 -13
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -527,27 +527,19 @@
527527
**
528528
** The "[" is only considered if flags contain ALLOW_LINKS or ALLOW_WIKI.
529529
** The "\n" is only considered interesting if the flags constains ALLOW_WIKI.
530530
*/
531531
static int textLength(const char *z, int flags){
532
- int n = 0;
533
- int c, x1, x2;
534
-
532
+ const char *zReject;
535533
if( flags & ALLOW_WIKI ){
536
- x1 = '[';
537
- x2 = '\n';
534
+ zReject = "<&[\n";
538535
}else if( flags & ALLOW_LINKS ){
539
- x1 = '[';
540
- x2 = 0;
536
+ zReject = "<&[";
541537
}else{
542
- x1 = x2 = 0;
538
+ zReject = "<&";
543539
}
544
- while( (c = z[0])!=0 && c!='<' && c!='&' && c!=x1 && c!=x2 ){
545
- n++;
546
- z++;
547
- }
548
- return n;
540
+ return strcspn(z, zReject);
549541
}
550542
551543
/*
552544
** Return true if z[] begins with an HTML character element.
553545
*/
554546
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -527,27 +527,19 @@
527 **
528 ** The "[" is only considered if flags contain ALLOW_LINKS or ALLOW_WIKI.
529 ** The "\n" is only considered interesting if the flags constains ALLOW_WIKI.
530 */
531 static int textLength(const char *z, int flags){
532 int n = 0;
533 int c, x1, x2;
534
535 if( flags & ALLOW_WIKI ){
536 x1 = '[';
537 x2 = '\n';
538 }else if( flags & ALLOW_LINKS ){
539 x1 = '[';
540 x2 = 0;
541 }else{
542 x1 = x2 = 0;
543 }
544 while( (c = z[0])!=0 && c!='<' && c!='&' && c!=x1 && c!=x2 ){
545 n++;
546 z++;
547 }
548 return n;
549 }
550
551 /*
552 ** Return true if z[] begins with an HTML character element.
553 */
554
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -527,27 +527,19 @@
527 **
528 ** The "[" is only considered if flags contain ALLOW_LINKS or ALLOW_WIKI.
529 ** The "\n" is only considered interesting if the flags constains ALLOW_WIKI.
530 */
531 static int textLength(const char *z, int flags){
532 const char *zReject;
 
 
533 if( flags & ALLOW_WIKI ){
534 zReject = "<&[\n";
 
535 }else if( flags & ALLOW_LINKS ){
536 zReject = "<&[";
 
537 }else{
538 zReject = "<&";
539 }
540 return strcspn(z, zReject);
 
 
 
 
541 }
542
543 /*
544 ** Return true if z[] begins with an HTML character element.
545 */
546

Keyboard Shortcuts

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