Speed up byteain by not parsing traditional-style input twice.

Instead of laboriously computing the exact output length, use strlen
to get an upper bound cheaply.  (This is still O(N) of course, but
the constant factor is a lot less.)  This will typically result in
overallocating the output datum, but that's of little concern since
it's a short-lived allocation in just about all use-cases.

A simple microbenchmark showed about 40% speedup for long input
strings.

While here, make some cosmetic cleanups and add a test case that
covers the double-backslash code path in byteain and byteaout.

Author: Steven Niu <[email protected]>
Reviewed-by: Kirill Reshke <[email protected]>
Reviewed-by: Stepan Neretin <[email protected]>
Reviewed-by: Tom Lane <[email protected]>
Discussion: https://postgr.es/m/[email protected]

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/3683af617044d271ab7486d43d06f9689ed4961d

Modified Files
--------------
src/backend/utils/adt/bytea.c         | 61 +++++++++--------------------------
src/test/regress/expected/strings.out | 12 +++++++
src/test/regress/sql/strings.sql      |  2 ++
3 files changed, 30 insertions(+), 45 deletions(-)

Reply via email to