[libcxx-commits] [libcxx] [libc++] Optimize ctype::to{lower, upper} (PR #145344)

Zibi Sarbinowski via libcxx-commits libcxx-commits at lists.llvm.org
Fri Aug 15 09:17:31 PDT 2025


================
@@ -697,6 +697,20 @@ const ctype_base::mask ctype_base::graph;
 
 // template <> class ctype<wchar_t>;
 
+template <class CharT>
+static CharT to_upper_impl(CharT c) {
+  if (c < 'a' || c > 'z')
+    return c;
+  return c & ~0x20;
+}
+
+template <class CharT>
+static CharT to_lower_impl(CharT c) {
+  if (c < 'A' || c > 'Z')
+    return c;
+  return c | 0x20;
+}
+
----------------
zibi2 wrote:

This code does not work for non-ASCII encodings since the assumption of char ordering cannot be assumed. Is there any reason why we cannot simply call C functions `::tolower(c)` and `touppoer(c)` here?

https://github.com/llvm/llvm-project/pull/145344


More information about the libcxx-commits mailing list