diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2024-07-10 17:47:56 +0100 |
---|---|---|
committer | Jonathan Wakely <redi@gcc.gnu.org> | 2024-07-10 22:05:22 +0100 |
commit | 9f758953eb2cb89e306025dc232ae20da6cb860a (patch) | |
tree | 36e1da0c009fd21b23ef798b7712408bb1fc1c8e | |
parent | c5efc6eca8e3eee7038ae218cf7e2dbe9ed9d82a (diff) | |
download | gcc-9f758953eb2cb89e306025dc232ae20da6cb860a.zip gcc-9f758953eb2cb89e306025dc232ae20da6cb860a.tar.gz gcc-9f758953eb2cb89e306025dc232ae20da6cb860a.tar.bz2 |
libstdc++: Minor optimization for std::locale::encoding()
For the C locale we know the encoding is ASCII, so we can avoid using
newlocale and nl_langinfo_l. Similarly, for an unnamed locale, we aren't
going to get a useful answer, so we can just use a default-constrcuted
std::text_encoding representing an unknown encoding.
libstdc++-v3/ChangeLog:
* src/c++26/text_encoding.cc (__locale_encoding): Add to unnamed
namespace.
(std::locale::encoding): Optimize for "C" and "*" names.
-rw-r--r-- | libstdc++-v3/src/c++26/text_encoding.cc | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/libstdc++-v3/src/c++26/text_encoding.cc b/libstdc++-v3/src/c++26/text_encoding.cc index b9a50ef..efe2997 100644 --- a/libstdc++-v3/src/c++26/text_encoding.cc +++ b/libstdc++-v3/src/c++26/text_encoding.cc @@ -36,7 +36,9 @@ namespace std { _GLIBCXX_BEGIN_NAMESPACE_VERSION - +namespace +{ +// Attempt to determine the text_encoding used by the named locale. text_encoding __locale_encoding(const char* name) { @@ -54,6 +56,7 @@ __locale_encoding(const char* name) return enc; } +} // namespace _GLIBCXX_END_NAMESPACE_VERSION } // namespace std @@ -87,8 +90,15 @@ std::text_encoding::_M_is_environment() const std::text_encoding std::locale::encoding() const { - return std::__locale_encoding(name().c_str()); + string name = this->name(); + if (name.length() == 1) + { + if (name[0] == 'C') + return text_encoding(text_encoding::ASCII); + if (name[0] == '*') + return {}; + } + return __locale_encoding(name.c_str()); } #endif // CHAR_BIT == 8 - #endif // _GLIBCXX_USE_NL_LANGINFO_L |