[libcxx] [llvm] [libcxx] Speed up xsgetn for always_noconv (PR #212010)

via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 11 02:07:36 PDT 2026


================
@@ -199,6 +200,28 @@ typename __stdinbuf<_CharT>::int_type __stdinbuf<_CharT>::__getchar(bool __consu
   return traits_type::to_int_type(__1buf);
 }
 
+template <class _CharT>
+streamsize __stdinbuf<_CharT>::xsgetn(char_type* __s, streamsize __n) {
+  if constexpr (is_same<_CharT, char>::value) {
----------------
aokblast wrote:

I just want to use same condition with xsputn.

In that function, we have

```
__always_noconv_ && !__is_win32api_wide_char
```
where __is_win32api_wide_char is basically is_same<_CharT, char>::value. However, it is in the same expression with __always_noconv_, which is at runtime, and the compiler takes extra effort to optimize. Therefore, I switch to constexpr here. Maybe it is an over optimization. I can use the same one as xsputn. Thanks!

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


More information about the llvm-commits mailing list