mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:57:45 +00:00
AK: Add Vector::prepend(Vector&&).
Also included a good boy unit test.
This commit is contained in:
parent
26c29e59ec
commit
67654ec529
2 changed files with 58 additions and 0 deletions
25
AK/Vector.h
25
AK/Vector.h
|
@ -349,6 +349,31 @@ public:
|
|||
++m_size;
|
||||
}
|
||||
|
||||
void prepend(Vector&& other)
|
||||
{
|
||||
if (other.is_empty())
|
||||
return;
|
||||
|
||||
if (is_empty()) {
|
||||
*this = move(other);
|
||||
return;
|
||||
}
|
||||
|
||||
auto other_size = other.size();
|
||||
grow_capacity(size() + other_size);
|
||||
|
||||
for (int i = size() + other_size - 1; i > other.size(); --i) {
|
||||
new (slot(i)) T(move(at(i - other_size)));
|
||||
at(i - other_size).~T();
|
||||
}
|
||||
|
||||
Vector tmp = move(other);
|
||||
for (int i = 0; i < tmp.size(); ++i)
|
||||
new (slot(i)) T(move(tmp.at(i)));
|
||||
|
||||
m_size += other_size;
|
||||
}
|
||||
|
||||
void append(const T* values, int count)
|
||||
{
|
||||
if (!count)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue