Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
make more functions constexpr
  • Loading branch information
anonrig committed Sep 3, 2024
commit 3d70ae629b02b5dba1b555d0880632fc3f57f3ee
4 changes: 2 additions & 2 deletions include/ada/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ ada_really_inline void remove_ascii_tab_or_newline(std::string& input) noexcept;
* Return the substring from input going from index pos to the end.
* This function cannot throw.
*/
ada_really_inline std::string_view substring(std::string_view input,
size_t pos) noexcept;
ada_really_inline constexpr std::string_view substring(std::string_view input,
size_t pos) noexcept;

/**
* @private
Expand Down
14 changes: 6 additions & 8 deletions src/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
#include "ada/common_defs.h" // make sure ADA_IS_BIG_ENDIAN gets defined.
#include "ada/scheme.h"

#include <algorithm>
#include <charconv>
#include <cstring>
#include <sstream>

Expand Down Expand Up @@ -159,8 +157,8 @@ ada_really_inline void remove_ascii_tab_or_newline(
input.end());
}

ada_really_inline std::string_view substring(std::string_view input,
size_t pos) noexcept {
ada_really_inline constexpr std::string_view substring(std::string_view input,
size_t pos) noexcept {
ADA_ASSERT_TRUE(pos <= input.size());
// The following is safer but unneeded if we have the above line:
// return pos > input.size() ? std::string_view() : input.substr(pos);
Expand Down Expand Up @@ -317,7 +315,7 @@ ada_really_inline size_t find_next_host_delimiter_special(
#else
// : / [ \\ ?
static constexpr std::array<uint8_t, 256> special_host_delimiters =
[]() constexpr {
[]() consteval {
std::array<uint8_t, 256> result{};
for (int i : {':', '/', '[', '\\', '?'}) {
result[i] = 1;
Expand Down Expand Up @@ -449,7 +447,7 @@ ada_really_inline size_t find_next_host_delimiter(std::string_view view,
}
#else
// : / [ ?
static constexpr std::array<uint8_t, 256> host_delimiters = []() constexpr {
static constexpr std::array<uint8_t, 256> host_delimiters = []() consteval {
std::array<uint8_t, 256> result{};
for (int i : {':', '/', '?', '['}) {
result[i] = 1;
Expand Down Expand Up @@ -744,7 +742,7 @@ ada_really_inline void strip_trailing_spaces_from_opaque_path(

// @ / \\ ?
static constexpr std::array<uint8_t, 256> authority_delimiter_special =
[]() constexpr {
[]() consteval {
std::array<uint8_t, 256> result{};
for (uint8_t i : {'@', '/', '\\', '?'}) {
result[i] = 1;
Expand All @@ -765,7 +763,7 @@ find_authority_delimiter_special(std::string_view view) noexcept {
}

// @ / ?
static constexpr std::array<uint8_t, 256> authority_delimiter = []() constexpr {
static constexpr std::array<uint8_t, 256> authority_delimiter = []() consteval {
std::array<uint8_t, 256> result{};
for (uint8_t i : {'@', '/', '?'}) {
result[i] = 1;
Expand Down
2 changes: 1 addition & 1 deletion src/unicode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ ada_really_inline constexpr bool contains_forbidden_domain_code_point(
}

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