1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 16:47:44 +00:00

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.
This commit is contained in:
Idan Horowitz 2021-10-24 17:43:23 +03:00 committed by Andreas Kling
parent 3e592f5959
commit b41954182a
2 changed files with 22 additions and 29 deletions

View file

@ -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<typename Func>
void combine(Mask const& other, Func func)