Skip to content

Commit e4b2293

Browse files
committed
make more functions constexpr
1 parent 9a1fcad commit e4b2293

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

include/ada/helpers.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ ada_really_inline void remove_ascii_tab_or_newline(std::string& input) noexcept;
8888
* Return the substring from input going from index pos to the end.
8989
* This function cannot throw.
9090
*/
91-
ada_really_inline std::string_view substring(std::string_view input,
92-
size_t pos) noexcept;
91+
ada_really_inline constexpr std::string_view substring(std::string_view input,
92+
size_t pos) noexcept;
9393

9494
/**
9595
* @private

src/helpers.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
#include "ada/common_defs.h" // make sure ADA_IS_BIG_ENDIAN gets defined.
44
#include "ada/scheme.h"
55

6-
#include <algorithm>
7-
#include <charconv>
86
#include <cstring>
97
#include <sstream>
108

@@ -159,8 +157,8 @@ ada_really_inline void remove_ascii_tab_or_newline(
159157
input.end());
160158
}
161159

162-
ada_really_inline std::string_view substring(std::string_view input,
163-
size_t pos) noexcept {
160+
ada_really_inline constexpr std::string_view substring(std::string_view input,
161+
size_t pos) noexcept {
164162
ADA_ASSERT_TRUE(pos <= input.size());
165163
// The following is safer but unneeded if we have the above line:
166164
// return pos > input.size() ? std::string_view() : input.substr(pos);
@@ -317,7 +315,7 @@ ada_really_inline size_t find_next_host_delimiter_special(
317315
#else
318316
// : / [ \\ ?
319317
static constexpr std::array<uint8_t, 256> special_host_delimiters =
320-
[]() constexpr {
318+
[]() consteval {
321319
std::array<uint8_t, 256> result{};
322320
for (int i : {':', '/', '[', '\\', '?'}) {
323321
result[i] = 1;
@@ -449,7 +447,7 @@ ada_really_inline size_t find_next_host_delimiter(std::string_view view,
449447
}
450448
#else
451449
// : / [ ?
452-
static constexpr std::array<uint8_t, 256> host_delimiters = []() constexpr {
450+
static constexpr std::array<uint8_t, 256> host_delimiters = []() consteval {
453451
std::array<uint8_t, 256> result{};
454452
for (int i : {':', '/', '?', '['}) {
455453
result[i] = 1;
@@ -744,7 +742,7 @@ ada_really_inline void strip_trailing_spaces_from_opaque_path(
744742

745743
// @ / \\ ?
746744
static constexpr std::array<uint8_t, 256> authority_delimiter_special =
747-
[]() constexpr {
745+
[]() consteval {
748746
std::array<uint8_t, 256> result{};
749747
for (uint8_t i : {'@', '/', '\\', '?'}) {
750748
result[i] = 1;
@@ -765,7 +763,7 @@ find_authority_delimiter_special(std::string_view view) noexcept {
765763
}
766764

767765
// @ / ?
768-
static constexpr std::array<uint8_t, 256> authority_delimiter = []() constexpr {
766+
static constexpr std::array<uint8_t, 256> authority_delimiter = []() consteval {
769767
std::array<uint8_t, 256> result{};
770768
for (uint8_t i : {'@', '/', '?'}) {
771769
result[i] = 1;

src/unicode.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ ada_really_inline constexpr bool contains_forbidden_domain_code_point(
210210
}
211211

212212
constexpr static std::array<uint8_t, 256>
213-
is_forbidden_domain_code_point_table_or_upper = []() constexpr {
213+
is_forbidden_domain_code_point_table_or_upper = []() consteval {
214214
std::array<uint8_t, 256> result{};
215215
for (uint8_t c : {'\0', '\x09', '\x0a', '\x0d', ' ', '#', '/', ':', '<',
216216
'>', '?', '@', '[', '\\', ']', '^', '|', '%'}) {

0 commit comments

Comments
 (0)