From 575664cda39d610ed2ea279e88eecf6a4fd8fdb4 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 15 Jan 2020 19:24:25 +0100 Subject: [PATCH] AK: Add Vector::unstable_remove(index) This removes an item at an index without preserving the sort order of the Vector. This enables constant-time removal from unsorted Vectors, as it avoids shifting all of the entries following the removed one. --- AK/Vector.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/AK/Vector.h b/AK/Vector.h index 194e043053..68f134aaab 100644 --- a/AK/Vector.h +++ b/AK/Vector.h @@ -278,6 +278,13 @@ public: return value; } + void unstable_remove(int index) + { + ASSERT(index < m_size); + swap(at(index), at(m_size - 1)); + take_last(); + } + void remove(int index) { ASSERT(index < m_size);