Teach convert() and friends to avoid copying when possible.
authorNathan Bossart <nathan@postgresql.org>
Mon, 4 Dec 2023 17:55:18 +0000 (11:55 -0600)
committerNathan Bossart <nathan@postgresql.org>
Mon, 4 Dec 2023 17:55:18 +0000 (11:55 -0600)
commitb14b1eb4da4c97afec24cf8956e842b98ebb2a51
tree621b51a60c7c4863686a42cf97b67718ea22ca46
parente7c6efe305afff030b50fe6f792af48deff5cf3e
Teach convert() and friends to avoid copying when possible.

Presently, pg_convert() allocates a new bytea and copies the result
regardless of whether any conversion actually happened.  This
commit adjusts this function to return the source pointer as-is if
no conversion occurred.  This optimization isn't expected to make a
tremendous difference, but it still seems worthwhile to avoid
unnecessary memory allocations.

Author: Yurii Rashkovskii
Reviewed-by: Bertrand Drouvot
Discussion: https://postgr.es/m/CA%2BRLCQyknBPSWXRBQGOi6aYEcdQ9RpH9Kch4GjoeY8dQ3D%2Bvhw%40mail.gmail.com
src/backend/utils/mb/mbutils.c