mirror of
https://github.com/SerenityOS/serenity
synced 2024-10-07 00:19:27 +00:00
LibWeb: Return FlyString from CSS::Parser::Token::ident
Instead of a StringView. This allows us to preserve the nice O(1) string compare property of FlyString, and not needing to allocate when one is needed. Ideally all other places in Token should have similar changes done, but to prevent a huge amount of churn, just change ident for now.
This commit is contained in:
parent
8c8ea86729
commit
3f13a50a20
|
@ -261,12 +261,12 @@ Optional<MediaFeature> Parser::parse_media_feature(TokenStream<ComponentValue>&
|
|||
return MediaFeatureName { MediaFeatureName::Type::Normal, id.value() };
|
||||
}
|
||||
|
||||
if (allow_min_max_prefix && (name.starts_with("min-"sv, CaseSensitivity::CaseInsensitive) || name.starts_with("max-"sv, CaseSensitivity::CaseInsensitive))) {
|
||||
auto adjusted_name = name.substring_view(4);
|
||||
if (allow_min_max_prefix && (name.starts_with_bytes("min-"sv, CaseSensitivity::CaseInsensitive) || name.starts_with_bytes("max-"sv, CaseSensitivity::CaseInsensitive))) {
|
||||
auto adjusted_name = name.bytes_as_string_view().substring_view(4);
|
||||
if (auto id = media_feature_id_from_string(adjusted_name); id.has_value() && media_feature_type_is_range(id.value())) {
|
||||
transaction.commit();
|
||||
return MediaFeatureName {
|
||||
name.starts_with("min-"sv, CaseSensitivity::CaseInsensitive) ? MediaFeatureName::Type::Min : MediaFeatureName::Type::Max,
|
||||
name.starts_with_bytes("min-"sv, CaseSensitivity::CaseInsensitive) ? MediaFeatureName::Type::Min : MediaFeatureName::Type::Max,
|
||||
id.value()
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1574,7 +1574,7 @@ CSSRule* Parser::convert_to_rule(NonnullRefPtr<Rule> rule)
|
|||
auto token = token_stream.next_token();
|
||||
Optional<DeprecatedString> prefix = {};
|
||||
if (token.is(Token::Type::Ident)) {
|
||||
prefix = token.token().ident();
|
||||
prefix = token.token().ident().bytes_as_string_view();
|
||||
token_stream.skip_whitespace();
|
||||
token = token_stream.next_token();
|
||||
}
|
||||
|
@ -2446,7 +2446,7 @@ Optional<Color> Parser::parse_color(ComponentValue const& component_value)
|
|||
else {
|
||||
if (!cv.is(Token::Type::Ident))
|
||||
return {};
|
||||
serialization = cv.token().ident();
|
||||
serialization = cv.token().ident().bytes_as_string_view();
|
||||
}
|
||||
|
||||
// 4. If serialization does not consist of three or six characters, return an error.
|
||||
|
@ -4178,7 +4178,7 @@ RefPtr<StyleValue> Parser::parse_font_family_value(TokenStream<ComponentValue>&
|
|||
(void)tokens.next_token(); // Comma
|
||||
continue;
|
||||
}
|
||||
current_name_parts.append(tokens.next_token().token().ident());
|
||||
current_name_parts.append(tokens.next_token().token().ident().bytes_as_string_view());
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -4270,7 +4270,7 @@ CSSRule* Parser::parse_font_face_rule(TokenStream<ComponentValue>& tokens)
|
|||
had_syntax_error = true;
|
||||
break;
|
||||
}
|
||||
font_family_parts.append(part.token().ident());
|
||||
font_family_parts.append(part.token().ident().bytes_as_string_view());
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -6800,7 +6800,7 @@ bool Parser::expand_variables(DOM::Element& element, Optional<Selector::PseudoEl
|
|||
if (!custom_property_name_token.is(Token::Type::Ident))
|
||||
return false;
|
||||
auto custom_property_name = custom_property_name_token.token().ident();
|
||||
if (!custom_property_name.starts_with("--"sv))
|
||||
if (!custom_property_name.bytes_as_string_view().starts_with("--"sv))
|
||||
return false;
|
||||
|
||||
// Detect dependency cycles. https://www.w3.org/TR/css-variables-1/#cycles
|
||||
|
|
|
@ -729,10 +729,10 @@ Optional<Selector::SimpleSelector::ANPlusBPattern> Parser::parse_a_n_plus_b_patt
|
|||
if (!value.is(Token::Type::Ident))
|
||||
return false;
|
||||
auto ident = value.token().ident();
|
||||
if (!ident.starts_with("n-"sv, CaseSensitivity::CaseInsensitive))
|
||||
if (!ident.starts_with_bytes("n-"sv, CaseSensitivity::CaseInsensitive))
|
||||
return false;
|
||||
for (size_t i = 2; i < ident.length(); ++i) {
|
||||
if (!is_ascii_digit(ident[i]))
|
||||
for (size_t i = 2; i < ident.bytes_as_string_view().length(); ++i) {
|
||||
if (!is_ascii_digit(ident.bytes_as_string_view()[i]))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -741,12 +741,12 @@ Optional<Selector::SimpleSelector::ANPlusBPattern> Parser::parse_a_n_plus_b_patt
|
|||
if (!value.is(Token::Type::Ident))
|
||||
return false;
|
||||
auto ident = value.token().ident();
|
||||
if (!ident.starts_with("-n-"sv, CaseSensitivity::CaseInsensitive))
|
||||
if (!ident.starts_with_bytes("-n-"sv, CaseSensitivity::CaseInsensitive))
|
||||
return false;
|
||||
if (ident.length() == 3)
|
||||
if (ident.bytes_as_string_view().length() == 3)
|
||||
return false;
|
||||
for (size_t i = 3; i < ident.length(); ++i) {
|
||||
if (!is_ascii_digit(ident[i]))
|
||||
for (size_t i = 3; i < ident.bytes_as_string_view().length(); ++i) {
|
||||
if (!is_ascii_digit(ident.bytes_as_string_view()[i]))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -844,7 +844,7 @@ Optional<Selector::SimpleSelector::ANPlusBPattern> Parser::parse_a_n_plus_b_patt
|
|||
}
|
||||
// <dashndashdigit-ident>
|
||||
if (is_dashndashdigit_ident(first_value)) {
|
||||
auto maybe_b = first_value.token().ident().substring_view(2).to_int();
|
||||
auto maybe_b = first_value.token().ident().bytes_as_string_view().substring_view(2).to_int();
|
||||
if (maybe_b.has_value()) {
|
||||
transaction.commit();
|
||||
return Selector::SimpleSelector::ANPlusBPattern { -1, maybe_b.value() };
|
||||
|
@ -957,7 +957,7 @@ Optional<Selector::SimpleSelector::ANPlusBPattern> Parser::parse_a_n_plus_b_patt
|
|||
|
||||
// '+'?† <ndashdigit-ident>
|
||||
if (is_ndashdigit_ident(first_after_plus)) {
|
||||
auto maybe_b = first_after_plus.token().ident().substring_view(1).to_int();
|
||||
auto maybe_b = first_after_plus.token().ident().bytes_as_string_view().substring_view(1).to_int();
|
||||
if (maybe_b.has_value()) {
|
||||
transaction.commit();
|
||||
return Selector::SimpleSelector::ANPlusBPattern { 1, maybe_b.value() };
|
||||
|
|
|
@ -59,10 +59,10 @@ public:
|
|||
Type type() const { return m_type; }
|
||||
bool is(Type type) const { return m_type == type; }
|
||||
|
||||
StringView ident() const
|
||||
FlyString const& ident() const
|
||||
{
|
||||
VERIFY(m_type == Type::Ident);
|
||||
return m_value.bytes_as_string_view();
|
||||
return m_value;
|
||||
}
|
||||
|
||||
StringView function() const
|
||||
|
|
Loading…
Reference in a new issue