perf: first_100_primes moved to the static storage

This commit is contained in:
Mateusz Pusz
2024-11-16 09:11:52 +01:00
parent 4f8e959b5c
commit 2c24c61da5

View File

@@ -38,6 +38,7 @@ import std;
#include <numeric>
#include <optional>
#include <tuple>
#include <version>
#endif
#endif
@@ -441,9 +442,20 @@ constexpr auto get_first_of(const Rng& rng, UnaryFunction f)
return get_first_of(begin(rng), end(rng), f);
}
#if __cpp_constexpr < 202211L
template<std::size_t N>
struct first_n_primes_impl {
static constexpr auto value = first_n_primes<N>();
};
#endif
[[nodiscard]] consteval std::uintmax_t find_first_factor(std::uintmax_t n)
{
constexpr auto first_100_primes = first_n_primes<100>();
#if __cpp_constexpr >= 202211L
static constexpr auto first_100_primes = first_n_primes<100>();
#else
constexpr auto first_100_primes = first_n_primes_impl<100>::value;
#endif
for (const auto& p : first_100_primes) {
if (n % p == 0u) {