From 5cdbcbbcbfcbba04e45b0213433b0fd7c1614e6f Mon Sep 17 00:00:00 2001 From: Nikolas Klauser Date: Tue, 10 Jun 2025 13:59:15 +0200 Subject: [PATCH] [libc++] Simplify the implementation of __next_prime a bit --- libcxx/src/hash.cpp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/libcxx/src/hash.cpp b/libcxx/src/hash.cpp index 41c4eb480a5fc..50d8cf9f9f539 100644 --- a/libcxx/src/hash.cpp +++ b/libcxx/src/hash.cpp @@ -9,7 +9,6 @@ #include <__hash_table> #include #include -#include _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 -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 -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) {