summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2008-09-10 17:01:17 +0000
committerTom Lane2008-09-10 17:01:17 +0000
commit1340294815f358ae22d41ecd63ef8f2982293d89 (patch)
tree1f23e67a66f88cc6019255a78055f8101f62b60a
parentc0360667f783243d173827a1d94aff54dbdad7af (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.
-rw-r--r--src/interfaces/libpq/fe-exec.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/interfaces/libpq/fe-exec.c b/src/interfaces/libpq/fe-exec.c
index 37f3f9946e..dbe75e6140 100644
--- a/src/interfaces/libpq/fe-exec.c
+++ b/src/interfaces/libpq/fe-exec.c
@@ -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 == '\'')
{