Skip to content

Commit 6d842be

Browse files
committed
Provide fast path in snprintf.c for conversion specs that are just "%s".
This case occurs often enough (around 45% of conversion specs executed in our regression tests are just "%s") that it's worth an extra test per conversion spec to allow skipping all the logic associated with field widths and padding when it happens. Discussion: https://postgr.es/m/26193.1538582367@sss.pgh.pa.us
1 parent abd9ca3 commit 6d842be

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/port/snprintf.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,19 @@ dopr(PrintfTarget *target, const char *format, va_list args)
431431

432432
/* Process conversion spec starting at *format */
433433
format++;
434+
435+
/* Fast path for conversion spec that is exactly %s */
436+
if (*format == 's')
437+
{
438+
format++;
439+
strvalue = va_arg(args, char *);
440+
Assert(strvalue != NULL);
441+
dostr(strvalue, strlen(strvalue), target);
442+
if (target->failed)
443+
break;
444+
continue;
445+
}
446+
434447
fieldwidth = precision = zpad = leftjust = forcesign = 0;
435448
longflag = longlongflag = pointflag = 0;
436449
fmtpos = accum = 0;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy