mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 12:05:15 +00:00
LibWeb: Always inline absolute Length to_px() conversion
Only do the relative Length units out of line.
This commit is contained in:
parent
5f0a1ef21b
commit
ae181e1573
Notes:
sideshowbarker
2024-07-19 05:25:00 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/ae181e15738
2 changed files with 16 additions and 6 deletions
|
@ -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:
|
||||
|
|
|
@ -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 };
|
||||
|
|
Loading…
Add table
Reference in a new issue