Skip to content

Commit

Permalink
improve url_pattern_part emplace_back calls
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig committed Dec 29, 2024
1 parent e7c580d commit 5ced1da
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
16 changes: 15 additions & 1 deletion include/ada/url_pattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,21 @@ enum class url_pattern_part_modifier : uint8_t {
};

// @see https://urlpattern.spec.whatwg.org/#part
struct url_pattern_part {
class url_pattern_part {
public:
url_pattern_part(url_pattern_part_type _type, std::string&& _value,
url_pattern_part_modifier _modifier)
: type(_type), value(_value), modifier(_modifier) {}

url_pattern_part(url_pattern_part_type _type, std::string&& _value,
url_pattern_part_modifier _modifier, std::string&& _name,
std::string&& _prefix, std::string&& _suffix)
: type(_type),
value(_value),
modifier(_modifier),
name(_name),
prefix(_prefix),
suffix(_suffix) {}
// A part has an associated type, a string, which must be set upon creation.
url_pattern_part_type type;
// A part has an associated value, a string, which must be set upon creation.
Expand Down
22 changes: 7 additions & 15 deletions include/ada/url_pattern_helpers-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -519,11 +519,10 @@ url_pattern_parser<F>::maybe_add_part_from_the_pending_fixed_value() {
pending_fixed_value.clear();
// Let part be a new part whose type is "fixed-text", value is encoded value,
// and modifier is "none".
url_pattern_part part{.type = url_pattern_part_type::FIXED_TEXT,
.value = std::move(*encoded_value),
.modifier = url_pattern_part_modifier::NONE};
// Append part to parser’s part list.
parts.push_back(std::move(part));
parts.emplace_back(url_pattern_part_type::FIXED_TEXT,
std::move(*encoded_value),
url_pattern_part_modifier::NONE);
return std::nullopt;
}

Expand Down Expand Up @@ -574,11 +573,9 @@ std::optional<url_pattern_errors> url_pattern_parser<F>::add_part(
}
// Let part be a new part whose type is "fixed-text", value is encoded
// value, and modifier is modifier.
url_pattern_part part{.type = url_pattern_part_type::FIXED_TEXT,
.value = std::move(*encoded_value),
.modifier = modifier};
// Append part to parser’s part list.
parts.push_back(std::move(part));
parts.emplace_back(url_pattern_part_type::FIXED_TEXT,
std::move(*encoded_value), modifier);
return std::nullopt;
}
// Let regexp value be the empty string.
Expand Down Expand Up @@ -639,14 +636,9 @@ std::optional<url_pattern_errors> url_pattern_parser<F>::add_part(
// Let part be a new part whose type is type, value is regexp value,
// modifier is modifier, name is name, prefix is encoded prefix, and suffix
// is encoded suffix.
auto part = url_pattern_part{.type = type,
.value = std::move(regexp_value),
.modifier = modifier,
.name = std::move(name),
.prefix = std::move(*encoded_prefix),
.suffix = std::move(*encoded_suffix)};
// Append part to parser’s part list.
parts.push_back(std::move(part));
parts.emplace_back(type, std::move(regexp_value), modifier, std::move(name),
std::move(*encoded_prefix), std::move(*encoded_suffix));
return std::nullopt;
}

Expand Down
2 changes: 1 addition & 1 deletion src/url_pattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ generate_regular_expression_and_name_list(
std::string result = "^";

// Let name list be a new list
std::vector<std::string> name_list;
std::vector<std::string> name_list{};
const std::string full_wildcard_regexp_value = ".*";

// For each part of part list:
Expand Down

0 comments on commit 5ced1da

Please sign in to comment.