1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 12:27:36 +00:00

PaintBrush: Speed up the bucket tool with smarter use of Vector.

Put together a pretty well-performing queue using a Vector and an offset.
By using the new Vector::shift_left(int) instead of Vector::take_first()
we can avoid shifting the vector contents every time and instead only
do it every so often.

Maybe this could be generalized into a separate class, I'm not sure if it's
the best algorithm though, it's just what I came up with right now. :^)
This commit is contained in:
Andreas Kling 2019-06-14 21:46:35 +02:00
parent e9c021de92
commit 9443957c14
2 changed files with 34 additions and 8 deletions

View file

@ -298,6 +298,19 @@ public:
m_capacity = new_capacity;
}
void shift_left(int count)
{
ASSERT(count <= m_size);
if (count == m_size) {
clear();
return;
}
for (int i = 0; i < m_size - count; ++i) {
at(i) = move(at(i + count));
}
m_size -= count;
}
void resize(int new_size)
{
if (new_size == size())