Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lemire/more constexpr #738

Merged
merged 5 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/ada.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "ada/url_base-inl.h"
#include "ada/url-inl.h"
#include "ada/url_components.h"
#include "ada/url_components-inl.h"
#include "ada/url_aggregator.h"
#include "ada/url_aggregator-inl.h"
#include "ada/url_search_params.h"
Expand Down
6 changes: 3 additions & 3 deletions include/ada/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ bool overlaps(std::string_view input1, const std::string& input2) noexcept;
* Return the substring from input going from index pos1 to the pos2 (non
* included). The length of the substring is pos2 - pos1.
*/
ada_really_inline std::string_view substring(const std::string& input,
size_t pos1,
size_t pos2) noexcept {
ada_really_inline constexpr std::string_view substring(const std::string& input,
size_t pos1,
size_t pos2) noexcept {
#if ADA_DEVELOPMENT_CHECKS
if (pos2 < pos1) {
std::cerr << "Negative-length substring: [" << pos1 << " to " << pos2 << ")"
Expand Down
18 changes: 11 additions & 7 deletions include/ada/url-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ inline std::ostream &operator<<(std::ostream &out, const ada::url &u) {
return path.size();
}

[[nodiscard]] constexpr std::string_view url::get_pathname() const noexcept {
return path;
}

[[nodiscard]] ada_really_inline ada::url_components url::get_components()
const noexcept {
url_components out{};
Expand Down Expand Up @@ -148,19 +152,19 @@ inline void url::update_base_port(std::optional<uint16_t> input) {
port = input;
}

inline void url::clear_pathname() { path.clear(); }
constexpr void url::clear_pathname() { path.clear(); }

inline void url::clear_search() { query = std::nullopt; }
constexpr void url::clear_search() { query = std::nullopt; }

[[nodiscard]] inline bool url::has_hash() const noexcept {
[[nodiscard]] constexpr bool url::has_hash() const noexcept {
return hash.has_value();
}

[[nodiscard]] inline bool url::has_search() const noexcept {
[[nodiscard]] constexpr bool url::has_search() const noexcept {
return query.has_value();
}

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

inline void url::set_scheme(std::string &&new_scheme) noexcept {
type = ada::scheme::get_scheme_type(new_scheme);
Expand All @@ -170,12 +174,12 @@ inline void url::set_scheme(std::string &&new_scheme) noexcept {
}
}

inline void url::copy_scheme(ada::url &&u) noexcept {
constexpr void url::copy_scheme(ada::url &&u) noexcept {
non_special_scheme = u.non_special_scheme;
type = u.type;
}

inline void url::copy_scheme(const ada::url &u) {
constexpr void url::copy_scheme(const ada::url &u) {
non_special_scheme = u.non_special_scheme;
type = u.type;
}
Expand Down
26 changes: 13 additions & 13 deletions include/ada/url.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ struct url : url_base {
* @return a newly allocated string.
* @see https://url.spec.whatwg.org/#dom-url-pathname
*/
[[nodiscard]] std::string_view get_pathname() const noexcept;
[[nodiscard]] constexpr std::string_view get_pathname() const noexcept;

/**
* Compute the pathname length in bytes without instantiating a view or a
Expand Down Expand Up @@ -283,9 +283,9 @@ struct url : url_base {
[[nodiscard]] ada_really_inline ada::url_components get_components()
const noexcept;
/** @return true if the URL has a hash component */
[[nodiscard]] inline bool has_hash() const noexcept override;
[[nodiscard]] constexpr bool has_hash() const noexcept override;
/** @return true if the URL has a search component */
[[nodiscard]] inline bool has_search() const noexcept override;
[[nodiscard]] constexpr bool has_search() const noexcept override;

private:
friend ada::url ada::parser::parse_url<ada::url>(std::string_view,
Expand Down Expand Up @@ -361,12 +361,6 @@ struct url : url_base {
return this->parse_port(view, false);
}

/**
* Take the scheme from another URL. The scheme string is copied from the
* provided url.
*/
inline void copy_scheme(const ada::url &u);

/**
* Parse the host from the provided input. We assume that
* the input does not contain spaces or tabs. Control
Expand All @@ -380,9 +374,9 @@ struct url : url_base {
template <bool has_state_override = false>
[[nodiscard]] ada_really_inline bool parse_scheme(std::string_view input);

inline void clear_pathname() override;
inline void clear_search() override;
inline void set_protocol_as_file();
constexpr void clear_pathname() override;
constexpr void clear_search() override;
constexpr void set_protocol_as_file();

/**
* Parse the path from the provided input.
Expand All @@ -407,7 +401,13 @@ struct url : url_base {
* Take the scheme from another URL. The scheme string is moved from the
* provided url.
*/
inline void copy_scheme(ada::url &&u) noexcept;
constexpr void copy_scheme(ada::url &&u) noexcept;

/**
* Take the scheme from another URL. The scheme string is copied from the
* provided url.
*/
constexpr void copy_scheme(const ada::url &u);

}; // struct url

Expand Down
Loading
Loading