aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrh <>2025-02-25 12:18:27 +0000
committerdrh <>2025-02-25 12:18:27 +0000
commitd4c686ed8fd4f69c26a1ee0c7d65ded6b5fa17c7 (patch)
tree799484dfc5746471bc9fdf76f141269c6620f3d4 /src
parenta357a90f12e927ec169168cd89e54dc4fa905717 (diff)
downloadsqlite-d4c686ed8fd4f69c26a1ee0c7d65ded6b5fa17c7.tar.gz
sqlite-d4c686ed8fd4f69c26a1ee0c7d65ded6b5fa17c7.zip
Small performance improvement for the new %#Q conversion in printf.
FossilOrigin-Name: 17e440781e68d7d3ea68c5144e1e08e183f0caef595a6c7ac4ce56489c60f476
Diffstat (limited to 'src')
-rw-r--r--src/printf.c30
1 files changed, 17 insertions, 13 deletions
diff --git a/src/printf.c b/src/printf.c
index 30c4ec605..ae9e9010b 100644
--- a/src/printf.c
+++ b/src/printf.c
@@ -757,7 +757,7 @@ void sqlite3_str_vappendf(
case etESCAPE_Q: /* %Q: Escape ' and enclose in '...' */
case etESCAPE_w: { /* %w: Escape " characters */
i64 i, j, k, n;
- int isnull, needQuote = 0;
+ int needQuote = 0;
char ch;
char *escarg;
char q;
@@ -767,18 +767,17 @@ void sqlite3_str_vappendf(
}else{
escarg = va_arg(ap,char*);
}
- isnull = escarg==0;
+ if( escarg==0 ){
+ escarg = (xtype==etESCAPE_Q ? "NULL" : "(NULL)");
+ }else if( xtype==etESCAPE_Q ){
+ needQuote = 1;
+ }
if( xtype==etESCAPE_w ){
q = '"';
flag_alternateform = 0;
}else{
q = '\'';
}
- if( isnull ){
- escarg = (xtype==etESCAPE_Q ? "NULL" : "(NULL)");
- }else if( xtype==etESCAPE_Q ){
- needQuote = 1;
- }
/* For %q, %Q, and %w, the precision is the number of bytes (or
** characters if the ! flags is present) to use from the input.
** Because of the extra quoting characters inserted, the number
@@ -832,12 +831,12 @@ void sqlite3_str_vappendf(
}
}
k = i;
- for(i=0; i<k; i++){
- bufpt[j++] = ch = escarg[i];
- if( ch==q ){
- bufpt[j++] = ch;
- }else if( flag_alternateform ){
- if( ch=='\\' ){
+ if( flag_alternateform ){
+ for(i=0; i<k; i++){
+ bufpt[j++] = ch = escarg[i];
+ if( ch==q ){
+ bufpt[j++] = ch;
+ }else if( ch=='\\' ){
bufpt[j++] = '\\';
}else if( ch<=0x1f ){
bufpt[j-1] = '\\';
@@ -848,6 +847,11 @@ void sqlite3_str_vappendf(
bufpt[j++] = "0123456789abcdef"[ch&0xf];
}
}
+ }else{
+ for(i=0; i<k; i++){
+ bufpt[j++] = ch = escarg[i];
+ if( ch==q ) bufpt[j++] = ch;
+ }
}
if( needQuote ){
bufpt[j++] = '\'';