mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-07 21:59:54 +00:00
AK: Introduce Vector::unchecked_empend()
This does the same thing as `Vector::empend()` without attempting to grow the underlying buffer.
This commit is contained in:
parent
f675cfe90f
commit
c1742fa989
Notes:
github-actions[bot]
2025-11-26 14:35:34 +00:00
Author: https://github.com/tcl3
Commit: c1742fa989
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6938
Reviewed-by: https://github.com/alimpfard ✅
1 changed files with 21 additions and 0 deletions
21
AK/Vector.h
21
AK/Vector.h
|
|
@ -382,6 +382,27 @@ public:
|
|||
MUST(try_empend(forward<Args>(args)...));
|
||||
}
|
||||
|
||||
template<class... Args>
|
||||
ALWAYS_INLINE void unchecked_empend(Args&&... args)
|
||||
requires(!contains_reference)
|
||||
{
|
||||
VERIFY(m_size < capacity());
|
||||
if constexpr (want_fast_last_access) {
|
||||
++m_metadata.last_slot;
|
||||
++m_size;
|
||||
} else {
|
||||
++m_size;
|
||||
}
|
||||
|
||||
StorageType* last_slot;
|
||||
if constexpr (want_fast_last_access)
|
||||
last_slot = m_metadata.last_slot;
|
||||
else
|
||||
last_slot = slot(m_size - 1);
|
||||
|
||||
new (last_slot) StorageType(forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename U = T>
|
||||
void prepend(U&& value)
|
||||
requires(CanBePlacedInsideVector<U>)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue