Skip to content

Commit a8ce381

Browse files
committed
remove string comparisons and use uint32_t
1 parent 9f0ed2d commit a8ce381

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

include/ada/url_pattern_helpers-inl.h

+15-13
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@ template <url_pattern_regex::regex_concept regex_provider>
5555
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 "#".
58-
return is_non_special_pattern_char(token_index, "#");
58+
return is_non_special_pattern_char(token_index, '#');
5959
}
6060

6161
template <url_pattern_regex::regex_concept regex_provider>
6262
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.
65-
if (is_non_special_pattern_char(token_index, "?")) {
65+
if (is_non_special_pattern_char(token_index, '?')) {
6666
return true;
6767
}
6868

@@ -93,13 +93,15 @@ bool constructor_string_parser<regex_provider>::is_search_prefix() {
9393

9494
template <url_pattern_regex::regex_concept regex_provider>
9595
bool constructor_string_parser<regex_provider>::is_non_special_pattern_char(
96-
size_t index, std::string_view value) const {
96+
size_t index, uint32_t value) const {
9797
// Let token be the result of running get a safe token given parser and index.
9898
auto token = get_safe_token(index);
9999
ADA_ASSERT_TRUE(token);
100100

101101
// If token’s value is not value, then return false.
102-
if (token->value != value) {
102+
// TODO: Remove this once we make sure get_safe_token returns a non-empty
103+
// string.
104+
if (!token->value.empty() && token->value[0] != value) {
103105
return false;
104106
}
105107

@@ -152,12 +154,12 @@ bool constructor_string_parser<regex_provider>::next_is_authority_slashes()
152154
const {
153155
// If the result of running is a non-special pattern char given parser,
154156
// parser’s token index + 1, and "/" is false, then return false.
155-
if (!is_non_special_pattern_char(token_index + 1, "/")) {
157+
if (!is_non_special_pattern_char(token_index + 1, '/')) {
156158
return false;
157159
}
158160
// If the result of running is a non-special pattern char given parser,
159161
// parser’s token index + 2, and "/" is false, then return false.
160-
if (!is_non_special_pattern_char(token_index + 2, "/")) {
162+
if (!is_non_special_pattern_char(token_index + 2, '/')) {
161163
return false;
162164
}
163165
return true;
@@ -167,7 +169,7 @@ template <url_pattern_regex::regex_concept regex_provider>
167169
bool constructor_string_parser<regex_provider>::is_protocol_suffix() const {
168170
// Return the result of running is a non-special pattern char given parser,
169171
// parser’s token index, and ":".
170-
return is_non_special_pattern_char(token_index, ":");
172+
return is_non_special_pattern_char(token_index, ':');
171173
}
172174

173175
template <url_pattern_regex::regex_concept regex_provider>
@@ -295,42 +297,42 @@ bool constructor_string_parser<regex_provider>::is_an_identity_terminator()
295297
const {
296298
// Return the result of running is a non-special pattern char given parser,
297299
// parser’s token index, and "@".
298-
return is_non_special_pattern_char(token_index, "@");
300+
return is_non_special_pattern_char(token_index, '@');
299301
}
300302

301303
template <url_pattern_regex::regex_concept regex_provider>
302304
bool constructor_string_parser<regex_provider>::is_pathname_start() const {
303305
// Return the result of running is a non-special pattern char given parser,
304306
// parser’s token index, and "/".
305-
return is_non_special_pattern_char(token_index, "/");
307+
return is_non_special_pattern_char(token_index, '/');
306308
}
307309

308310
template <url_pattern_regex::regex_concept regex_provider>
309311
bool constructor_string_parser<regex_provider>::is_password_prefix() const {
310312
// Return the result of running is a non-special pattern char given parser,
311313
// parser’s token index, and ":".
312-
return is_non_special_pattern_char(token_index, ":");
314+
return is_non_special_pattern_char(token_index, ':');
313315
}
314316

315317
template <url_pattern_regex::regex_concept regex_provider>
316318
bool constructor_string_parser<regex_provider>::is_an_ipv6_open() const {
317319
// Return the result of running is a non-special pattern char given parser,
318320
// parser’s token index, and "[".
319-
return is_non_special_pattern_char(token_index, "[");
321+
return is_non_special_pattern_char(token_index, '[');
320322
}
321323

322324
template <url_pattern_regex::regex_concept regex_provider>
323325
bool constructor_string_parser<regex_provider>::is_an_ipv6_close() const {
324326
// Return the result of running is a non-special pattern char given parser,
325327
// parser’s token index, and "]".
326-
return is_non_special_pattern_char(token_index, "]");
328+
return is_non_special_pattern_char(token_index, ']');
327329
}
328330

329331
template <url_pattern_regex::regex_concept regex_provider>
330332
bool constructor_string_parser<regex_provider>::is_port_prefix() const {
331333
// Return the result of running is a non-special pattern char given parser,
332334
// parser’s token index, and ":".
333-
return is_non_special_pattern_char(token_index, ":");
335+
return is_non_special_pattern_char(token_index, ':');
334336
}
335337

336338
inline void Tokenizer::get_next_code_point() {

include/ada/url_pattern_helpers.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ struct constructor_string_parser {
222222

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

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

0 commit comments

Comments
 (0)