Skip to content

Commit bc71ba7

Browse files
authored
optimize urlpattern as much as we can (#1035)
1 parent 8139b3f commit bc71ba7

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

include/ada/url_pattern-inl.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,8 @@ url_pattern_component<regex_provider>::create_component_match_result(
4646
// says we should start from 1. This case is handled by the
4747
// std_regex_provider.
4848
for (size_t index = 0; index < exec_result.size(); index++) {
49-
result.groups.insert({
50-
group_name_list[index],
51-
std::move(exec_result[index]),
52-
});
49+
result.groups.emplace(group_name_list[index],
50+
std::move(exec_result[index]));
5351
}
5452
return result;
5553
}

src/url_pattern_regex.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,9 @@ std::optional<std::regex> std_regex_provider::create_instance(
2525
std::optional<std::vector<std::optional<std::string>>>
2626
std_regex_provider::regex_search(std::string_view input,
2727
const std::regex& pattern) {
28-
std::string input_str(
29-
input.begin(),
30-
input.end()); // Convert string_view to string for regex_search
31-
std::smatch match_result;
32-
if (!std::regex_search(input_str, match_result, pattern,
28+
// Use iterator-based regex_search to avoid string allocation
29+
std::match_results<std::string_view::const_iterator> match_result;
30+
if (!std::regex_search(input.begin(), input.end(), match_result, pattern,
3331
std::regex_constants::match_any)) {
3432
return std::nullopt;
3533
}

0 commit comments

Comments
 (0)