From b41954182ae7d7b6c3282f1cb2bdea0de0d073b2 Mon Sep 17 00:00:00 2001 From: Idan Horowitz Date: Sun, 24 Oct 2021 17:43:23 +0300 Subject: [PATCH] PixelPaint: Move Mask::{get, set, to_index} to the header file They were previously taking up 9% of samples in a profile of PixelPaint while selecting a mask, and as a result of moving them to the header they were inlined, which effectively eliminated them from the profile. --- Userland/Applications/PixelPaint/Mask.cpp | 26 ----------------------- Userland/Applications/PixelPaint/Mask.h | 25 +++++++++++++++++++--- 2 files changed, 22 insertions(+), 29 deletions(-) diff --git a/Userland/Applications/PixelPaint/Mask.cpp b/Userland/Applications/PixelPaint/Mask.cpp index 51fbcf4664..cdc25e712d 100644 --- a/Userland/Applications/PixelPaint/Mask.cpp +++ b/Userland/Applications/PixelPaint/Mask.cpp @@ -19,32 +19,6 @@ Mask::Mask(Gfx::IntRect bounding_rect, u8 default_value) } } -size_t Mask::to_index(int x, int y) const -{ - VERIFY(m_bounding_rect.contains(x, y)); - - int dx = x - m_bounding_rect.x(); - int dy = y - m_bounding_rect.y(); - return dy * m_bounding_rect.width() + dx; -} - -u8 Mask::get(int x, int y) const -{ - if (is_null() || !m_bounding_rect.contains(x, y)) { - return 0; - } - - return m_data[to_index(x, y)]; -} - -void Mask::set(int x, int y, u8 value) -{ - VERIFY(!is_null()); - VERIFY(m_bounding_rect.contains(x, y)); - - m_data[to_index(x, y)] = value; -} - Mask Mask::with_bounding_rect(Gfx::IntRect inner_rect) const { auto result = Mask::empty(inner_rect); diff --git a/Userland/Applications/PixelPaint/Mask.h b/Userland/Applications/PixelPaint/Mask.h index 1d70c26cb1..d95111c117 100644 --- a/Userland/Applications/PixelPaint/Mask.h +++ b/Userland/Applications/PixelPaint/Mask.h @@ -28,12 +28,24 @@ public: [[nodiscard]] bool is_null() const { return m_data.is_empty(); } [[nodiscard]] Gfx::IntRect bounding_rect() const { return m_bounding_rect; } - [[nodiscard]] u8 get(int x, int y) const; + [[nodiscard]] u8 get(int x, int y) const + { + if (is_null() || !m_bounding_rect.contains(x, y)) + return 0; + + return m_data[to_index(x, y)]; + } [[nodiscard]] u8 get(Gfx::IntPoint point) const { return get(point.x(), point.y()); } [[nodiscard]] float getf(int x, int y) const { return (float)get(x, y) / 255.0f; } [[nodiscard]] float getf(Gfx::IntPoint point) const { return getf(point.x(), point.y()); } - void set(int x, int y, u8); + void set(int x, int y, u8 value) + { + VERIFY(!is_null()); + VERIFY(m_bounding_rect.contains(x, y)); + + m_data[to_index(x, y)] = value; + } void set(Gfx::IntPoint point, u8 value) { set(point.x(), point.y(), value); } void setf(int x, int y, float value) { set(x, y, (u8)clamp(value * 255.0f, 0.0f, 255.0f)); } void setf(Gfx::IntPoint point, float value) { setf(point.x(), point.y(), value); } @@ -62,7 +74,14 @@ private: Mask(Gfx::IntRect, u8 default_value); - [[nodiscard]] size_t to_index(int x, int y) const; + [[nodiscard]] size_t to_index(int x, int y) const + { + VERIFY(m_bounding_rect.contains(x, y)); + + int dx = x - m_bounding_rect.x(); + int dy = y - m_bounding_rect.y(); + return dy * m_bounding_rect.width() + dx; + } template void combine(Mask const& other, Func func)