mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-11 13:36:13 +03:00
LibWeb: Skip some redundant UTF-8 validation in CSS tokenizer
If we're just adding code points to a StringBuilder, there's no need to revalidate the result.
This commit is contained in:
parent
a88799c032
commit
8d7a1e5654
Notes:
sideshowbarker
2024-07-17 05:00:08 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/8d7a1e5654 Pull-request: https://github.com/SerenityOS/serenity/pull/23690 Reviewed-by: https://github.com/Hendiadyoin1
@ -31,6 +31,11 @@ ErrorOr<FlyString> FlyString::from_utf8(StringView string)
|
|||||||
return FlyString { TRY(String::from_utf8(string)) };
|
return FlyString { TRY(String::from_utf8(string)) };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FlyString FlyString::from_utf8_without_validation(ReadonlyBytes string)
|
||||||
|
{
|
||||||
|
return FlyString { String::from_utf8_without_validation(string) };
|
||||||
|
}
|
||||||
|
|
||||||
FlyString::FlyString(String const& string)
|
FlyString::FlyString(String const& string)
|
||||||
{
|
{
|
||||||
if (string.is_short_string()) {
|
if (string.is_short_string()) {
|
||||||
|
@ -23,6 +23,7 @@ public:
|
|||||||
FlyString() = default;
|
FlyString() = default;
|
||||||
|
|
||||||
static ErrorOr<FlyString> from_utf8(StringView);
|
static ErrorOr<FlyString> from_utf8(StringView);
|
||||||
|
static FlyString from_utf8_without_validation(ReadonlyBytes);
|
||||||
template<typename T>
|
template<typename T>
|
||||||
requires(IsOneOf<RemoveCVReference<T>, ByteString, DeprecatedFlyString, FlyString, String>)
|
requires(IsOneOf<RemoveCVReference<T>, ByteString, DeprecatedFlyString, FlyString, String>)
|
||||||
static ErrorOr<String> from_utf8(T&&) = delete;
|
static ErrorOr<String> from_utf8(T&&) = delete;
|
||||||
|
@ -161,6 +161,11 @@ String StringBuilder::to_string_without_validation() const
|
|||||||
return String::from_utf8_without_validation(string_view().bytes());
|
return String::from_utf8_without_validation(string_view().bytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FlyString StringBuilder::to_fly_string_without_validation() const
|
||||||
|
{
|
||||||
|
return FlyString::from_utf8_without_validation(string_view().bytes());
|
||||||
|
}
|
||||||
|
|
||||||
ErrorOr<FlyString> StringBuilder::to_fly_string() const
|
ErrorOr<FlyString> StringBuilder::to_fly_string() const
|
||||||
{
|
{
|
||||||
return FlyString::from_utf8(string_view());
|
return FlyString::from_utf8(string_view());
|
||||||
|
@ -75,6 +75,8 @@ public:
|
|||||||
|
|
||||||
[[nodiscard]] String to_string_without_validation() const;
|
[[nodiscard]] String to_string_without_validation() const;
|
||||||
ErrorOr<String> to_string() const;
|
ErrorOr<String> to_string() const;
|
||||||
|
|
||||||
|
[[nodiscard]] FlyString to_fly_string_without_validation() const;
|
||||||
ErrorOr<FlyString> to_fly_string() const;
|
ErrorOr<FlyString> to_fly_string() const;
|
||||||
|
|
||||||
[[nodiscard]] ErrorOr<ByteBuffer> to_byte_buffer() const;
|
[[nodiscard]] ErrorOr<ByteBuffer> to_byte_buffer() const;
|
||||||
|
@ -238,7 +238,7 @@ ErrorOr<Vector<Token>> Tokenizer::tokenize(StringView input, StringView encoding
|
|||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}));
|
}));
|
||||||
return builder.to_string();
|
return builder.to_string_without_validation();
|
||||||
};
|
};
|
||||||
|
|
||||||
Tokenizer tokenizer { TRY(filter_code_points(input, encoding)) };
|
Tokenizer tokenizer { TRY(filter_code_points(input, encoding)) };
|
||||||
@ -623,7 +623,7 @@ ErrorOr<FlyString> Tokenizer::consume_an_ident_sequence()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result.to_fly_string();
|
return result.to_fly_string_without_validation();
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://www.w3.org/TR/css-syntax-3/#consume-url-token
|
// https://www.w3.org/TR/css-syntax-3/#consume-url-token
|
||||||
|
Loading…
Reference in New Issue
Block a user