From d3867e2e6744fa218bcaa9b7f28335d0d984b432 Mon Sep 17 00:00:00 2001 From: The Moisrex <12122474+the-moisrex@users.noreply.github.com> Date: Wed, 10 Dec 2025 13:27:26 -1000 Subject: [PATCH] Make some ifs constexpr --- benchmarks/benchmark_template.cpp | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/benchmarks/benchmark_template.cpp b/benchmarks/benchmark_template.cpp index ba205540e..9178393ff 100644 --- a/benchmarks/benchmark_template.cpp +++ b/benchmarks/benchmark_template.cpp @@ -14,10 +14,7 @@ size_t count_ada_invalid() { return how_many; } -enum { JUST_PARSE = 1, PARSE_AND_HREF = 0 }; - -template +template static void BasicBench_AdaURL(benchmark::State& state) { // volatile to prevent optimizations. volatile size_t success = 0; @@ -96,7 +93,7 @@ static void BasicBench_AdaURL(benchmark::State& state) { #define BENCHMARK_NAME(name) CONCAT(BENCHMARK_PREFIX, name) auto BENCHMARK_NAME(BasicBench_AdaURL_href) = - BasicBench_AdaURL; + BasicBench_AdaURL; static auto* CONCAT(benchmark_register_, BENCHMARK_NAME(BasicBench_AdaURL_href)) = ::benchmark::RegisterBenchmark(BENCHMARK_PREFIX_STR @@ -104,7 +101,7 @@ static auto* CONCAT(benchmark_register_, BENCHMARK_NAME(BasicBench_AdaURL_href)); auto BENCHMARK_NAME(BasicBench_AdaURL_aggregator_href) = - BasicBench_AdaURL; + BasicBench_AdaURL; static auto* CONCAT(benchmark_register_, BENCHMARK_NAME(BasicBench_AdaURL_aggregator_href)) = ::benchmark::RegisterBenchmark( @@ -188,7 +185,7 @@ size_t count_whatwg_invalid() { return how_many; } -template +template static void BasicBench_whatwg(benchmark::State& state) { // volatile to prevent optimizations. volatile size_t success = 0; @@ -198,7 +195,7 @@ static void BasicBench_whatwg(benchmark::State& state) { upa::url url; if (upa::success(url.parse(url_string, nullptr))) { success++; - if (!just_parse) { + if constexpr (!just_parse) { href_size += url.href().size(); } } @@ -213,7 +210,7 @@ static void BasicBench_whatwg(benchmark::State& state) { upa::url url; if (upa::success(url.parse(url_string, nullptr))) { success++; - if (!just_parse) { + if constexpr (!just_parse) { href_size += url.href().size(); } } @@ -255,7 +252,7 @@ BENCHMARK(BasicBench_whatwg); // There is no need for BasicBench_whatwg_just_parse because whatwg appears to // provide the href at a minimal cost, probably because it is already // materialized. auto BasicBench_whatwg_just_parse = -// BasicBench_whatwg; BENCHMARK(BasicBench_whatwg_just_parse); +// BasicBench_whatwg; BENCHMARK(BasicBench_whatwg_just_parse); #endif // ADA_url_whatwg_ENABLED @@ -290,7 +287,7 @@ static void BasicBench_CURL(benchmark::State& state) { // Returns a CURLUcode error value, which is (0) if everything went fine. if (rc == 0) { success++; - if (!just_parse) { + if constexpr (!just_parse) { char* buffer; // When asked to return the full URL, curl_url_get will return a // normalized and possibly cleaned up version of what was previously @@ -313,7 +310,7 @@ static void BasicBench_CURL(benchmark::State& state) { CURLUcode rc = curl_url_set(url, CURLUPART_URL, url_string.c_str(), 0); // Returns a CURLUcode error value, which is (0) if everything went // fine. - if (!just_parse) { + if constexpr (!just_parse) { char* buffer; rc = curl_url_get(url, CURLUPART_URL, &buffer, 0); if (rc == 0) { @@ -357,7 +354,7 @@ static void BasicBench_CURL(benchmark::State& state) { } BENCHMARK(BasicBench_CURL); // 'just parsing' is faster with curl, but maybe not so important for us. -// auto BasicBench_CURL_just_parse = BasicBench_CURL; +// auto BasicBench_CURL_just_parse = BasicBench_CURL; // BENCHMARK(BasicBench_CURL_just_parse); #endif @@ -391,7 +388,7 @@ static void BasicBench_BoostURL(benchmark::State& state) { url u(url_string); u.normalize(); success++; - if (!just_parse) { + if constexpr (!just_parse) { href_size += u.buffer().size(); } } catch (...) { @@ -408,7 +405,7 @@ static void BasicBench_BoostURL(benchmark::State& state) { url u(url_string); u.normalize(); success++; - if (!just_parse) { + if constexpr (!just_parse) { href_size += u.buffer().size(); } } catch (...) { @@ -450,7 +447,7 @@ static void BasicBench_BoostURL(benchmark::State& state) { } BENCHMARK(BasicBench_BoostURL); // There is no need for 'just_parse' because BoostURL materializes the href. -// auto BasicBench_BoostURL_just_parse = BasicBench_BoostURL; +// auto BasicBench_BoostURL_just_parse = BasicBench_BoostURL; // BENCHMARK(BasicBench_BoostURL_just_parse); #endif // ADA_BOOST_ENABLED