String and bytea encoding optimization

Expand use of the hash table to control all aspects of string and bytea quoting and escaping.
Optimize the hash function to make as few decisions as possible on current PG version.