add GapBuffer::compact()
This commit is contained in:
parent
b532e80ac8
commit
18f3af443e
@ -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()
|
||||
{
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user