summaryrefslogtreecommitdiff
path: root/Libraries/LibWeb
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-06-23 23:21:58 +0200
committerAndreas Kling <kling@serenityos.org>2020-06-23 23:21:58 +0200
commitae181e15738fa65c6736578f4705d546687125e0 (patch)
treec8dc8b28ad58c08a68b9a7e4000baa1550ca4711 /Libraries/LibWeb
parent5f0a1ef21b1b0a2ab40a5e3d20b9cec924e9df80 (diff)
downloadserenity-ae181e15738fa65c6736578f4705d546687125e0.zip
LibWeb: Always inline absolute Length to_px() conversion
Only do the relative Length units out of line.
Diffstat (limited to 'Libraries/LibWeb')
-rw-r--r--Libraries/LibWeb/CSS/Length.cpp6
-rw-r--r--Libraries/LibWeb/CSS/Length.h16
2 files changed, 16 insertions, 6 deletions
diff --git a/Libraries/LibWeb/CSS/Length.cpp b/Libraries/LibWeb/CSS/Length.cpp
index 698608b836..0df4001de0 100644
--- a/Libraries/LibWeb/CSS/Length.cpp
+++ b/Libraries/LibWeb/CSS/Length.cpp
@@ -30,13 +30,9 @@
namespace Web {
-float Length::to_px(const LayoutNode& layout_node) const
+float Length::relative_length_to_px(const LayoutNode& layout_node) const
{
switch (m_type) {
- case Type::Auto:
- return 0;
- case Type::Px:
- return m_value;
case Type::Em:
return m_value * layout_node.font_size();
case Type::Rem:
diff --git a/Libraries/LibWeb/CSS/Length.h b/Libraries/LibWeb/CSS/Length.h
index c63bd15345..d290b714d7 100644
--- a/Libraries/LibWeb/CSS/Length.h
+++ b/Libraries/LibWeb/CSS/Length.h
@@ -57,7 +57,19 @@ public:
bool is_relative() const { return m_type == Type::Em || m_type == Type::Rem; }
float raw_value() const { return m_value; }
- float to_px(const LayoutNode&) const;
+ ALWAYS_INLINE float to_px(const LayoutNode& layout_node) const
+ {
+ if (is_relative())
+ return relative_length_to_px(layout_node);
+ switch (m_type) {
+ case Type::Auto:
+ return 0;
+ case Type::Px:
+ return m_value;
+ default:
+ ASSERT_NOT_REACHED();
+ }
+ }
String to_string() const
{
@@ -67,6 +79,8 @@ public:
}
private:
+ float relative_length_to_px(const LayoutNode&) const;
+
const char* unit_name() const;
Type m_type { Type::Auto };