add GapBuffer::compact()

This commit is contained in:
Josh Holtrop 2016-11-07 22:18:56 -05:00
parent b532e80ac8
commit 18f3af443e
2 changed files with 13 additions and 1 deletions

View File

@ -1,5 +1,6 @@
#include "GapBuffer.h"
#include "System.h"
#include <string.h>
GapBuffer::GapBuffer(Encoding::Type encoding)
{
@ -33,6 +34,15 @@ std::shared_ptr<GapBuffer::Cursor> GapBuffer::add_cursor()
return cursor;
}
void GapBuffer::compact()
{
if (m_gap_position < m_size)
{
memmove(&m_buffer[m_gap_position], &m_buffer[m_gap_position + gap_size()], m_size - m_gap_position);
m_gap_position = m_size;
}
}
void GapBuffer::Iterator::go_forward()
{

View File

@ -102,9 +102,11 @@ public:
}
else
{
return &m_buffer[offset + (m_buffer_size - m_size)];
return &m_buffer[offset + gap_size()];
}
}
size_t gap_size() const { return m_buffer_size - m_size; }
void compact();
protected:
uint8_t * m_buffer;