From 1227f60798b05a04412af867d2f13ed20ead9243 Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Fri, 17 May 2024 00:08:01 -0400 Subject: [PATCH] refactor: cleanup clang-tidy warnings (#672) --- src/helpers.cpp | 6 ++---- src/parser.cpp | 1 - src/unicode.cpp | 11 ++--------- src/url-getters.cpp | 1 - src/url-setters.cpp | 1 - src/url.cpp | 2 +- src/url_aggregator.cpp | 10 ++++------ src/url_components.cpp | 1 - 8 files changed, 9 insertions(+), 24 deletions(-) diff --git a/src/helpers.cpp b/src/helpers.cpp index e1491bd08..d64673d7b 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -1,8 +1,6 @@ #include "ada.h" #include "ada/checkers-inl.h" -#include "ada/checkers.h" #include "ada/common_defs.h" // make sure ADA_IS_BIG_ENDIAN gets defined. -#include "ada/unicode.h" #include "ada/scheme.h" #include @@ -748,7 +746,7 @@ ada_really_inline void strip_trailing_spaces_from_opaque_path( static constexpr std::array authority_delimiter_special = []() constexpr { std::array result{}; - for (int i : {'@', '/', '\\', '?'}) { + for (uint8_t i : {'@', '/', '\\', '?'}) { result[i] = 1; } return result; @@ -769,7 +767,7 @@ find_authority_delimiter_special(std::string_view view) noexcept { // @ / ? static constexpr std::array authority_delimiter = []() constexpr { std::array result{}; - for (int i : {'@', '/', '?'}) { + for (uint8_t i : {'@', '/', '?'}) { result[i] = 1; } return result; diff --git a/src/parser.cpp b/src/parser.cpp index 680ce35e4..a3a6b3586 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -6,7 +6,6 @@ #include "ada/log.h" #include "ada/parser.h" -#include #include namespace ada::parser { diff --git a/src/unicode.cpp b/src/unicode.cpp index 3f3a84c21..975588bb7 100644 --- a/src/unicode.cpp +++ b/src/unicode.cpp @@ -260,15 +260,8 @@ contains_forbidden_domain_code_point_or_upper(const char* input, constexpr static std::array is_alnum_plus_table = []() constexpr { std::array result{}; for (size_t c = 0; c < 256; c++) { - if (c >= '0' && c <= '9') { - result[c] = true; - } else if (c >= 'a' && c <= 'z') { - result[c] = true; - } else if (c >= 'A' && c <= 'Z') { - result[c] = true; - } else if (c == '+' || c == '-' || c == '.') { - result[c] = true; - } + result[c] = (c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || + (c >= 'A' && c <= 'Z') || c == '+' || c == '-' || c == '.'; } return result; }(); diff --git a/src/url-getters.cpp b/src/url-getters.cpp index d965dc931..227863a71 100644 --- a/src/url-getters.cpp +++ b/src/url-getters.cpp @@ -7,7 +7,6 @@ #include "ada/helpers.h" #include "ada/scheme.h" -#include #include namespace ada { diff --git a/src/url-setters.cpp b/src/url-setters.cpp index 99ca19022..a3c416620 100644 --- a/src/url-setters.cpp +++ b/src/url-setters.cpp @@ -160,7 +160,6 @@ void url::set_hash(const std::string_view input) { helpers::remove_ascii_tab_or_newline(new_value); hash = unicode::percent_encode(new_value, ada::character_sets::FRAGMENT_PERCENT_ENCODE); - return; } void url::set_search(const std::string_view input) { diff --git a/src/url.cpp b/src/url.cpp index c03ba766f..777432705 100644 --- a/src/url.cpp +++ b/src/url.cpp @@ -43,7 +43,7 @@ bool url::parse_ipv4(std::string_view input) { segment_result = 0; input.remove_prefix(2); } else { - std::from_chars_result r; + std::from_chars_result r{}; if (is_hex) { r = std::from_chars(input.data() + 2, input.data() + input.size(), segment_result, 16); diff --git a/src/url_aggregator.cpp b/src/url_aggregator.cpp index 2fb1cf5d5..c6472a2c7 100644 --- a/src/url_aggregator.cpp +++ b/src/url_aggregator.cpp @@ -1,6 +1,5 @@ #include "ada.h" #include "ada/checkers-inl.h" -#include "ada/checkers.h" #include "ada/helpers.h" #include "ada/implementation.h" #include "ada/scheme.h" @@ -8,7 +7,6 @@ #include "ada/url_components.h" #include "ada/url_aggregator.h" #include "ada/url_aggregator-inl.h" -#include "ada/parser.h" #include #include @@ -701,7 +699,7 @@ bool url_aggregator::set_hostname(const std::string_view input) { // if we have an empty host, then the space between components.host_end and // components.pathname_start may be occupied by /. if (start == components.host_end) { - return std::string_view(); + return {}; } return helpers::substring(buffer, start, components.pathname_start); } @@ -725,7 +723,7 @@ bool url_aggregator::set_hostname(const std::string_view input) { components.pathname_start, " buffer.size() = ", buffer.size(), " components.search_start = ", components.search_start, " components.hash_start = ", components.hash_start); - uint32_t ending_index = uint32_t(buffer.size()); + auto ending_index = uint32_t(buffer.size()); if (components.search_start != url_components::omitted) { ending_index = components.search_start; } else if (components.hash_start != url_components::omitted) { @@ -741,7 +739,7 @@ bool url_aggregator::set_hostname(const std::string_view input) { if (components.search_start == url_components::omitted) { return ""; } - uint32_t ending_index = uint32_t(buffer.size()); + auto ending_index = uint32_t(buffer.size()); if (components.hash_start != url_components::omitted) { ending_index = components.hash_start; } @@ -879,7 +877,7 @@ bool url_aggregator::parse_ipv4(std::string_view input, bool in_place) { segment_result = 0; input.remove_prefix(2); } else { - std::from_chars_result r; + std::from_chars_result r{}; if (is_hex) { ada_log("parse_ipv4 trying to parse hex number"); r = std::from_chars(input.data() + 2, input.data() + input.size(), diff --git a/src/url_components.cpp b/src/url_components.cpp index 3870b9b44..7324caeb9 100644 --- a/src/url_components.cpp +++ b/src/url_components.cpp @@ -77,7 +77,6 @@ namespace ada { if (hash_start < index) { return false; } - index = hash_start; } return true;