Skip to content

Commit

Permalink
check template arguments with constexpr
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig committed Sep 18, 2024
1 parent b431670 commit 7459f65
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/unicode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion src/url-setters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/url.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();

Expand All @@ -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.
Expand All @@ -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();

Expand Down
10 changes: 5 additions & 5 deletions src/url_aggregator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ template <bool has_state_override>
*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) {
Expand All @@ -52,7 +52,7 @@ template <bool has_state_override>
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();

Expand All @@ -69,7 +69,7 @@ template <bool has_state_override>
// 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.
Expand All @@ -94,7 +94,7 @@ template <bool has_state_override>

set_scheme(_buffer);

if (has_state_override) {
if constexpr (has_state_override) {
// This is uncommon.
uint16_t urls_scheme_port = get_special_port();

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 7459f65

Please sign in to comment.