diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2008-09-10 17:01:17 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2008-09-10 17:01:17 +0000 |
commit | 8208fbb4ce26e08287f2b8ac68e530959880d88e (patch) | |
tree | 3bd490d2984d340641d8af3bd41aa7e5adb6a897 /src | |
parent | 6c5cf22edd519cefefa335f46199005b45f404d7 (diff) |
Avoid using sprintf() for a simple octal conversion in PQescapeByteaInternal.
Improves performance, per suggestion from Rudolf Leitgeb (bug #4414).
The backend did this right already, but not libpq.
Diffstat (limited to 'src')
-rw-r--r-- | src/interfaces/libpq/fe-exec.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/interfaces/libpq/fe-exec.c b/src/interfaces/libpq/fe-exec.c index e7941dffe02..2f02d91db9e 100644 --- a/src/interfaces/libpq/fe-exec.c +++ b/src/interfaces/libpq/fe-exec.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/interfaces/libpq/fe-exec.c,v 1.194 2008/01/01 19:46:00 momjian Exp $ + * $PostgreSQL: pgsql/src/interfaces/libpq/fe-exec.c,v 1.194.2.1 2008/09/10 17:01:17 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -2760,10 +2760,14 @@ PQescapeByteaInternal(PGconn *conn, { if (*vp < 0x20 || *vp > 0x7e) { + int val = *vp; + if (!std_strings) *rp++ = '\\'; - (void) sprintf((char *) rp, "\\%03o", *vp); - rp += 4; + *rp++ = '\\'; + *rp++ = (val >> 6) + '0'; + *rp++ = ((val >> 3) & 07) + '0'; + *rp++ = (val & 07) + '0'; } else if (*vp == '\'') { |