The patch is pretty straightforward, I just have one remark:
+ /* if no actual conversion happened, return the original string */ + /* (we are checking pointers to strings instead of encodings because + `pg_do_encoding_conversion` above covers more cases than just + encoding equality) */
I think this could be done in one single comment and follow the preferred style for multi-line comment, see [1].
Thank you for your feedback. I've attached a revised patch.