1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-11 10:01:57 +03:00

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
This commit is contained in:
Tom Lane
2018-10-03 13:05:01 -04:00
parent abd9ca377d
commit 6d842be6c1

View File

@ -431,6 +431,19 @@ dopr(PrintfTarget *target, const char *format, va_list args)
/* Process conversion spec starting at *format */ /* Process conversion spec starting at *format */
format++; format++;
/* Fast path for conversion spec that is exactly %s */
if (*format == 's')
{
format++;
strvalue = va_arg(args, char *);
Assert(strvalue != NULL);
dostr(strvalue, strlen(strvalue), target);
if (target->failed)
break;
continue;
}
fieldwidth = precision = zpad = leftjust = forcesign = 0; fieldwidth = precision = zpad = leftjust = forcesign = 0;
longflag = longlongflag = pointflag = 0; longflag = longlongflag = pointflag = 0;
fmtpos = accum = 0; fmtpos = accum = 0;