Skip to content

Commit b359743

Browse files
committed
make more functions private and constexpr
1 parent 9737407 commit b359743

File tree

2 files changed

+58
-49
lines changed

2 files changed

+58
-49
lines changed

include/ada/url_pattern_helpers-inl.h

+29-20
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,22 @@ inline std::string to_string(token_type type) {
4444
#endif // ADA_TESTING
4545

4646
template <url_pattern_regex::regex_concept regex_provider>
47-
void constructor_string_parser<regex_provider>::rewind() {
47+
constexpr void constructor_string_parser<regex_provider>::rewind() {
4848
// Set parser’s token index to parser’s component start.
4949
token_index = component_start;
5050
// Set parser’s token increment to 0.
5151
token_increment = 0;
5252
}
5353

5454
template <url_pattern_regex::regex_concept regex_provider>
55-
bool constructor_string_parser<regex_provider>::is_hash_prefix() {
55+
constexpr bool constructor_string_parser<regex_provider>::is_hash_prefix() {
5656
// Return the result of running is a non-special pattern char given parser,
5757
// parser’s token index and "#".
5858
return is_non_special_pattern_char(token_index, '#');
5959
}
6060

6161
template <url_pattern_regex::regex_concept regex_provider>
62-
bool constructor_string_parser<regex_provider>::is_search_prefix() {
62+
constexpr bool constructor_string_parser<regex_provider>::is_search_prefix() {
6363
// If result of running is a non-special pattern char given parser, parser’s
6464
// token index and "?" is true, then return true.
6565
if (is_non_special_pattern_char(token_index, '?')) {
@@ -92,7 +92,8 @@ bool constructor_string_parser<regex_provider>::is_search_prefix() {
9292
}
9393

9494
template <url_pattern_regex::regex_concept regex_provider>
95-
bool constructor_string_parser<regex_provider>::is_non_special_pattern_char(
95+
constexpr bool
96+
constructor_string_parser<regex_provider>::is_non_special_pattern_char(
9697
size_t index, uint32_t value) const {
9798
// Let token be the result of running get a safe token given parser and index.
9899
auto token = get_safe_token(index);
@@ -116,8 +117,8 @@ bool constructor_string_parser<regex_provider>::is_non_special_pattern_char(
116117
}
117118

118119
template <url_pattern_regex::regex_concept regex_provider>
119-
const token* constructor_string_parser<regex_provider>::get_safe_token(
120-
size_t index) const {
120+
constexpr const token*
121+
constructor_string_parser<regex_provider>::get_safe_token(size_t index) const {
121122
// If index is less than parser’s token list's size, then return parser’s
122123
// token list[index].
123124
if (index < token_list.size()) [[likely]] {
@@ -136,22 +137,24 @@ const token* constructor_string_parser<regex_provider>::get_safe_token(
136137
}
137138

138139
template <url_pattern_regex::regex_concept regex_provider>
139-
bool constructor_string_parser<regex_provider>::is_group_open() const {
140+
constexpr bool constructor_string_parser<regex_provider>::is_group_open()
141+
const {
140142
// If parser’s token list[parser’s token index]'s type is "open", then return
141143
// true.
142144
return token_list[token_index].type == token_type::OPEN;
143145
}
144146

145147
template <url_pattern_regex::regex_concept regex_provider>
146-
bool constructor_string_parser<regex_provider>::is_group_close() const {
148+
constexpr bool constructor_string_parser<regex_provider>::is_group_close()
149+
const {
147150
// If parser’s token list[parser’s token index]'s type is "close", then return
148151
// true.
149152
return token_list[token_index].type == token_type::CLOSE;
150153
}
151154

152155
template <url_pattern_regex::regex_concept regex_provider>
153-
bool constructor_string_parser<regex_provider>::next_is_authority_slashes()
154-
const {
156+
constexpr bool
157+
constructor_string_parser<regex_provider>::next_is_authority_slashes() const {
155158
// If the result of running is a non-special pattern char given parser,
156159
// parser’s token index + 1, and "/" is false, then return false.
157160
if (!is_non_special_pattern_char(token_index + 1, '/')) {
@@ -166,7 +169,8 @@ bool constructor_string_parser<regex_provider>::next_is_authority_slashes()
166169
}
167170

168171
template <url_pattern_regex::regex_concept regex_provider>
169-
bool constructor_string_parser<regex_provider>::is_protocol_suffix() const {
172+
constexpr bool constructor_string_parser<regex_provider>::is_protocol_suffix()
173+
const {
170174
// Return the result of running is a non-special pattern char given parser,
171175
// parser’s token index, and ":".
172176
return is_non_special_pattern_char(token_index, ':');
@@ -293,49 +297,54 @@ std::string constructor_string_parser<regex_provider>::make_component_string() {
293297
}
294298

295299
template <url_pattern_regex::regex_concept regex_provider>
296-
bool constructor_string_parser<regex_provider>::is_an_identity_terminator()
297-
const {
300+
constexpr bool
301+
constructor_string_parser<regex_provider>::is_an_identity_terminator() const {
298302
// Return the result of running is a non-special pattern char given parser,
299303
// parser’s token index, and "@".
300304
return is_non_special_pattern_char(token_index, '@');
301305
}
302306

303307
template <url_pattern_regex::regex_concept regex_provider>
304-
bool constructor_string_parser<regex_provider>::is_pathname_start() const {
308+
constexpr bool constructor_string_parser<regex_provider>::is_pathname_start()
309+
const {
305310
// Return the result of running is a non-special pattern char given parser,
306311
// parser’s token index, and "/".
307312
return is_non_special_pattern_char(token_index, '/');
308313
}
309314

310315
template <url_pattern_regex::regex_concept regex_provider>
311-
bool constructor_string_parser<regex_provider>::is_password_prefix() const {
316+
constexpr bool constructor_string_parser<regex_provider>::is_password_prefix()
317+
const {
312318
// Return the result of running is a non-special pattern char given parser,
313319
// parser’s token index, and ":".
314320
return is_non_special_pattern_char(token_index, ':');
315321
}
316322

317323
template <url_pattern_regex::regex_concept regex_provider>
318-
bool constructor_string_parser<regex_provider>::is_an_ipv6_open() const {
324+
constexpr bool constructor_string_parser<regex_provider>::is_an_ipv6_open()
325+
const {
319326
// Return the result of running is a non-special pattern char given parser,
320327
// parser’s token index, and "[".
321328
return is_non_special_pattern_char(token_index, '[');
322329
}
323330

324331
template <url_pattern_regex::regex_concept regex_provider>
325-
bool constructor_string_parser<regex_provider>::is_an_ipv6_close() const {
332+
constexpr bool constructor_string_parser<regex_provider>::is_an_ipv6_close()
333+
const {
326334
// Return the result of running is a non-special pattern char given parser,
327335
// parser’s token index, and "]".
328336
return is_non_special_pattern_char(token_index, ']');
329337
}
330338

331339
template <url_pattern_regex::regex_concept regex_provider>
332-
bool constructor_string_parser<regex_provider>::is_port_prefix() const {
340+
constexpr bool constructor_string_parser<regex_provider>::is_port_prefix()
341+
const {
333342
// Return the result of running is a non-special pattern char given parser,
334343
// parser’s token index, and ":".
335344
return is_non_special_pattern_char(token_index, ':');
336345
}
337346

338-
inline void Tokenizer::get_next_code_point() {
347+
constexpr void Tokenizer::get_next_code_point() {
339348
ada_log("Tokenizer::get_next_code_point called with index=", next_index);
340349
ADA_ASSERT_TRUE(next_index < input.size());
341350
// this assumes that we have a valid, non-truncated UTF-8 stream.
@@ -382,7 +391,7 @@ inline void Tokenizer::get_next_code_point() {
382391
next_index += number_bytes;
383392
}
384393

385-
inline void Tokenizer::seek_and_get_next_code_point(size_t new_index) {
394+
constexpr void Tokenizer::seek_and_get_next_code_point(size_t new_index) {
386395
ada_log("Tokenizer::seek_and_get_next_code_point called with new_index=",
387396
new_index);
388397
// Set tokenizer’s next index to index.

include/ada/url_pattern_helpers.h

+29-29
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,10 @@ class Tokenizer {
109109
: input(new_input), policy(new_policy) {}
110110

111111
// @see https://urlpattern.spec.whatwg.org/#get-the-next-code-point
112-
void get_next_code_point();
112+
constexpr void get_next_code_point();
113113

114114
// @see https://urlpattern.spec.whatwg.org/#seek-and-get-the-next-code-point
115-
void seek_and_get_next_code_point(size_t index);
115+
constexpr void seek_and_get_next_code_point(size_t index);
116116

117117
// @see https://urlpattern.spec.whatwg.org/#add-a-token
118118

@@ -155,16 +155,6 @@ struct constructor_string_parser {
155155
explicit constructor_string_parser(std::string_view new_input,
156156
std::vector<token>&& new_token_list)
157157
: input(new_input), token_list(std::move(new_token_list)) {}
158-
159-
// @see https://urlpattern.spec.whatwg.org/#rewind
160-
void rewind();
161-
162-
// @see https://urlpattern.spec.whatwg.org/#is-a-hash-prefix
163-
bool is_hash_prefix();
164-
165-
// @see https://urlpattern.spec.whatwg.org/#is-a-search-prefix
166-
bool is_search_prefix();
167-
168158
// @see https://urlpattern.spec.whatwg.org/#parse-a-constructor-string
169159
static tl::expected<url_pattern_init, errors> parse(std::string_view input);
170160

@@ -183,49 +173,59 @@ struct constructor_string_parser {
183173
DONE,
184174
};
185175

176+
// @see
177+
// https://urlpattern.spec.whatwg.org/#compute-protocol-matches-a-special-scheme-flag
178+
std::optional<errors> compute_protocol_matches_special_scheme_flag();
179+
180+
private:
181+
// @see https://urlpattern.spec.whatwg.org/#rewind
182+
constexpr void rewind();
183+
184+
// @see https://urlpattern.spec.whatwg.org/#is-a-hash-prefix
185+
constexpr bool is_hash_prefix();
186+
187+
// @see https://urlpattern.spec.whatwg.org/#is-a-search-prefix
188+
constexpr bool is_search_prefix();
189+
186190
// @see https://urlpattern.spec.whatwg.org/#change-state
187191
void change_state(State state, size_t skip);
188192

189193
// @see https://urlpattern.spec.whatwg.org/#is-a-group-open
190-
bool is_group_open() const;
194+
constexpr bool is_group_open() const;
191195

192196
// @see https://urlpattern.spec.whatwg.org/#is-a-group-close
193-
bool is_group_close() const;
197+
constexpr bool is_group_close() const;
194198

195199
// @see https://urlpattern.spec.whatwg.org/#is-a-protocol-suffix
196-
bool is_protocol_suffix() const;
197-
198-
// @see
199-
// https://urlpattern.spec.whatwg.org/#compute-protocol-matches-a-special-scheme-flag
200-
std::optional<errors> compute_protocol_matches_special_scheme_flag();
200+
constexpr bool is_protocol_suffix() const;
201201

202202
// @see https://urlpattern.spec.whatwg.org/#next-is-authority-slashes
203-
bool next_is_authority_slashes() const;
203+
constexpr bool next_is_authority_slashes() const;
204204

205205
// @see https://urlpattern.spec.whatwg.org/#is-an-identity-terminator
206-
bool is_an_identity_terminator() const;
206+
constexpr bool is_an_identity_terminator() const;
207207

208208
// @see https://urlpattern.spec.whatwg.org/#is-a-pathname-start
209-
bool is_pathname_start() const;
209+
constexpr bool is_pathname_start() const;
210210

211211
// @see https://urlpattern.spec.whatwg.org/#is-a-password-prefix
212-
bool is_password_prefix() const;
212+
constexpr bool is_password_prefix() const;
213213

214214
// @see https://urlpattern.spec.whatwg.org/#is-an-ipv6-open
215-
bool is_an_ipv6_open() const;
215+
constexpr bool is_an_ipv6_open() const;
216216

217217
// @see https://urlpattern.spec.whatwg.org/#is-an-ipv6-close
218-
bool is_an_ipv6_close() const;
218+
constexpr bool is_an_ipv6_close() const;
219219

220220
// @see https://urlpattern.spec.whatwg.org/#is-a-port-prefix
221-
bool is_port_prefix() const;
221+
constexpr bool is_port_prefix() const;
222222

223-
private:
224223
// @see https://urlpattern.spec.whatwg.org/#is-a-non-special-pattern-char
225-
bool is_non_special_pattern_char(size_t index, uint32_t value) const;
224+
constexpr bool is_non_special_pattern_char(size_t index,
225+
uint32_t value) const;
226226

227227
// @see https://urlpattern.spec.whatwg.org/#get-a-safe-token
228-
const token* get_safe_token(size_t index) const;
228+
constexpr const token* get_safe_token(size_t index) const;
229229

230230
// @see https://urlpattern.spec.whatwg.org/#make-a-component-string
231231
std::string make_component_string();

0 commit comments

Comments
 (0)