mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-05 01:55:21 +03:00
Vector: Simplify functions that take both T&& and const T&.
We can implement foo(const T&) by invoking foo(T&&) with a temporary T.
This commit is contained in:
parent
1791ebaacd
commit
57da8792fd
Notes:
sideshowbarker
2024-07-19 13:23:34 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/57da8792fd5
25
AK/Vector.h
25
AK/Vector.h
@ -240,16 +240,7 @@ public:
|
||||
|
||||
void insert(int index, const T& value)
|
||||
{
|
||||
ASSERT(index <= size());
|
||||
if (index == size())
|
||||
return append(value);
|
||||
grow_capacity(size() + 1);
|
||||
++m_size;
|
||||
for (int i = size() - 1; i > index; --i) {
|
||||
new (slot(i)) T(move(at(i - 1)));
|
||||
at(i - 1).~T();
|
||||
}
|
||||
new (slot(index)) T(value);
|
||||
insert(index, T(value));
|
||||
}
|
||||
|
||||
Vector& operator=(const Vector& other)
|
||||
@ -275,6 +266,13 @@ public:
|
||||
unchecked_append(move(v));
|
||||
}
|
||||
|
||||
void append(const Vector& other)
|
||||
{
|
||||
grow_capacity(size() + other.size());
|
||||
for (auto& value : other)
|
||||
unchecked_append(value);
|
||||
}
|
||||
|
||||
template<typename Callback>
|
||||
void remove_first_matching(Callback callback)
|
||||
{
|
||||
@ -295,8 +293,7 @@ public:
|
||||
|
||||
void unchecked_append(const T& value)
|
||||
{
|
||||
new (slot(m_size)) T(value);
|
||||
++m_size;
|
||||
unchecked_append(T(value));
|
||||
}
|
||||
|
||||
void append(T&& value)
|
||||
@ -308,9 +305,7 @@ public:
|
||||
|
||||
void append(const T& value)
|
||||
{
|
||||
grow_capacity(size() + 1);
|
||||
new (slot(m_size)) T(value);
|
||||
++m_size;
|
||||
append(T(value));
|
||||
}
|
||||
|
||||
void prepend(const T& value)
|
||||
|
Loading…
Reference in New Issue
Block a user