Fossil SCM

Performance optimization in the building printf() logic makes the "fossil annotate" command run 6x faster.

drh 2020-02-25 11:32 trunk
Commit 1e881f59786bd89129f2b3be03903d0a0d8af7ca0aab00b332941e3126d801c6
1 file changed +2 -14
+2 -14
--- src/printf.c
+++ src/printf.c
@@ -198,22 +198,10 @@
198198
/*
199199
** Size of temporary conversion buffer.
200200
*/
201201
#define etBUFSIZE 500
202202
203
-/*
204
-** Find the length of a string as long as that length does not
205
-** exceed N bytes. If no zero terminator is seen in the first
206
-** N bytes then return N. If N is negative, then this routine
207
-** is an alias for strlen().
208
-*/
209
-static int StrNLen32(const char *z, int N){
210
- int n = 0;
211
- while( (N-- != 0) && *(z++)!=0 ){ n++; }
212
- return n;
213
-}
214
-
215203
/*
216204
** Return an appropriate set of flags for wiki_convert() for displaying
217205
** comments on a timeline. These flag settings are determined by
218206
** configuration parameters.
219207
**
@@ -652,11 +640,11 @@
652640
case etPATH: {
653641
int i;
654642
int limit = flag_alternateform ? va_arg(ap,int) : -1;
655643
char *e = va_arg(ap,char*);
656644
if( e==0 ){e="";}
657
- length = StrNLen32(e, limit);
645
+ length = (int)strnlen(e,limit);
658646
zExtra = bufpt = fossil_malloc(length+1);
659647
for( i=0; i<length; i++ ){
660648
if( e[i]=='\\' ){
661649
bufpt[i]='/';
662650
}else{
@@ -681,11 +669,11 @@
681669
}else if( xtype==etDYNSTRING ){
682670
zExtra = bufpt;
683671
}else if( xtype==etSTRINGID ){
684672
precision = hash_digits(flag_altform2);
685673
}
686
- length = StrNLen32(bufpt, limit);
674
+ length = (int)strnlen(bufpt,limit);
687675
if( precision>=0 && precision<length ) length = precision;
688676
break;
689677
}
690678
case etBLOB: {
691679
int limit = flag_alternateform ? va_arg(ap, int) : -1;
692680
--- src/printf.c
+++ src/printf.c
@@ -198,22 +198,10 @@
198 /*
199 ** Size of temporary conversion buffer.
200 */
201 #define etBUFSIZE 500
202
203 /*
204 ** Find the length of a string as long as that length does not
205 ** exceed N bytes. If no zero terminator is seen in the first
206 ** N bytes then return N. If N is negative, then this routine
207 ** is an alias for strlen().
208 */
209 static int StrNLen32(const char *z, int N){
210 int n = 0;
211 while( (N-- != 0) && *(z++)!=0 ){ n++; }
212 return n;
213 }
214
215 /*
216 ** Return an appropriate set of flags for wiki_convert() for displaying
217 ** comments on a timeline. These flag settings are determined by
218 ** configuration parameters.
219 **
@@ -652,11 +640,11 @@
652 case etPATH: {
653 int i;
654 int limit = flag_alternateform ? va_arg(ap,int) : -1;
655 char *e = va_arg(ap,char*);
656 if( e==0 ){e="";}
657 length = StrNLen32(e, limit);
658 zExtra = bufpt = fossil_malloc(length+1);
659 for( i=0; i<length; i++ ){
660 if( e[i]=='\\' ){
661 bufpt[i]='/';
662 }else{
@@ -681,11 +669,11 @@
681 }else if( xtype==etDYNSTRING ){
682 zExtra = bufpt;
683 }else if( xtype==etSTRINGID ){
684 precision = hash_digits(flag_altform2);
685 }
686 length = StrNLen32(bufpt, limit);
687 if( precision>=0 && precision<length ) length = precision;
688 break;
689 }
690 case etBLOB: {
691 int limit = flag_alternateform ? va_arg(ap, int) : -1;
692
--- src/printf.c
+++ src/printf.c
@@ -198,22 +198,10 @@
198 /*
199 ** Size of temporary conversion buffer.
200 */
201 #define etBUFSIZE 500
202
 
 
 
 
 
 
 
 
 
 
 
 
203 /*
204 ** Return an appropriate set of flags for wiki_convert() for displaying
205 ** comments on a timeline. These flag settings are determined by
206 ** configuration parameters.
207 **
@@ -652,11 +640,11 @@
640 case etPATH: {
641 int i;
642 int limit = flag_alternateform ? va_arg(ap,int) : -1;
643 char *e = va_arg(ap,char*);
644 if( e==0 ){e="";}
645 length = (int)strnlen(e,limit);
646 zExtra = bufpt = fossil_malloc(length+1);
647 for( i=0; i<length; i++ ){
648 if( e[i]=='\\' ){
649 bufpt[i]='/';
650 }else{
@@ -681,11 +669,11 @@
669 }else if( xtype==etDYNSTRING ){
670 zExtra = bufpt;
671 }else if( xtype==etSTRINGID ){
672 precision = hash_digits(flag_altform2);
673 }
674 length = (int)strnlen(bufpt,limit);
675 if( precision>=0 && precision<length ) length = precision;
676 break;
677 }
678 case etBLOB: {
679 int limit = flag_alternateform ? va_arg(ap, int) : -1;
680

Keyboard Shortcuts

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