aboutsummaryrefslogtreecommitdiff
path: root/libcxx/src
diff options
context:
space:
mode:
authorNikolas Klauser <nikolasklauser@berlin.de>2025-06-11 20:39:45 +0200
committerGitHub <noreply@github.com>2025-06-11 20:39:45 +0200
commit773d357b9882fe0e30ffddee5ac1fbe2254fac05 (patch)
treeefb0315bed752e8429774ba243ad286c01926850 /libcxx/src
parent8d7da9a2a40302af25ee70841a4b549f4ed5ee8a (diff)
downloadllvm-773d357b9882fe0e30ffddee5ac1fbe2254fac05.zip
llvm-773d357b9882fe0e30ffddee5ac1fbe2254fac05.tar.gz
llvm-773d357b9882fe0e30ffddee5ac1fbe2254fac05.tar.bz2
[libc++] Simplify the implementation of __next_prime a bit (#143512)
Diffstat (limited to 'libcxx/src')
-rw-r--r--libcxx/src/hash.cpp20
1 files changed, 9 insertions, 11 deletions
diff --git a/libcxx/src/hash.cpp b/libcxx/src/hash.cpp
index 41c4eb4..50d8cf9 100644
--- a/libcxx/src/hash.cpp
+++ b/libcxx/src/hash.cpp
@@ -9,7 +9,6 @@
#include <__hash_table>
#include <algorithm>
#include <stdexcept>
-#include <type_traits>
_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wtautological-constant-out-of-range-compare")
@@ -52,16 +51,15 @@ const unsigned indices[] = {
// are fewer potential primes to search, and fewer potential primes to divide
// against.
-template <size_t _Sz = sizeof(size_t)>
-inline _LIBCPP_HIDE_FROM_ABI typename enable_if<_Sz == 4, void>::type __check_for_overflow(size_t N) {
- if (N > 0xFFFFFFFB)
- std::__throw_overflow_error("__next_prime overflow");
-}
-
-template <size_t _Sz = sizeof(size_t)>
-inline _LIBCPP_HIDE_FROM_ABI typename enable_if<_Sz == 8, void>::type __check_for_overflow(size_t N) {
- if (N > 0xFFFFFFFFFFFFFFC5ull)
- std::__throw_overflow_error("__next_prime overflow");
+inline void __check_for_overflow(size_t N) {
+ if constexpr (sizeof(size_t) == 4) {
+ if (N > 0xFFFFFFFB)
+ std::__throw_overflow_error("__next_prime overflow");
+ } else {
+ static_assert(sizeof(size_t) == 8);
+ if (N > 0xFFFFFFFFFFFFFFC5ull)
+ std::__throw_overflow_error("__next_prime overflow");
+ }
}
size_t __next_prime(size_t n) {