[libcxx-commits] [libcxx] 6b5eef6 - [libc++] Disable the wmemchr optimization in std::find on Apple platforms (#217655)
via libcxx-commits
libcxx-commits at lists.llvm.org
Sat Aug 22 01:37:06 PDT 2026
Author: Nikolas Klauser
Date: 2026-08-22T10:37:01+02:00
New Revision: 6b5eef65d1b4568e902dd04f294076c275cc4991
URL: https://github.com/llvm/llvm-project/commit/6b5eef65d1b4568e902dd04f294076c275cc4991
DIFF: https://github.com/llvm/llvm-project/commit/6b5eef65d1b4568e902dd04f294076c275cc4991.diff
LOG: [libc++] Disable the wmemchr optimization in std::find on Apple platforms (#217655)
`wmemchr` on Apple platforms is incredibly slow. We can do significantly
better by just implementing it on our own.
Fixes #205840
Added:
Modified:
libcxx/include/__algorithm/find.h
libcxx/include/module.modulemap.in
Removed:
################################################################################
diff --git a/libcxx/include/__algorithm/find.h b/libcxx/include/__algorithm/find.h
index f677fb2c7392d..be45c8bfa966c 100644
--- a/libcxx/include/__algorithm/find.h
+++ b/libcxx/include/__algorithm/find.h
@@ -126,7 +126,9 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp* __find(_Tp* __first, _T
return __ret;
return __last;
}
-# if _LIBCPP_HAS_WIDE_CHARACTERS
+ // wmemchr is very slow on apple platforms - we can do significantly better on our own.
+ // TODO: Remove this special-case once Apple's wmemchr is fixed.
+# if _LIBCPP_HAS_WIDE_CHARACTERS && !defined(__APPLE__)
else if constexpr (sizeof(_Tp) == sizeof(wchar_t) && _LIBCPP_ALIGNOF(_Tp) >= _LIBCPP_ALIGNOF(wchar_t)) {
if (auto __ret = std::__constexpr_wmemchr(__first, __value, __last - __first))
return __ret;
diff --git a/libcxx/include/module.modulemap.in b/libcxx/include/module.modulemap.in
index c6d38d5dfaea5..78f4e08d9c282 100644
--- a/libcxx/include/module.modulemap.in
+++ b/libcxx/include/module.modulemap.in
@@ -413,7 +413,10 @@ module std {
module find_if_not { header "__algorithm/find_if_not.h" }
module find_if { header "__algorithm/find_if.h" }
module find_segment_if { header "__algorithm/find_segment_if.h" }
- module find { header "__algorithm/find.h" }
+ module find {
+ header "__algorithm/find.h"
+ export std.algorithm.simd_utils // TODO: Workaround for https://llvm.org/PR120108
+ }
module for_each_n { header "__algorithm/for_each_n.h" }
module for_each_n_segment { header "__algorithm/for_each_n_segment.h" }
module for_each_segment { header "__algorithm/for_each_segment.h" }
@@ -1705,7 +1708,7 @@ module std {
module noexcept_move_assign_container { header "__memory/noexcept_move_assign_container.h" }
module out_ptr { header "__memory/out_ptr.h" }
module pointer_traits { header "__memory/pointer_traits.h" }
- module pstl { header "__memory/pstl.h" }
+ module pstl { header "__memory/pstl.h" }
module ranges_construct_at { header "__memory/ranges_construct_at.h" }
module ranges_destroy { header "__memory/ranges_destroy.h" }
module ranges_uninitialized_algorithms {
More information about the libcxx-commits
mailing list