From e46deec84657999ee086ab46993fdd6bdd513c1a Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 2 Mar 2024 10:40:38 +0100 Subject: [PATCH] LibGfx: Inline some AffineTransform functions Asking if an AffineTransform is identity or translate-only can be done inline and avoid the cost of a function call in tight loops. --- Userland/Libraries/LibGfx/AffineTransform.cpp | 10 ---------- Userland/Libraries/LibGfx/AffineTransform.h | 11 +++++++++-- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/Userland/Libraries/LibGfx/AffineTransform.cpp b/Userland/Libraries/LibGfx/AffineTransform.cpp index 8ef5b78ea3..b32258977e 100644 --- a/Userland/Libraries/LibGfx/AffineTransform.cpp +++ b/Userland/Libraries/LibGfx/AffineTransform.cpp @@ -12,16 +12,6 @@ namespace Gfx { -bool AffineTransform::is_identity() const -{ - return m_values[0] == 1 && m_values[1] == 0 && m_values[2] == 0 && m_values[3] == 1 && m_values[4] == 0 && m_values[5] == 0; -} - -bool AffineTransform::is_identity_or_translation() const -{ - return a() == 1 && b() == 0 && c() == 0 && d() == 1; -} - float AffineTransform::x_scale() const { return AK::hypot(m_values[0], m_values[1]); diff --git a/Userland/Libraries/LibGfx/AffineTransform.h b/Userland/Libraries/LibGfx/AffineTransform.h index 693f6652b5..74a69060ea 100644 --- a/Userland/Libraries/LibGfx/AffineTransform.h +++ b/Userland/Libraries/LibGfx/AffineTransform.h @@ -25,8 +25,15 @@ public: { } - bool is_identity() const; - bool is_identity_or_translation() const; + [[nodiscard]] bool is_identity() const + { + return m_values[0] == 1 && m_values[1] == 0 && m_values[2] == 0 && m_values[3] == 1 && m_values[4] == 0 && m_values[5] == 0; + } + + [[nodiscard]] bool is_identity_or_translation() const + { + return m_values[0] == 1 && m_values[1] == 0 && m_values[2] == 0 && m_values[3] == 1; + } void map(float unmapped_x, float unmapped_y, float& mapped_x, float& mapped_y) const;