From 7f717b841475449b244529eb9e7c21eef801e940 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Wed, 1 Mar 2023 15:06:27 -0500 Subject: [PATCH] LibWeb: Store all members of WebIDL::ExceptionOr in a single Variant This reduces the size of WebIDL::ExceptionOr as follows for a few different Ts: WebIDL::ExceptionOr: 48 bytes to 40 bytes WebIDL::ExceptionOr: 48 bytes to 40 bytes WebIDL::ExceptionOr: 56 bytes to 40 bytes --- .../Libraries/LibWeb/WebIDL/ExceptionOr.h | 32 +++++++++---------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/Userland/Libraries/LibWeb/WebIDL/ExceptionOr.h b/Userland/Libraries/LibWeb/WebIDL/ExceptionOr.h index cb0eaa52d0c..0c40327d83b 100644 --- a/Userland/Libraries/LibWeb/WebIDL/ExceptionOr.h +++ b/Userland/Libraries/LibWeb/WebIDL/ExceptionOr.h @@ -37,17 +37,17 @@ class [[nodiscard]] ExceptionOr { public: ExceptionOr() requires(IsSame) - : m_result(Empty {}) + : m_result_or_exception(Empty {}) { } ExceptionOr(ValueType const& result) - : m_result(result) + : m_result_or_exception(result) { } ExceptionOr(ValueType&& result) - : m_result(move(result)) + : m_result_or_exception(move(result)) { } @@ -57,31 +57,31 @@ public: template ExceptionOr(WrappedValueType result) requires(!IsPOD) - : m_result(move(result)) + : m_result_or_exception(ValueType { move(result) }) { } ExceptionOr(JS::NonnullGCPtr exception) - : m_exception(move(exception)) + : m_result_or_exception(exception) { } ExceptionOr(SimpleException exception) - : m_exception(move(exception)) + : m_result_or_exception(move(exception)) { } ExceptionOr(JS::Completion exception) - : m_exception(move(exception)) + : m_result_or_exception(move(exception)) { - auto const& completion = m_exception.get(); + auto const& completion = m_result_or_exception.template get(); VERIFY(completion.is_error()); } ExceptionOr(Variant, JS::Completion> exception) - : m_exception(move(exception).template downcast, JS::Completion>()) + : m_result_or_exception(move(exception)) { - if (auto* completion = m_exception.template get_pointer()) + if (auto* completion = m_result_or_exception.template get_pointer()) VERIFY(completion->is_error()); } @@ -92,22 +92,22 @@ public: ValueType& value() requires(!IsSame) { - return m_result.value(); + return m_result_or_exception.template get(); } ValueType release_value() { - return m_result.release_value(); + return move(m_result_or_exception.template get()); } Variant, JS::Completion> exception() const { - return m_exception.template downcast, JS::Completion>(); + return m_result_or_exception.template downcast, JS::Completion>(); } bool is_exception() const { - return !m_exception.template has(); + return !m_result_or_exception.template has(); } ValueType release_value_but_fixme_should_propagate_errors() @@ -121,10 +121,8 @@ public: Variant, JS::Completion> release_error() { return exception(); } private: - Optional m_result; - // https://webidl.spec.whatwg.org/#idl-exceptions - Variant, JS::Completion> m_exception {}; + Variant, JS::Completion> m_result_or_exception; }; template<>