aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/libpq/fe-exec.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2008-09-10 17:01:07 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2008-09-10 17:01:07 +0000
commitbacf7b2086d971e8b3f65eea00b5550db6fa9614 (patch)
treeae5a68256f74d2c4bc02ab411085c076c9a920c1 /src/interfaces/libpq/fe-exec.c
parent3c221c3dae5978ef3668000a3b7166e2a4f9a750 (diff)
downloadpostgresql-bacf7b2086d971e8b3f65eea00b5550db6fa9614.tar.gz
postgresql-bacf7b2086d971e8b3f65eea00b5550db6fa9614.zip
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/interfaces/libpq/fe-exec.c')
-rw-r--r--src/interfaces/libpq/fe-exec.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/interfaces/libpq/fe-exec.c b/src/interfaces/libpq/fe-exec.c
index 50b5c7bcf7c..149a0b73f6b 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.196 2008/06/23 21:10:49 momjian Exp $
+ * $PostgreSQL: pgsql/src/interfaces/libpq/fe-exec.c,v 1.197 2008/09/10 17:01:07 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -2763,10 +2763,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 == '\'')
{