mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 18:57:42 +00:00
SharedGraphics: Make Rect::shatter() return a Vector<Rect, 4>.
We know that shatter() will never return more than four rects, so we can use vector inline capacity to always avoid heap allocation here.
This commit is contained in:
parent
3873c51781
commit
4fb2e5d8af
2 changed files with 8 additions and 8 deletions
|
@ -34,11 +34,11 @@ Rect Rect::united(const Rect& other) const
|
||||||
return rect;
|
return rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector<Rect> Rect::shatter(const Rect& hammer) const
|
Vector<Rect, 4> Rect::shatter(const Rect& hammer) const
|
||||||
{
|
{
|
||||||
Vector<Rect> pieces;
|
Vector<Rect, 4> pieces;
|
||||||
if (!intersects(hammer)) {
|
if (!intersects(hammer)) {
|
||||||
pieces.append(*this);
|
pieces.unchecked_append(*this);
|
||||||
return pieces;
|
return pieces;
|
||||||
}
|
}
|
||||||
Rect top_shard {
|
Rect top_shard {
|
||||||
|
@ -66,13 +66,13 @@ Vector<Rect> Rect::shatter(const Rect& hammer) const
|
||||||
min((hammer.y() + hammer.height()), (y() + height())) - max(hammer.y(), y())
|
min((hammer.y() + hammer.height()), (y() + height())) - max(hammer.y(), y())
|
||||||
};
|
};
|
||||||
if (intersects(top_shard))
|
if (intersects(top_shard))
|
||||||
pieces.append(top_shard);
|
pieces.unchecked_append(top_shard);
|
||||||
if (intersects(bottom_shard))
|
if (intersects(bottom_shard))
|
||||||
pieces.append(bottom_shard);
|
pieces.unchecked_append(bottom_shard);
|
||||||
if (intersects(left_shard))
|
if (intersects(left_shard))
|
||||||
pieces.append(left_shard);
|
pieces.unchecked_append(left_shard);
|
||||||
if (intersects(right_shard))
|
if (intersects(right_shard))
|
||||||
pieces.append(right_shard);
|
pieces.unchecked_append(right_shard);
|
||||||
|
|
||||||
return pieces;
|
return pieces;
|
||||||
}
|
}
|
||||||
|
|
|
@ -177,7 +177,7 @@ public:
|
||||||
Point location() const { return m_location; }
|
Point location() const { return m_location; }
|
||||||
Size size() const { return m_size; }
|
Size size() const { return m_size; }
|
||||||
|
|
||||||
Vector<Rect> shatter(const Rect& hammer) const;
|
Vector<Rect, 4> shatter(const Rect& hammer) const;
|
||||||
|
|
||||||
operator WSAPI_Rect() const;
|
operator WSAPI_Rect() const;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue