Skip to content

Commit 9bb54ec

Browse files
lemireanonrig
andauthored
more constexpr (#738)
* convert more functions to constexpr * moving functions around * tweak * lint * simplify --------- Co-authored-by: Yagiz Nizipli <[email protected]>
1 parent e730702 commit 9bb54ec

File tree

14 files changed

+349
-336
lines changed

14 files changed

+349
-336
lines changed

.github/workflows/aarch64.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,11 @@ concurrency:
2323
jobs:
2424
build:
2525
runs-on: ubuntu-latest
26-
strategy:
27-
matrix:
28-
shared: [OFF]
2926
steps:
3027
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
3128
- uses: uraimo/run-on-arch-action@b0ffb25eb00af00468375982384441f063da1741 # v2.7.2
3229
name: Build and Test
3330
id: runcmd
34-
env:
35-
CXX: g++-12
3631
with:
3732
arch: aarch64
3833
githubToken: ${{ github.token }}
@@ -41,6 +36,6 @@ jobs:
4136
apt-get update -q -y
4237
apt-get install -y cmake make g++ ninja-build git
4338
run: |
44-
cmake -DADA_SANITIZE_BOUNDS_STRICT=ON -DBUILD_SHARED_LIBS=${{matrix.shared}} -B build
39+
cmake -B build
4540
cmake --build build
4641
ctest --test-dir build

include/ada.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "ada/url_base-inl.h"
2222
#include "ada/url-inl.h"
2323
#include "ada/url_components.h"
24+
#include "ada/url_components-inl.h"
2425
#include "ada/url_aggregator.h"
2526
#include "ada/url_aggregator-inl.h"
2627
#include "ada/url_search_params.h"

include/ada/helpers.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ bool overlaps(std::string_view input1, const std::string& input2) noexcept;
102102
* Return the substring from input going from index pos1 to the pos2 (non
103103
* included). The length of the substring is pos2 - pos1.
104104
*/
105-
ada_really_inline std::string_view substring(const std::string& input,
106-
size_t pos1,
107-
size_t pos2) noexcept {
105+
ada_really_inline constexpr std::string_view substring(const std::string& input,
106+
size_t pos1,
107+
size_t pos2) noexcept {
108108
#if ADA_DEVELOPMENT_CHECKS
109109
if (pos2 < pos1) {
110110
std::cerr << "Negative-length substring: [" << pos1 << " to " << pos2 << ")"

include/ada/url-inl.h

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ inline std::ostream &operator<<(std::ostream &out, const ada::url &u) {
4343
return path.size();
4444
}
4545

46+
[[nodiscard]] constexpr std::string_view url::get_pathname() const noexcept {
47+
return path;
48+
}
49+
4650
[[nodiscard]] ada_really_inline ada::url_components url::get_components()
4751
const noexcept {
4852
url_components out{};
@@ -148,19 +152,19 @@ inline void url::update_base_port(std::optional<uint16_t> input) {
148152
port = input;
149153
}
150154

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

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

155-
[[nodiscard]] inline bool url::has_hash() const noexcept {
159+
[[nodiscard]] constexpr bool url::has_hash() const noexcept {
156160
return hash.has_value();
157161
}
158162

159-
[[nodiscard]] inline bool url::has_search() const noexcept {
163+
[[nodiscard]] constexpr bool url::has_search() const noexcept {
160164
return query.has_value();
161165
}
162166

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

165169
inline void url::set_scheme(std::string &&new_scheme) noexcept {
166170
type = ada::scheme::get_scheme_type(new_scheme);
@@ -170,12 +174,12 @@ inline void url::set_scheme(std::string &&new_scheme) noexcept {
170174
}
171175
}
172176

173-
inline void url::copy_scheme(ada::url &&u) noexcept {
177+
constexpr void url::copy_scheme(ada::url &&u) noexcept {
174178
non_special_scheme = u.non_special_scheme;
175179
type = u.type;
176180
}
177181

178-
inline void url::copy_scheme(const ada::url &u) {
182+
constexpr void url::copy_scheme(const ada::url &u) {
179183
non_special_scheme = u.non_special_scheme;
180184
type = u.type;
181185
}

include/ada/url.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ struct url : url_base {
149149
* @return a newly allocated string.
150150
* @see https://url.spec.whatwg.org/#dom-url-pathname
151151
*/
152-
[[nodiscard]] std::string_view get_pathname() const noexcept;
152+
[[nodiscard]] constexpr std::string_view get_pathname() const noexcept;
153153

154154
/**
155155
* Compute the pathname length in bytes without instantiating a view or a
@@ -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

0 commit comments

Comments
 (0)