Everywhere: Use Optional<T>::ensure() where useful

No functional changes.
This commit is contained in:
Jelle Raaijmakers 2025-09-17 15:48:22 +02:00 committed by Tim Flynn
parent 0fe9255991
commit c31eff6a47
Notes: github-actions[bot] 2025-09-17 16:02:17 +00:00
14 changed files with 53 additions and 87 deletions

View file

@ -213,9 +213,7 @@ void HTMLTextAreaElement::set_raw_value(Utf16String value)
Utf16String HTMLTextAreaElement::api_value() const
{
// The algorithm for obtaining the element's API value is to return the element's raw value, with newlines normalized.
if (!m_api_value.has_value())
m_api_value = Infra::normalize_newlines(m_raw_value);
return *m_api_value;
return m_api_value.ensure([&] { return Infra::normalize_newlines(m_raw_value); });
}
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#concept-textarea/input-relevant-value

View file

@ -21,15 +21,14 @@ bool ListOfAvailableImages::Key::operator==(Key const& other) const
u32 ListOfAvailableImages::Key::hash() const
{
if (!cached_hash.has_value()) {
return cached_hash.ensure([&] {
u32 url_hash = url.hash();
u32 mode_hash = static_cast<u32>(mode);
u32 origin_hash = 0;
if (origin.has_value())
origin_hash = Traits<URL::Origin>::hash(origin.value());
cached_hash = pair_int_hash(url_hash, pair_int_hash(mode_hash, origin_hash));
}
return cached_hash.value();
return pair_int_hash(url_hash, pair_int_hash(mode_hash, origin_hash));
});
}
void ListOfAvailableImages::visit_edges(JS::Cell::Visitor& visitor)