I modified the code a bit further to use an if-test to avoid a useless function call, and added/tweaked comments and docs further. Attached is a new version of the patch. I am planning to commit this, if there are no objections.
pgsql-hackers by date:
Соглашаюсь с условиями обработки персональных данных