| Index: Source/wtf/Deque.h
|
| diff --git a/Source/wtf/Deque.h b/Source/wtf/Deque.h
|
| index b0ab0c4260a20d6ab0759419908300b08f628d54..a838a06b17143d08762af6500186265d137b8b5b 100644
|
| --- a/Source/wtf/Deque.h
|
| +++ b/Source/wtf/Deque.h
|
| @@ -331,8 +331,20 @@ namespace WTF {
|
| size_t oldCapacity = m_buffer.capacity();
|
| T* oldBuffer = m_buffer.buffer();
|
| size_t newCapacity = std::max(static_cast<size_t>(16), oldCapacity + oldCapacity / 4 + 1);
|
| - if (m_buffer.expandBuffer(newCapacity))
|
| + if (m_buffer.expandBuffer(newCapacity)) {
|
| + if (m_start <= m_end) {
|
| + // Expanded the buffer beyond m_end; no need to move elements
|
| + // nor adjust start index, everything's in place.
|
| + return;
|
| + }
|
| + // The expanded buffer contains [0, m_end] from the "old" buffer
|
| + // already, so only have to move [m_start, oldCapacity] to the
|
| + // back of the expanded buffer.
|
| + size_t newStart = m_buffer.capacity() - (oldCapacity - m_start);
|
| + TypeOperations::moveOverlapping(oldBuffer + m_start, oldBuffer + oldCapacity, m_buffer.buffer() + newStart);
|
| + m_start = newStart;
|
| return;
|
| + }
|
| m_buffer.allocateBuffer(newCapacity);
|
| if (m_start <= m_end)
|
| TypeOperations::move(oldBuffer + m_start, oldBuffer + m_end, m_buffer.buffer() + m_start);
|
|
|