From 4fb2e5d8af6200cb1c5de8fb104a9b2b4eb2252a Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 27 May 2019 12:50:18 +0200 Subject: [PATCH] SharedGraphics: Make Rect::shatter() return a Vector. We know that shatter() will never return more than four rects, so we can use vector inline capacity to always avoid heap allocation here. --- SharedGraphics/Rect.cpp | 14 +++++++------- SharedGraphics/Rect.h | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/SharedGraphics/Rect.cpp b/SharedGraphics/Rect.cpp index 6013dc6343c..1f14918cd1b 100644 --- a/SharedGraphics/Rect.cpp +++ b/SharedGraphics/Rect.cpp @@ -34,11 +34,11 @@ Rect Rect::united(const Rect& other) const return rect; } -Vector Rect::shatter(const Rect& hammer) const +Vector Rect::shatter(const Rect& hammer) const { - Vector pieces; + Vector pieces; if (!intersects(hammer)) { - pieces.append(*this); + pieces.unchecked_append(*this); return pieces; } Rect top_shard { @@ -66,13 +66,13 @@ Vector Rect::shatter(const Rect& hammer) const min((hammer.y() + hammer.height()), (y() + height())) - max(hammer.y(), y()) }; if (intersects(top_shard)) - pieces.append(top_shard); + pieces.unchecked_append(top_shard); if (intersects(bottom_shard)) - pieces.append(bottom_shard); + pieces.unchecked_append(bottom_shard); if (intersects(left_shard)) - pieces.append(left_shard); + pieces.unchecked_append(left_shard); if (intersects(right_shard)) - pieces.append(right_shard); + pieces.unchecked_append(right_shard); return pieces; } diff --git a/SharedGraphics/Rect.h b/SharedGraphics/Rect.h index 05695b69969..de600a4e77b 100644 --- a/SharedGraphics/Rect.h +++ b/SharedGraphics/Rect.h @@ -177,7 +177,7 @@ public: Point location() const { return m_location; } Size size() const { return m_size; } - Vector shatter(const Rect& hammer) const; + Vector shatter(const Rect& hammer) const; operator WSAPI_Rect() const;