Skip to content

Commit f11d6f2

Browse files
committed
convert more functions to constexpr
1 parent b431670 commit f11d6f2

File tree

6 files changed

+57
-57
lines changed

6 files changed

+57
-57
lines changed

include/ada/url-inl.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,19 +148,19 @@ inline void url::update_base_port(std::optional<uint16_t> input) {
148148
port = input;
149149
}
150150

151-
inline void url::clear_pathname() { path.clear(); }
151+
constexpr void url::clear_pathname() { path.clear(); }
152152

153-
inline void url::clear_search() { query = std::nullopt; }
153+
constexpr void url::clear_search() { query = std::nullopt; }
154154

155-
[[nodiscard]] inline bool url::has_hash() const noexcept {
155+
[[nodiscard]] constexpr bool url::has_hash() const noexcept {
156156
return hash.has_value();
157157
}
158158

159-
[[nodiscard]] inline bool url::has_search() const noexcept {
159+
[[nodiscard]] constexpr bool url::has_search() const noexcept {
160160
return query.has_value();
161161
}
162162

163-
inline void url::set_protocol_as_file() { type = ada::scheme::type::FILE; }
163+
constexpr void url::set_protocol_as_file() { type = ada::scheme::type::FILE; }
164164

165165
inline void url::set_scheme(std::string &&new_scheme) noexcept {
166166
type = ada::scheme::get_scheme_type(new_scheme);
@@ -170,12 +170,12 @@ inline void url::set_scheme(std::string &&new_scheme) noexcept {
170170
}
171171
}
172172

173-
inline void url::copy_scheme(ada::url &&u) noexcept {
173+
constexpr void url::copy_scheme(ada::url &&u) noexcept {
174174
non_special_scheme = u.non_special_scheme;
175175
type = u.type;
176176
}
177177

178-
inline void url::copy_scheme(const ada::url &u) {
178+
constexpr void url::copy_scheme(const ada::url &u) {
179179
non_special_scheme = u.non_special_scheme;
180180
type = u.type;
181181
}

include/ada/url.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,9 @@ struct url : url_base {
283283
[[nodiscard]] ada_really_inline ada::url_components get_components()
284284
const noexcept;
285285
/** @return true if the URL has a hash component */
286-
[[nodiscard]] inline bool has_hash() const noexcept override;
286+
[[nodiscard]] constexpr bool has_hash() const noexcept override;
287287
/** @return true if the URL has a search component */
288-
[[nodiscard]] inline bool has_search() const noexcept override;
288+
[[nodiscard]] constexpr bool has_search() const noexcept override;
289289

290290
private:
291291
friend ada::url ada::parser::parse_url<ada::url>(std::string_view,
@@ -361,12 +361,6 @@ struct url : url_base {
361361
return this->parse_port(view, false);
362362
}
363363

364-
/**
365-
* Take the scheme from another URL. The scheme string is copied from the
366-
* provided url.
367-
*/
368-
inline void copy_scheme(const ada::url &u);
369-
370364
/**
371365
* Parse the host from the provided input. We assume that
372366
* the input does not contain spaces or tabs. Control
@@ -380,9 +374,9 @@ struct url : url_base {
380374
template <bool has_state_override = false>
381375
[[nodiscard]] ada_really_inline bool parse_scheme(std::string_view input);
382376

383-
inline void clear_pathname() override;
384-
inline void clear_search() override;
385-
inline void set_protocol_as_file();
377+
constexpr void clear_pathname() override;
378+
constexpr void clear_search() override;
379+
constexpr void set_protocol_as_file();
386380

387381
/**
388382
* Parse the path from the provided input.
@@ -407,7 +401,13 @@ struct url : url_base {
407401
* Take the scheme from another URL. The scheme string is moved from the
408402
* provided url.
409403
*/
410-
inline void copy_scheme(ada::url &&u) noexcept;
404+
constexpr void copy_scheme(ada::url &&u) noexcept;
405+
406+
/**
407+
* Take the scheme from another URL. The scheme string is copied from the
408+
* provided url.
409+
*/
410+
constexpr void copy_scheme(const ada::url &u);
411411

412412
}; // struct url
413413

include/ada/url_aggregator-inl.h

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ inline void url_aggregator::append_base_username(const std::string_view input) {
412412
ADA_ASSERT_TRUE(validate());
413413
}
414414

415-
inline void url_aggregator::clear_password() {
415+
constexpr void url_aggregator::clear_password() {
416416
ada_log("url_aggregator::clear_password ", to_string(), "\n", to_diagram());
417417
ADA_ASSERT_TRUE(validate());
418418
if (!has_password()) {
@@ -634,7 +634,7 @@ inline void url_aggregator::clear_hash() {
634634
ADA_ASSERT_TRUE(validate());
635635
}
636636

637-
inline void url_aggregator::clear_pathname() {
637+
constexpr void url_aggregator::clear_pathname() {
638638
ada_log("url_aggregator::clear_pathname");
639639
ADA_ASSERT_TRUE(validate());
640640
uint32_t ending_index = uint32_t(buffer.size());
@@ -669,7 +669,7 @@ inline void url_aggregator::clear_pathname() {
669669
ada_log("url_aggregator::clear_pathname completed, running checks... ok");
670670
}
671671

672-
inline void url_aggregator::clear_hostname() {
672+
constexpr void url_aggregator::clear_hostname() {
673673
ada_log("url_aggregator::clear_hostname");
674674
ADA_ASSERT_TRUE(validate());
675675
if (!has_authority()) {
@@ -706,22 +706,22 @@ inline void url_aggregator::clear_hostname() {
706706
ADA_ASSERT_TRUE(validate());
707707
}
708708

709-
[[nodiscard]] inline bool url_aggregator::has_hash() const noexcept {
709+
[[nodiscard]] constexpr bool url_aggregator::has_hash() const noexcept {
710710
ada_log("url_aggregator::has_hash");
711711
return components.hash_start != url_components::omitted;
712712
}
713713

714-
[[nodiscard]] inline bool url_aggregator::has_search() const noexcept {
714+
[[nodiscard]] constexpr bool url_aggregator::has_search() const noexcept {
715715
ada_log("url_aggregator::has_search");
716716
return components.search_start != url_components::omitted;
717717
}
718718

719-
ada_really_inline bool url_aggregator::has_credentials() const noexcept {
719+
constexpr bool url_aggregator::has_credentials() const noexcept {
720720
ada_log("url_aggregator::has_credentials");
721721
return has_non_empty_username() || has_non_empty_password();
722722
}
723723

724-
inline bool url_aggregator::cannot_have_credentials_or_port() const {
724+
constexpr bool url_aggregator::cannot_have_credentials_or_port() const {
725725
ada_log("url_aggregator::cannot_have_credentials_or_port");
726726
return type == ada::scheme::type::FILE ||
727727
components.host_start == components.host_end;
@@ -732,7 +732,7 @@ url_aggregator::get_components() const noexcept {
732732
return components;
733733
}
734734

735-
[[nodiscard]] inline bool ada::url_aggregator::has_authority() const noexcept {
735+
[[nodiscard]] constexpr bool ada::url_aggregator::has_authority() const noexcept {
736736
ada_log("url_aggregator::has_authority");
737737
// Performance: instead of doing this potentially expensive check, we could
738738
// have a boolean in the struct.
@@ -767,28 +767,28 @@ inline void ada::url_aggregator::add_authority_slashes_if_needed() noexcept {
767767
ADA_ASSERT_TRUE(validate());
768768
}
769769

770-
inline void ada::url_aggregator::reserve(uint32_t capacity) {
770+
constexpr void ada::url_aggregator::reserve(uint32_t capacity) {
771771
buffer.reserve(capacity);
772772
}
773773

774-
inline bool url_aggregator::has_non_empty_username() const noexcept {
774+
constexpr bool url_aggregator::has_non_empty_username() const noexcept {
775775
ada_log("url_aggregator::has_non_empty_username");
776776
return components.protocol_end + 2 < components.username_end;
777777
}
778778

779-
inline bool url_aggregator::has_non_empty_password() const noexcept {
779+
constexpr bool url_aggregator::has_non_empty_password() const noexcept {
780780
ada_log("url_aggregator::has_non_empty_password");
781781
return components.host_start - components.username_end > 0;
782782
}
783783

784-
inline bool url_aggregator::has_password() const noexcept {
784+
constexpr bool url_aggregator::has_password() const noexcept {
785785
ada_log("url_aggregator::has_password");
786786
// This function does not care about the length of the password
787787
return components.host_start > components.username_end &&
788788
buffer[components.username_end] == ':';
789789
}
790790

791-
inline bool url_aggregator::has_empty_hostname() const noexcept {
791+
constexpr bool url_aggregator::has_empty_hostname() const noexcept {
792792
if (!has_hostname()) {
793793
return false;
794794
}
@@ -801,18 +801,18 @@ inline bool url_aggregator::has_empty_hostname() const noexcept {
801801
return components.username_end != components.host_start;
802802
}
803803

804-
inline bool url_aggregator::has_hostname() const noexcept {
804+
constexpr bool url_aggregator::has_hostname() const noexcept {
805805
return has_authority();
806806
}
807807

808-
inline bool url_aggregator::has_port() const noexcept {
808+
constexpr bool url_aggregator::has_port() const noexcept {
809809
ada_log("url_aggregator::has_port");
810810
// A URL cannot have a username/password/port if its host is null or the empty
811811
// string, or its scheme is "file".
812812
return has_hostname() && components.pathname_start != components.host_end;
813813
}
814814

815-
[[nodiscard]] inline bool url_aggregator::has_dash_dot() const noexcept {
815+
[[nodiscard]] constexpr bool url_aggregator::has_dash_dot() const noexcept {
816816
// If url's host is null, url does not have an opaque path, url's path's size
817817
// is greater than 1, and url's path[0] is the empty string, then append
818818
// U+002F (/) followed by U+002E (.) to output.
@@ -844,7 +844,7 @@ inline bool url_aggregator::has_port() const noexcept {
844844
buffer[components.host_end + 1] == '.';
845845
}
846846

847-
[[nodiscard]] inline std::string_view url_aggregator::get_href() const noexcept
847+
[[nodiscard]] constexpr std::string_view url_aggregator::get_href() const noexcept
848848
ada_lifetime_bound {
849849
ada_log("url_aggregator::get_href");
850850
return buffer;
@@ -889,7 +889,7 @@ ada_really_inline size_t url_aggregator::parse_port(
889889
return consumed;
890890
}
891891

892-
inline void url_aggregator::set_protocol_as_file() {
892+
constexpr void url_aggregator::set_protocol_as_file() {
893893
ada_log("url_aggregator::set_protocol_as_file ");
894894
ADA_ASSERT_TRUE(validate());
895895
type = ada::scheme::type::FILE;

include/ada/url_aggregator.h

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ struct url_aggregator : url_base {
5757
* @see https://url.spec.whatwg.org/#dom-url-href
5858
* @see https://url.spec.whatwg.org/#concept-url-serializer
5959
*/
60-
[[nodiscard]] inline std::string_view get_href() const noexcept
60+
[[nodiscard]] constexpr std::string_view get_href() const noexcept
6161
ada_lifetime_bound;
6262
/**
6363
* The username getter steps are to return this's URL's username.
@@ -144,7 +144,7 @@ struct url_aggregator : url_base {
144144
* A URL includes credentials if its username or password is not the empty
145145
* string.
146146
*/
147-
[[nodiscard]] ada_really_inline bool has_credentials() const noexcept;
147+
[[nodiscard]] ada_really_inline constexpr bool has_credentials() const noexcept;
148148

149149
/**
150150
* Useful for implementing efficient serialization for the URL.
@@ -186,21 +186,21 @@ struct url_aggregator : url_base {
186186
[[nodiscard]] bool validate() const noexcept;
187187

188188
/** @return true if it has an host but it is the empty string */
189-
[[nodiscard]] inline bool has_empty_hostname() const noexcept;
189+
[[nodiscard]] constexpr bool has_empty_hostname() const noexcept;
190190
/** @return true if it has a host (included an empty host) */
191-
[[nodiscard]] inline bool has_hostname() const noexcept;
191+
[[nodiscard]] constexpr bool has_hostname() const noexcept;
192192
/** @return true if the URL has a non-empty username */
193-
[[nodiscard]] inline bool has_non_empty_username() const noexcept;
193+
[[nodiscard]] constexpr bool has_non_empty_username() const noexcept;
194194
/** @return true if the URL has a non-empty password */
195-
[[nodiscard]] inline bool has_non_empty_password() const noexcept;
195+
[[nodiscard]] constexpr bool has_non_empty_password() const noexcept;
196196
/** @return true if the URL has a (non default) port */
197-
[[nodiscard]] inline bool has_port() const noexcept;
197+
[[nodiscard]] constexpr bool has_port() const noexcept;
198198
/** @return true if the URL has a password */
199-
[[nodiscard]] inline bool has_password() const noexcept;
199+
[[nodiscard]] constexpr bool has_password() const noexcept;
200200
/** @return true if the URL has a hash component */
201-
[[nodiscard]] inline bool has_hash() const noexcept override;
201+
[[nodiscard]] constexpr bool has_hash() const noexcept override;
202202
/** @return true if the URL has a search component */
203-
[[nodiscard]] inline bool has_search() const noexcept override;
203+
[[nodiscard]] constexpr bool has_search() const noexcept override;
204204

205205
inline void clear_port();
206206
inline void clear_hash();
@@ -233,7 +233,7 @@ struct url_aggregator : url_base {
233233
* To optimize performance, you may indicate how much memory to allocate
234234
* within this instance.
235235
*/
236-
inline void reserve(uint32_t capacity);
236+
constexpr void reserve(uint32_t capacity);
237237

238238
ada_really_inline size_t parse_port(
239239
std::string_view view, bool check_trailing_content) noexcept override;
@@ -268,7 +268,7 @@ struct url_aggregator : url_base {
268268
* A URL cannot have a username/password/port if its host is null or the empty
269269
* string, or its scheme is "file".
270270
*/
271-
[[nodiscard]] inline bool cannot_have_credentials_or_port() const;
271+
[[nodiscard]] constexpr bool cannot_have_credentials_or_port() const;
272272

273273
template <bool override_hostname = false>
274274
bool set_host_or_hostname(std::string_view input);
@@ -290,19 +290,19 @@ struct url_aggregator : url_base {
290290
inline void update_base_port(uint32_t input);
291291
inline void append_base_pathname(std::string_view input);
292292
[[nodiscard]] inline uint32_t retrieve_base_port() const;
293-
inline void clear_hostname();
294-
inline void clear_password();
295-
inline void clear_pathname() override;
296-
[[nodiscard]] inline bool has_dash_dot() const noexcept;
293+
constexpr void clear_hostname();
294+
constexpr void clear_password();
295+
constexpr void clear_pathname() override;
296+
[[nodiscard]] constexpr bool has_dash_dot() const noexcept;
297297
void delete_dash_dot();
298298
inline void consume_prepared_path(std::string_view input);
299299
template <bool has_state_override = false>
300300
[[nodiscard]] ada_really_inline bool parse_scheme_with_colon(
301301
std::string_view input);
302302
ada_really_inline uint32_t replace_and_resize(uint32_t start, uint32_t end,
303303
std::string_view input);
304-
[[nodiscard]] inline bool has_authority() const noexcept;
305-
inline void set_protocol_as_file();
304+
[[nodiscard]] constexpr bool has_authority() const noexcept;
305+
constexpr void set_protocol_as_file();
306306
inline void set_scheme(std::string_view new_scheme) noexcept;
307307
/**
308308
* Fast function to set the scheme from a view with a colon in the

include/ada/url_base-inl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
namespace ada {
2323

24-
[[nodiscard]] ada_really_inline bool url_base::is_special() const noexcept {
24+
[[nodiscard]] ada_really_inline constexpr bool url_base::is_special() const noexcept {
2525
return type != ada::scheme::NOT_SPECIAL;
2626
}
2727

include/ada/url_base.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ struct url_base {
6868
* A URL is special if its scheme is a special scheme. A URL is not special if
6969
* its scheme is not a special scheme.
7070
*/
71-
[[nodiscard]] ada_really_inline bool is_special() const noexcept;
71+
[[nodiscard]] ada_really_inline constexpr bool is_special() const noexcept;
7272

7373
/**
7474
* The origin getter steps are to return the serialization of this's URL's

0 commit comments

Comments
 (0)