From b66033720adfe6700efd1c8de67672ac8b8c40ab Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 2 Mar 2024 11:17:06 +0100 Subject: [PATCH] LibWeb: Let Length::to_px(Layout::Node) be inline for absolute lengths --- Userland/Libraries/LibWeb/CSS/Length.cpp | 6 +----- Userland/Libraries/LibWeb/CSS/Length.h | 9 ++++++++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Userland/Libraries/LibWeb/CSS/Length.cpp b/Userland/Libraries/LibWeb/CSS/Length.cpp index e15918d7bc..d4752a6ac3 100644 --- a/Userland/Libraries/LibWeb/CSS/Length.cpp +++ b/Userland/Libraries/LibWeb/CSS/Length.cpp @@ -148,17 +148,13 @@ CSSPixels Length::to_px(ResolutionContext const& context) const return to_px(context.viewport_rect, context.font_metrics, context.root_font_metrics); } -CSSPixels Length::to_px(Layout::Node const& layout_node) const +CSSPixels Length::to_px_slow_case(Layout::Node const& layout_node) const { if (is_auto()) { // FIXME: We really, really shouldn't end up here, but we do, and so frequently that // adding a dbgln() here outputs a couple hundred lines loading `welcome.html`. return 0; } - - if (is_absolute()) - return absolute_length_to_px(); - if (!layout_node.document().browsing_context()) return 0; diff --git a/Userland/Libraries/LibWeb/CSS/Length.h b/Userland/Libraries/LibWeb/CSS/Length.h index 00ad4231ac..d3eeddd302 100644 --- a/Userland/Libraries/LibWeb/CSS/Length.h +++ b/Userland/Libraries/LibWeb/CSS/Length.h @@ -166,7 +166,12 @@ public: [[nodiscard]] CSSPixels to_px(ResolutionContext const&) const; - CSSPixels to_px(Layout::Node const&) const; + [[nodiscard]] ALWAYS_INLINE CSSPixels to_px(Layout::Node const& node) const + { + if (is_absolute()) + return absolute_length_to_px(); + return to_px_slow_case(node); + } ALWAYS_INLINE CSSPixels to_px(CSSPixelRect const& viewport_rect, FontMetrics const& font_metrics, FontMetrics const& root_font_metrics) const { @@ -220,6 +225,8 @@ public: private: char const* unit_name() const; + [[nodiscard]] CSSPixels to_px_slow_case(Layout::Node const&) const; + Type m_type; double m_value { 0 }; };