|
9 | 9 | #include "ada/url_pattern_helpers.h"
|
10 | 10 | #include "ada/url_pattern.h"
|
11 | 11 |
|
| 12 | +#include <algorithm> |
12 | 13 | #include <string_view>
|
| 14 | +#include <utility> |
13 | 15 |
|
14 | 16 | namespace ada {
|
15 | 17 |
|
@@ -330,36 +332,34 @@ result<std::optional<url_pattern_result>> url_pattern<regex_provider>::match(
|
330 | 332 | // https://github.com/cloudflare/workerd/blob/8620d14012513a6ce04d079e401d3becac3c67bd/src/workerd/jsg/url.c%2B%2B#L2038
|
331 | 333 | protocol = url->get_protocol().substr(0, url->get_protocol().size() - 1);
|
332 | 334 | // Set username to url’s username.
|
333 |
| - username = url->get_username(); |
| 335 | + username = std::move(url->get_username()); |
334 | 336 | // Set password to url’s password.
|
335 |
| - password = url->get_password(); |
| 337 | + password = std::move(url->get_password()); |
336 | 338 | // Set hostname to url’s host, serialized, or the empty string if the value
|
337 | 339 | // is null.
|
338 |
| - hostname = url->get_hostname(); |
| 340 | + hostname = std::move(url->get_hostname()); |
339 | 341 | // Set port to url’s port, serialized, or the empty string if the value is
|
340 | 342 | // null.
|
341 |
| - port = url->get_port(); |
| 343 | + port = std::move(url->get_port()); |
342 | 344 | // Set pathname to the result of URL path serializing url.
|
343 |
| - pathname = url->get_pathname(); |
| 345 | + pathname = std::move(url->get_pathname()); |
344 | 346 | // Set search to url’s query or the empty string if the value is null.
|
345 | 347 | // IMPORTANT: Not documented on the URLPattern spec, but search prefix '?'
|
346 | 348 | // is removed. Similar work was done on workerd:
|
347 | 349 | // https://github.com/cloudflare/workerd/blob/8620d14012513a6ce04d079e401d3becac3c67bd/src/workerd/jsg/url.c%2B%2B#L2232
|
348 | 350 | if (url->has_search()) {
|
349 | 351 | auto view = url->get_search();
|
350 |
| - search = view.starts_with("?") ? url->get_search().substr(1) : view; |
351 |
| - } else { |
352 |
| - search = ""; |
| 352 | + search = |
| 353 | + view.starts_with("?") ? url->get_search().substr(1) : std::move(view); |
353 | 354 | }
|
354 | 355 | // Set hash to url’s fragment or the empty string if the value is null.
|
355 | 356 | // IMPORTANT: Not documented on the URLPattern spec, but hash prefix '#' is
|
356 | 357 | // removed. Similar work was done on workerd:
|
357 | 358 | // https://github.com/cloudflare/workerd/blob/8620d14012513a6ce04d079e401d3becac3c67bd/src/workerd/jsg/url.c%2B%2B#L2242
|
358 | 359 | if (url->has_hash()) {
|
359 | 360 | auto view = url->get_hash();
|
360 |
| - hash = view.starts_with("#") ? url->get_hash().substr(1) : view; |
361 |
| - } else { |
362 |
| - hash = ""; |
| 361 | + hash = |
| 362 | + view.starts_with("#") ? url->get_hash().substr(1) : std::move(view); |
363 | 363 | }
|
364 | 364 | }
|
365 | 365 |
|
|
0 commit comments