LibWeb: Simplify IPC encoding of style sheet DOM node IDs

We were essentially reinventing Optional::map here.
This commit is contained in:
Timothy Flynn 2025-03-12 14:33:31 -04:00 committed by Tim Flynn
parent 2ee3985fd1
commit 576eede2b1
Notes: github-actions[bot] 2025-03-13 20:57:37 +00:00

View file

@ -50,8 +50,7 @@ template<>
ErrorOr<void> encode(Encoder& encoder, Web::CSS::StyleSheetIdentifier const& style_sheet_source)
{
TRY(encoder.encode(style_sheet_source.type));
Optional<i64> dom_element_unique_id = style_sheet_source.dom_element_unique_id.has_value() ? Optional<i64>(style_sheet_source.dom_element_unique_id.value()) : Optional<i64> {};
TRY(encoder.encode(dom_element_unique_id));
TRY(encoder.encode(style_sheet_source.dom_element_unique_id.map([](auto value) { return value.value(); })));
TRY(encoder.encode(style_sheet_source.url));
return {};
@ -61,12 +60,12 @@ template<>
ErrorOr<Web::CSS::StyleSheetIdentifier> decode(Decoder& decoder)
{
auto type = TRY(decoder.decode<Web::CSS::StyleSheetIdentifier::Type>());
auto dom_element_unique_id = TRY(decoder.decode<Optional<i64>>());
auto dom_element_unique_id = TRY(decoder.decode<Optional<Web::UniqueNodeID::Type>>());
auto url = TRY(decoder.decode<Optional<String>>());
return Web::CSS::StyleSheetIdentifier {
.type = type,
.dom_element_unique_id = dom_element_unique_id.has_value() ? Web::UniqueNodeID(dom_element_unique_id.value()) : Optional<Web::UniqueNodeID> {},
.dom_element_unique_id = dom_element_unique_id.map([](auto value) -> Web::UniqueNodeID { return value; }),
.url = move(url),
};
}