From 769065c1b2471f484bb48bb58a8bdcf1d12a419c Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sun, 23 Feb 2014 16:59:05 -0500 Subject: 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. --- src/backend/commands/extension.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'src/backend/commands/extension.c') diff --git a/src/backend/commands/extension.c b/src/backend/commands/extension.c index ce5aed301b1..06bd90b9aa9 100644 --- a/src/backend/commands/extension.c +++ b/src/backend/commands/extension.c @@ -635,7 +635,6 @@ read_extension_script_file(const ExtensionControlFile *control, const char *filename) { int src_encoding; - int dest_encoding = GetDatabaseEncoding(); bytea *content; char *src_str; char *dest_str; @@ -645,7 +644,7 @@ read_extension_script_file(const ExtensionControlFile *control, /* use database encoding if not given */ if (control->encoding < 0) - src_encoding = dest_encoding; + src_encoding = GetDatabaseEncoding(); else src_encoding = control->encoding; @@ -655,10 +654,7 @@ read_extension_script_file(const ExtensionControlFile *control, pg_verify_mbstr_len(src_encoding, src_str, len, false); /* convert the encoding to the database encoding */ - dest_str = (char *) pg_do_encoding_conversion((unsigned char *) src_str, - len, - src_encoding, - dest_encoding); + dest_str = pg_any_to_server(src_str, len, src_encoding); /* if no conversion happened, we have to arrange for null termination */ if (dest_str == src_str) -- cgit v1.2.3