Fossil SCM
Use the strcspn() C-library routine to optimize the textLength() function in the Fossil-wiki formatter.
Commit
64a63468892a7ebb095adb5617d5163db8c59ec7d0ba91bcd498cb6d1ed7e65d
Parent
cd5e9f265de1a0d…
1 file changed
+5
-13
+5
-13
| --- src/wikiformat.c | ||
| +++ src/wikiformat.c | ||
| @@ -527,27 +527,19 @@ | ||
| 527 | 527 | ** |
| 528 | 528 | ** The "[" is only considered if flags contain ALLOW_LINKS or ALLOW_WIKI. |
| 529 | 529 | ** The "\n" is only considered interesting if the flags constains ALLOW_WIKI. |
| 530 | 530 | */ |
| 531 | 531 | static int textLength(const char *z, int flags){ |
| 532 | - int n = 0; | |
| 533 | - int c, x1, x2; | |
| 534 | - | |
| 532 | + const char *zReject; | |
| 535 | 533 | if( flags & ALLOW_WIKI ){ |
| 536 | - x1 = '['; | |
| 537 | - x2 = '\n'; | |
| 534 | + zReject = "<&[\n"; | |
| 538 | 535 | }else if( flags & ALLOW_LINKS ){ |
| 539 | - x1 = '['; | |
| 540 | - x2 = 0; | |
| 536 | + zReject = "<&["; | |
| 541 | 537 | }else{ |
| 542 | - x1 = x2 = 0; | |
| 538 | + zReject = "<&"; | |
| 543 | 539 | } |
| 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); | |
| 549 | 541 | } |
| 550 | 542 | |
| 551 | 543 | /* |
| 552 | 544 | ** Return true if z[] begins with an HTML character element. |
| 553 | 545 | */ |
| 554 | 546 |
| --- 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 |