[libcxx-commits] [libcxx] [libc++] Optimize std::find if types are integral (PR #70345)
via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Oct 27 02:23:08 PDT 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libcxx
Author: None (philnik777)
<details>
<summary>Changes</summary>
Fixes #<!-- -->70238
---
Full diff: https://github.com/llvm/llvm-project/pull/70345.diff
1 Files Affected:
- (modified) libcxx/include/__algorithm/find.h (+13)
``````````diff
diff --git a/libcxx/include/__algorithm/find.h b/libcxx/include/__algorithm/find.h
index d7c268bc6b338b0..019848158c174df 100644
--- a/libcxx/include/__algorithm/find.h
+++ b/libcxx/include/__algorithm/find.h
@@ -73,6 +73,19 @@ __find_impl(_Tp* __first, _Tp* __last, const _Up& __value, _Proj&) {
}
#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
+template <class _Tp,
+ class _Up,
+ class _Proj,
+ __enable_if_t<__is_identity<_Proj>::value && !__libcpp_is_trivially_equality_comparable<_Tp, _Up>::value &&
+ is_integral<_Tp>::value && is_integral<_Up>::value,
+ int> = 0>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp*
+__find_impl(_Tp* __first, _Tp* __last, const _Up& __value, _Proj& __proj) {
+ if (__value < numeric_limits<_Tp>::min() || __value > numeric_limits<_Tp>::max())
+ return __last;
+ return std::__find_impl(__first, __last, _Tp(__value), __proj);
+}
+
// __bit_iterator implementation
template <bool _ToFind, class _Cp, bool _IsConst>
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cp, _IsConst>
``````````
</details>
https://github.com/llvm/llvm-project/pull/70345
More information about the libcxx-commits
mailing list