diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2014-02-23 16:59:05 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2014-02-23 16:59:05 -0500 |
commit | 769065c1b2471f484bb48bb58a8bdcf1d12a419c (patch) | |
tree | dc0344a494ceabe955b403b992f4092ec4140f8b /src/pl/plperl/plperl.c | |
parent | 49c817eab78c6f0ce8c3bf46766b73d6cf3190b7 (diff) | |
download | postgresql-769065c1b2471f484bb48bb58a8bdcf1d12a419c.tar.gz postgresql-769065c1b2471f484bb48bb58a8bdcf1d12a419c.zip |
Prefer pg_any_to_server/pg_server_to_any over pg_do_encoding_conversion.
A large majority of the callers of pg_do_encoding_conversion were
specifying the database encoding as either source or target of the
conversion, meaning that we can use the less general functions
pg_any_to_server/pg_server_to_any instead.
The main advantage of using the latter functions is that they can make use
of a cached conversion-function lookup in the common case that the other
encoding is the current client_encoding. It's notationally cleaner too in
most cases, not least because of the historical artifact that the latter
functions use "char *" rather than "unsigned char *" in their APIs.
Note that pg_any_to_server will apply an encoding verification step in
some cases where pg_do_encoding_conversion would have just done nothing.
This seems to me to be a good idea at most of these call sites, though
it partially negates the performance benefit.
Per discussion of bug #9210.
Diffstat (limited to 'src/pl/plperl/plperl.c')
-rw-r--r-- | src/pl/plperl/plperl.c | 8 |
1 files changed, 2 insertions, 6 deletions
diff --git a/src/pl/plperl/plperl.c b/src/pl/plperl/plperl.c index ed6884e863a..f8ccaa59e89 100644 --- a/src/pl/plperl/plperl.c +++ b/src/pl/plperl/plperl.c @@ -3811,9 +3811,7 @@ hv_store_string(HV *hv, const char *key, SV *val) char *hkey; SV **ret; - hkey = (char *) - pg_do_encoding_conversion((unsigned char *) key, strlen(key), - GetDatabaseEncoding(), PG_UTF8); + hkey = pg_server_to_any(key, strlen(key), PG_UTF8); /* * This seems nowhere documented, but under Perl 5.8.0 and up, hv_store() @@ -3841,9 +3839,7 @@ hv_fetch_string(HV *hv, const char *key) char *hkey; SV **ret; - hkey = (char *) - pg_do_encoding_conversion((unsigned char *) key, strlen(key), - GetDatabaseEncoding(), PG_UTF8); + hkey = pg_server_to_any(key, strlen(key), PG_UTF8); /* See notes in hv_store_string */ hlen = -(int) strlen(hkey); |