Skip to content

Commit c1742fa

Browse files
committed
AK: Introduce Vector::unchecked_empend()
This does the same thing as `Vector::empend()` without attempting to grow the underlying buffer.
1 parent f675cfe commit c1742fa

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

AK/Vector.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,27 @@ requires(!IsRvalueReference<T>) class Vector {
382382
MUST(try_empend(forward<Args>(args)...));
383383
}
384384

385+
template<class... Args>
386+
ALWAYS_INLINE void unchecked_empend(Args&&... args)
387+
requires(!contains_reference)
388+
{
389+
VERIFY(m_size < capacity());
390+
if constexpr (want_fast_last_access) {
391+
++m_metadata.last_slot;
392+
++m_size;
393+
} else {
394+
++m_size;
395+
}
396+
397+
StorageType* last_slot;
398+
if constexpr (want_fast_last_access)
399+
last_slot = m_metadata.last_slot;
400+
else
401+
last_slot = slot(m_size - 1);
402+
403+
new (last_slot) StorageType(forward<Args>(args)...);
404+
}
405+
385406
template<typename U = T>
386407
void prepend(U&& value)
387408
requires(CanBePlacedInsideVector<U>)

0 commit comments

Comments
 (0)