Skip to content

Commit 79d1342

Browse files
committed
more c++20 changes
1 parent c0ed932 commit 79d1342

18 files changed

+108
-118
lines changed

include/ada/helpers.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
#include <string_view>
1313
#include <optional>
1414

15+
#if ADA_DEVELOPMENT_CHECKS
16+
#include <iostream>
17+
#endif // ADA_DEVELOPMENT_CHECKS
18+
1519
/**
1620
* These functions are not part of our public API and may
1721
* change at any time.
@@ -128,7 +132,7 @@ ada_really_inline void resize(std::string_view& input, size_t pos) noexcept;
128132
* and whether a colon was found outside brackets. Used by the host parser.
129133
*/
130134
ada_really_inline std::pair<size_t, bool> get_host_delimiter_location(
131-
const bool is_special, std::string_view& view) noexcept;
135+
bool is_special, std::string_view& view) noexcept;
132136

133137
/**
134138
* @private

include/ada/log.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@
77
#define ADA_LOG_H
88
#include "ada/common_defs.h"
99

10-
#include <iostream>
1110
// To enable logging, set ADA_LOGGING to 1:
1211
#ifndef ADA_LOGGING
1312
#define ADA_LOGGING 0
1413
#endif
1514

15+
#if ADA_LOGGING
16+
#include <iostream>
17+
#endif // ADA_LOGGING
18+
1619
namespace ada {
1720

1821
/**

include/ada/scheme-inl.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ ada_really_inline constexpr bool is_special(std::string_view scheme) {
5050
if (scheme.empty()) {
5151
return false;
5252
}
53-
int hash_value = (2 * scheme.size() + (unsigned)(scheme[0])) & 7;
53+
int hash_value = (2 * scheme.size() + static_cast<unsigned>(scheme[0])) & 7;
5454
const std::string_view target = details::is_special_list[hash_value];
5555
return (target[0] == scheme[0]) && (target.substr(1) == scheme.substr(1));
5656
}
5757
constexpr uint16_t get_special_port(std::string_view scheme) noexcept {
5858
if (scheme.empty()) {
5959
return 0;
6060
}
61-
int hash_value = (2 * scheme.size() + (unsigned)(scheme[0])) & 7;
61+
int hash_value = (2 * scheme.size() + static_cast<unsigned>(scheme[0])) & 7;
6262
const std::string_view target = details::is_special_list[hash_value];
6363
if ((target[0] == scheme[0]) && (target.substr(1) == scheme.substr(1))) {
6464
return details::special_ports[hash_value];
@@ -67,13 +67,13 @@ constexpr uint16_t get_special_port(std::string_view scheme) noexcept {
6767
}
6868
}
6969
constexpr uint16_t get_special_port(ada::scheme::type type) noexcept {
70-
return details::special_ports[int(type)];
70+
return details::special_ports[static_cast<int>(type)];
7171
}
7272
constexpr ada::scheme::type get_scheme_type(std::string_view scheme) noexcept {
7373
if (scheme.empty()) {
7474
return ada::scheme::NOT_SPECIAL;
7575
}
76-
int hash_value = (2 * scheme.size() + (unsigned)(scheme[0])) & 7;
76+
int hash_value = (2 * scheme.size() + static_cast<unsigned>(scheme[0])) & 7;
7777
const std::string_view target = details::is_special_list[hash_value];
7878
if ((target[0] == scheme[0]) && (target.substr(1) == scheme.substr(1))) {
7979
return ada::scheme::type(hash_value);

include/ada/scheme.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include "ada/common_defs.h"
99

1010
#include <array>
11-
#include <optional>
1211
#include <string>
1312

1413
/**

include/ada/serializers.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include "ada/common_defs.h"
99

1010
#include <array>
11-
#include <optional>
1211
#include <string>
1312

1413
/**

include/ada/unicode-inl.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ namespace ada::unicode {
1919
ada_really_inline size_t percent_encode_index(const std::string_view input,
2020
const uint8_t character_set[]) {
2121
return std::distance(
22-
input.begin(),
23-
std::find_if(input.begin(), input.end(), [character_set](const char c) {
22+
input.begin(), std::ranges::find_if(input, [character_set](const char c) {
2423
return character_sets::bit_at(character_set, c);
2524
}));
2625
}

include/ada/url-inl.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ inline void url::update_base_search(std::string_view input,
133133
}
134134

135135
inline void url::update_base_search(std::optional<std::string> input) {
136-
query = input;
136+
query = std::move(input);
137137
}
138138

139139
inline void url::update_base_pathname(const std::string_view input) {
@@ -232,7 +232,7 @@ ada_really_inline size_t url::parse_port(std::string_view view,
232232
return 0;
233233
}
234234
ada_log("parse_port: ", parsed_port);
235-
const size_t consumed = size_t(r.ptr - view.data());
235+
const auto consumed = size_t(r.ptr - view.data());
236236
ada_log("parse_port: consumed ", consumed);
237237
if (check_trailing_content) {
238238
is_valid &=
@@ -245,9 +245,8 @@ ada_really_inline size_t url::parse_port(std::string_view view,
245245
auto default_port = scheme_default_port();
246246
bool is_port_valid = (default_port == 0 && parsed_port == 0) ||
247247
(default_port != parsed_port);
248-
port = (r.ec == std::errc() && is_port_valid)
249-
? std::optional<uint16_t>(parsed_port)
250-
: std::nullopt;
248+
port = (r.ec == std::errc() && is_port_valid) ? std::optional(parsed_port)
249+
: std::nullopt;
251250
}
252251
return consumed;
253252
}

include/ada/url_aggregator-inl.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ inline void url_aggregator::update_unencoded_base_hash(std::string_view input) {
106106
ada_really_inline uint32_t url_aggregator::replace_and_resize(
107107
uint32_t start, uint32_t end, std::string_view input) {
108108
uint32_t current_length = end - start;
109-
uint32_t input_size = uint32_t(input.size());
109+
auto input_size = static_cast<uint32_t>(input.size());
110110
uint32_t new_difference = input_size - current_length;
111111

112112
if (current_length == 0) {
@@ -155,7 +155,7 @@ inline void url_aggregator::update_base_hostname(const std::string_view input) {
155155
[[nodiscard]] ada_really_inline uint32_t
156156
url_aggregator::get_pathname_length() const noexcept {
157157
ada_log("url_aggregator::get_pathname_length");
158-
uint32_t ending_index = uint32_t(buffer.size());
158+
auto ending_index = static_cast<uint32_t>(buffer.size());
159159
if (components.search_start != url_components::omitted) {
160160
ending_index = components.search_start;
161161
} else if (components.hash_start != url_components::omitted) {
@@ -307,7 +307,7 @@ inline void url_aggregator::append_base_pathname(const std::string_view input) {
307307
std::string path_expected(get_pathname());
308308
path_expected.append(input);
309309
#endif // ADA_DEVELOPMENT_CHECKS
310-
uint32_t ending_index = uint32_t(buffer.size());
310+
auto ending_index = static_cast<uint32_t>(buffer.size());
311311
if (components.search_start != url_components::omitted) {
312312
ending_index = components.search_start;
313313
} else if (components.hash_start != url_components::omitted) {
@@ -384,7 +384,7 @@ inline void url_aggregator::append_base_username(const std::string_view input) {
384384
return;
385385
}
386386

387-
uint32_t difference = uint32_t(input.size());
387+
auto difference = static_cast<uint32_t>(input.size());
388388
buffer.insert(components.username_end, input);
389389
components.username_end += difference;
390390
components.host_start += difference;
@@ -452,7 +452,7 @@ inline void url_aggregator::update_base_password(const std::string_view input) {
452452
}
453453

454454
bool password_exists = has_password();
455-
uint32_t difference = uint32_t(input.size());
455+
auto difference = static_cast<uint32_t>(input.size());
456456

457457
if (password_exists) {
458458
uint32_t current_length =
@@ -503,7 +503,7 @@ inline void url_aggregator::append_base_password(const std::string_view input) {
503503
return;
504504
}
505505

506-
uint32_t difference = uint32_t(input.size());
506+
auto difference = static_cast<uint32_t>(input.size());
507507
if (has_password()) {
508508
buffer.insert(components.host_start, input);
509509
} else {
@@ -548,7 +548,7 @@ inline void url_aggregator::update_base_port(uint32_t input) {
548548
// calling std::to_string(input.value()) is unfortunate given that the port
549549
// value is probably already available as a string.
550550
std::string value = helpers::concat(":", std::to_string(input));
551-
uint32_t difference = uint32_t(value.size());
551+
auto difference = static_cast<uint32_t>(value.size());
552552

553553
if (components.port != url_components::omitted) {
554554
difference -= components.pathname_start - components.host_end;
@@ -637,7 +637,7 @@ inline void url_aggregator::clear_hash() {
637637
constexpr void url_aggregator::clear_pathname() {
638638
ada_log("url_aggregator::clear_pathname");
639639
ADA_ASSERT_TRUE(validate());
640-
uint32_t ending_index = uint32_t(buffer.size());
640+
auto ending_index = static_cast<uint32_t>(buffer.size());
641641
if (components.search_start != url_components::omitted) {
642642
ending_index = components.search_start;
643643
} else if (components.hash_start != url_components::omitted) {
@@ -867,7 +867,7 @@ ada_really_inline size_t url_aggregator::parse_port(
867867
return 0;
868868
}
869869
ada_log("parse_port: ", parsed_port);
870-
const size_t consumed = size_t(r.ptr - view.data());
870+
const auto consumed = static_cast<size_t>(r.ptr - view.data());
871871
ada_log("parse_port: consumed ", consumed);
872872
if (check_trailing_content) {
873873
is_valid &=

include/ada/url_search_params-inl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ inline url_search_params_entries_iter url_search_params::get_entries() {
193193
}
194194

195195
template <typename T, url_search_params_iter_type Type>
196-
inline bool url_search_params_iter<T, Type>::has_next() {
196+
inline bool url_search_params_iter<T, Type>::has_next() const {
197197
return pos < params.params.size();
198198
}
199199

include/ada/url_search_params.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ struct url_search_params {
4242
* @see
4343
* https://github.com/web-platform-tests/wpt/blob/master/url/urlsearchparams-constructor.any.js
4444
*/
45-
url_search_params(const std::string_view input) { initialize(input); }
45+
explicit url_search_params(const std::string_view input) {
46+
initialize(input);
47+
}
4648

4749
url_search_params(const url_search_params &u) = default;
4850
url_search_params(url_search_params &&u) noexcept = default;
@@ -172,7 +174,7 @@ struct url_search_params_iter {
172174
*/
173175
inline std::optional<T> next();
174176

175-
inline bool has_next();
177+
inline bool has_next() const;
176178

177179
private:
178180
static url_search_params EMPTY;

0 commit comments

Comments
 (0)