Fossil SCM

Further performance improvements to the internal printf() implementation.

drh 2020-11-21 14:34 trunk
Commit 3ad620df0058144d39fd950d819f2dc10cab1185a04ce3965833ab6f5cc19af2
1 file changed +8 -6
+8 -6
--- src/printf.c
+++ src/printf.c
@@ -174,10 +174,11 @@
174174
{ 'n', 0, 0, etSIZE, 0, 0 },
175175
{ '%', 0, 0, etPERCENT, 0, 0 },
176176
{ 'p', 16, 0, etPOINTER, 0, 1 },
177177
{ '/', 0, 0, etPATH, 0, 0 },
178178
{ '$', 0, 0, etSHELLESC, 0, 0 },
179
+ { etERROR, 0,0,0,0,0} /* Must be last */
179180
};
180181
#define etNINFO count(fmtinfo)
181182
182183
/*
183184
** Verify that the fmtchr[] and fmtinfo[] arrays are in agreement.
@@ -329,17 +330,18 @@
329330
330331
count = length = 0;
331332
bufpt = 0;
332333
for(; (c=(*fmt))!=0; ++fmt){
333334
if( c!='%' ){
334
- int amt;
335335
bufpt = (char *)fmt;
336
- amt = 1;
337
- while( (c=(*++fmt))!='%' && c!=0 ) amt++;
338
- blob_append(pBlob,bufpt,amt);
339
- count += amt;
340
- if( c==0 ) break;
336
+#if HAVE_STRCHRNUL
337
+ fmt = strchrnul(fmt, '%');
338
+#else
339
+ do{ fmt++; }while( *fmt && *fmt != '%' );
340
+#endif
341
+ blob_append(pBlob, bufpt, (int)(fmt - bufpt));
342
+ if( *fmt==0 ) break;
341343
}
342344
if( (c=(*++fmt))==0 ){
343345
errorflag = 1;
344346
blob_append(pBlob,"%",1);
345347
count++;
346348
--- src/printf.c
+++ src/printf.c
@@ -174,10 +174,11 @@
174 { 'n', 0, 0, etSIZE, 0, 0 },
175 { '%', 0, 0, etPERCENT, 0, 0 },
176 { 'p', 16, 0, etPOINTER, 0, 1 },
177 { '/', 0, 0, etPATH, 0, 0 },
178 { '$', 0, 0, etSHELLESC, 0, 0 },
 
179 };
180 #define etNINFO count(fmtinfo)
181
182 /*
183 ** Verify that the fmtchr[] and fmtinfo[] arrays are in agreement.
@@ -329,17 +330,18 @@
329
330 count = length = 0;
331 bufpt = 0;
332 for(; (c=(*fmt))!=0; ++fmt){
333 if( c!='%' ){
334 int amt;
335 bufpt = (char *)fmt;
336 amt = 1;
337 while( (c=(*++fmt))!='%' && c!=0 ) amt++;
338 blob_append(pBlob,bufpt,amt);
339 count += amt;
340 if( c==0 ) break;
 
 
341 }
342 if( (c=(*++fmt))==0 ){
343 errorflag = 1;
344 blob_append(pBlob,"%",1);
345 count++;
346
--- src/printf.c
+++ src/printf.c
@@ -174,10 +174,11 @@
174 { 'n', 0, 0, etSIZE, 0, 0 },
175 { '%', 0, 0, etPERCENT, 0, 0 },
176 { 'p', 16, 0, etPOINTER, 0, 1 },
177 { '/', 0, 0, etPATH, 0, 0 },
178 { '$', 0, 0, etSHELLESC, 0, 0 },
179 { etERROR, 0,0,0,0,0} /* Must be last */
180 };
181 #define etNINFO count(fmtinfo)
182
183 /*
184 ** Verify that the fmtchr[] and fmtinfo[] arrays are in agreement.
@@ -329,17 +330,18 @@
330
331 count = length = 0;
332 bufpt = 0;
333 for(; (c=(*fmt))!=0; ++fmt){
334 if( c!='%' ){
 
335 bufpt = (char *)fmt;
336 #if HAVE_STRCHRNUL
337 fmt = strchrnul(fmt, '%');
338 #else
339 do{ fmt++; }while( *fmt && *fmt != '%' );
340 #endif
341 blob_append(pBlob, bufpt, (int)(fmt - bufpt));
342 if( *fmt==0 ) break;
343 }
344 if( (c=(*++fmt))==0 ){
345 errorflag = 1;
346 blob_append(pBlob,"%",1);
347 count++;
348

Keyboard Shortcuts

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