From c248cd90b69a3ec30b812cbf3aac08b0138527ab Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Wed, 18 Sep 2024 10:51:30 -0400 Subject: [PATCH] check template arguments with constexpr --- src/unicode.cpp | 2 +- src/url-setters.cpp | 2 +- src/url.cpp | 8 ++++---- src/url_aggregator.cpp | 10 +++++----- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/unicode.cpp b/src/unicode.cpp index 262db071a..c979c0250 100644 --- a/src/unicode.cpp +++ b/src/unicode.cpp @@ -428,7 +428,7 @@ bool percent_encode(const std::string_view input, const uint8_t character_set[], ada_log("percent_encode encoding not needed."); return false; } - if (!append) { + if constexpr (!append) { out.clear(); } ada_log("percent_encode appending ", std::distance(input.begin(), pointer), diff --git a/src/url-setters.cpp b/src/url-setters.cpp index a3c416620..a368ef3a3 100644 --- a/src/url-setters.cpp +++ b/src/url-setters.cpp @@ -37,7 +37,7 @@ bool url::set_host_or_hostname(const std::string_view input) { // Note: the 'found_colon' value is true if and only if a colon was // encountered while not inside brackets. if (found_colon) { - if (override_hostname) { + if constexpr (override_hostname) { return false; } std::string_view buffer = new_host.substr(location + 1); diff --git a/src/url.cpp b/src/url.cpp index c3121056b..657364381 100644 --- a/src/url.cpp +++ b/src/url.cpp @@ -336,7 +336,7 @@ ada_really_inline bool url::parse_scheme(const std::string_view input) { *http, https), in which case, we can go really fast. **/ if (is_input_special) { // fast path!!! - if (has_state_override) { + if constexpr (has_state_override) { // If url's scheme is not a special scheme and buffer is a special scheme, // then return. if (is_special() != is_input_special) { @@ -360,7 +360,7 @@ ada_really_inline bool url::parse_scheme(const std::string_view input) { type = parsed_type; - if (has_state_override) { + if constexpr (has_state_override) { // This is uncommon. uint16_t urls_scheme_port = get_special_port(); @@ -380,7 +380,7 @@ ada_really_inline bool url::parse_scheme(const std::string_view input) { // bool is_ascii = unicode::to_lower_ascii(_buffer.data(), _buffer.size()); - if (has_state_override) { + if constexpr (has_state_override) { // If url's scheme is a special scheme and buffer is not a special scheme, // then return. If url's scheme is not a special scheme and buffer is a // special scheme, then return. @@ -404,7 +404,7 @@ ada_really_inline bool url::parse_scheme(const std::string_view input) { set_scheme(std::move(_buffer)); - if (has_state_override) { + if constexpr (has_state_override) { // This is uncommon. uint16_t urls_scheme_port = get_special_port(); diff --git a/src/url_aggregator.cpp b/src/url_aggregator.cpp index dd753568c..8e4d07aa0 100644 --- a/src/url_aggregator.cpp +++ b/src/url_aggregator.cpp @@ -27,7 +27,7 @@ template *http, https), in which case, we can go really fast. **/ if (is_input_special) { // fast path!!! - if (has_state_override) { + if constexpr (has_state_override) { // If url's scheme is not a special scheme and buffer is a special scheme, // then return. if (is_special() != is_input_special) { @@ -52,7 +52,7 @@ template type = parsed_type; set_scheme_from_view_with_colon(input_with_colon); - if (has_state_override) { + if constexpr (has_state_override) { // This is uncommon. uint16_t urls_scheme_port = get_special_port(); @@ -69,7 +69,7 @@ template // need to check the return value. unicode::to_lower_ascii(_buffer.data(), _buffer.size()); - if (has_state_override) { + if constexpr (has_state_override) { // If url's scheme is a special scheme and buffer is not a special scheme, // then return. If url's scheme is not a special scheme and buffer is a // special scheme, then return. @@ -94,7 +94,7 @@ template set_scheme(_buffer); - if (has_state_override) { + if constexpr (has_state_override) { // This is uncommon. uint16_t urls_scheme_port = get_special_port(); @@ -539,7 +539,7 @@ bool url_aggregator::set_host_or_hostname(const std::string_view input) { // Note: the 'found_colon' value is true if and only if a colon was // encountered while not inside brackets. if (found_colon) { - if (override_hostname) { + if constexpr (override_hostname) { return false; } std::string_view sub_buffer = new_host.substr(location + 1);