remove EOL Piece flag; use \n in memory to represent EOL
(cursor movement needs to be updated yet)
This commit is contained in:
parent
85ab570ce5
commit
4ebe81c062
@ -38,7 +38,7 @@ bool Buffer::load_from_file(const char * filename)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_file_buffer_size = ((unsigned long)file_size + System::page_size - 1u) & System::page_base_mask;
|
m_file_buffer_size = ((unsigned long)file_size + System::page_size) & System::page_base_mask;
|
||||||
m_file_buffer = (uint8_t *)System::alloc_pages(m_file_buffer_size >> System::page_size_log);
|
m_file_buffer = (uint8_t *)System::alloc_pages(m_file_buffer_size >> System::page_size_log);
|
||||||
if (m_file_buffer == NULL)
|
if (m_file_buffer == NULL)
|
||||||
{
|
{
|
||||||
@ -60,7 +60,8 @@ bool Buffer::load_from_file(const char * filename)
|
|||||||
auto next = it;
|
auto next = it;
|
||||||
next++;
|
next++;
|
||||||
bool eol = next != text_loader.end();
|
bool eol = next != text_loader.end();
|
||||||
piece_table->append_initial_line_piece(it->start, it->length, eol);
|
it->start[it->length] = PieceTable::INTERNAL_EOL;
|
||||||
|
piece_table->append_initial_line_piece(it->start, it->length + 1u, eol);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_eol_at_eof = text_loader.get_eol_at_eof();
|
m_eol_at_eof = text_loader.get_eol_at_eof();
|
||||||
|
@ -19,9 +19,6 @@ void PieceTable::append_initial_line_piece(uint8_t * start, uint32_t length, boo
|
|||||||
piece->next = end_piece;
|
piece->next = end_piece;
|
||||||
piece->start = start;
|
piece->start = start;
|
||||||
piece->length = length;
|
piece->length = length;
|
||||||
piece->flags = 0u;
|
|
||||||
if (eol)
|
|
||||||
piece->flags |= Piece::EOL_FLAG;
|
|
||||||
end_piece->prev->next = piece;
|
end_piece->prev->next = piece;
|
||||||
end_piece->prev = piece;
|
end_piece->prev = piece;
|
||||||
m_num_lines++;
|
m_num_lines++;
|
||||||
@ -357,12 +354,10 @@ void PieceTable::begin_insert(const Cursor & cursor, bool before)
|
|||||||
Piece * new_piece_1 = add_piece();
|
Piece * new_piece_1 = add_piece();
|
||||||
new_piece_1->start = piece->start;
|
new_piece_1->start = piece->start;
|
||||||
new_piece_1->length = offset;
|
new_piece_1->length = offset;
|
||||||
new_piece_1->flags = 0u;
|
|
||||||
|
|
||||||
Piece * new_piece_2 = add_piece();
|
Piece * new_piece_2 = add_piece();
|
||||||
new_piece_2->start = piece->start + offset;
|
new_piece_2->start = piece->start + offset;
|
||||||
new_piece_2->length = piece->length - offset;
|
new_piece_2->length = piece->length - offset;
|
||||||
new_piece_2->flags = piece->flags;
|
|
||||||
|
|
||||||
new_piece_1->prev = piece->prev;
|
new_piece_1->prev = piece->prev;
|
||||||
new_piece_1->next = new_piece_2;
|
new_piece_1->next = new_piece_2;
|
||||||
@ -394,7 +389,6 @@ void PieceTable::insert_code_point(uint32_t code_point)
|
|||||||
m_inserting_piece = add_piece();
|
m_inserting_piece = add_piece();
|
||||||
m_inserting_piece->start = &m_append_buffer[m_append_buffer_index];
|
m_inserting_piece->start = &m_append_buffer[m_append_buffer_index];
|
||||||
m_inserting_piece->length = 0u;
|
m_inserting_piece->length = 0u;
|
||||||
m_inserting_piece->flags = 0u;
|
|
||||||
m_inserting_piece->prev = m_insert_before_piece;
|
m_inserting_piece->prev = m_insert_before_piece;
|
||||||
m_inserting_piece->next = m_insert_before_piece->next;
|
m_inserting_piece->next = m_insert_before_piece->next;
|
||||||
|
|
||||||
@ -425,7 +419,6 @@ void PieceTable::insertion_test(Cursor & c)
|
|||||||
Piece * piece = add_piece();
|
Piece * piece = add_piece();
|
||||||
piece->start = &m_append_buffer[m_append_buffer_index];
|
piece->start = &m_append_buffer[m_append_buffer_index];
|
||||||
piece->length = 3u;
|
piece->length = 3u;
|
||||||
piece->flags = 0u;
|
|
||||||
m_append_buffer[m_append_buffer_index++] = 'x';
|
m_append_buffer[m_append_buffer_index++] = 'x';
|
||||||
m_append_buffer[m_append_buffer_index++] = 'y';
|
m_append_buffer[m_append_buffer_index++] = 'y';
|
||||||
m_append_buffer[m_append_buffer_index++] = 'z';
|
m_append_buffer[m_append_buffer_index++] = 'z';
|
||||||
@ -443,12 +436,10 @@ void PieceTable::insertion_test(Cursor & c)
|
|||||||
Piece * piece2 = add_piece();
|
Piece * piece2 = add_piece();
|
||||||
piece2->start = c.iterator.piece->start;
|
piece2->start = c.iterator.piece->start;
|
||||||
piece2->length = c.iterator.offset;
|
piece2->length = c.iterator.offset;
|
||||||
piece2->flags = 0u;
|
|
||||||
|
|
||||||
Piece * piece3 = add_piece();
|
Piece * piece3 = add_piece();
|
||||||
piece3->start = c.iterator.piece->start + c.iterator.offset;
|
piece3->start = c.iterator.piece->start + c.iterator.offset;
|
||||||
piece3->length = c.iterator.piece->length - c.iterator.offset;
|
piece3->length = c.iterator.piece->length - c.iterator.offset;
|
||||||
piece3->flags = c.iterator.piece->flags;
|
|
||||||
|
|
||||||
piece2->next = piece;
|
piece2->next = piece;
|
||||||
piece->prev = piece2;
|
piece->prev = piece2;
|
||||||
@ -464,7 +455,6 @@ void PieceTable::insertion_test(Cursor & c)
|
|||||||
{
|
{
|
||||||
if (c.iterator.piece->length == 0u)
|
if (c.iterator.piece->length == 0u)
|
||||||
{
|
{
|
||||||
piece->flags = c.iterator.piece->flags;
|
|
||||||
change->links[1][0][0] = c.iterator.piece->prev;
|
change->links[1][0][0] = c.iterator.piece->prev;
|
||||||
change->links[1][0][1] = piece;
|
change->links[1][0][1] = piece;
|
||||||
change->links[1][1][0] = piece;
|
change->links[1][1][0] = piece;
|
||||||
|
@ -16,14 +16,13 @@ public:
|
|||||||
PIECE_INDEX_START = 0,
|
PIECE_INDEX_START = 0,
|
||||||
PIECE_INDEX_END = 1,
|
PIECE_INDEX_END = 1,
|
||||||
};
|
};
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
INTERNAL_EOL = '\n',
|
||||||
|
};
|
||||||
|
|
||||||
struct Piece
|
struct Piece
|
||||||
{
|
{
|
||||||
enum
|
|
||||||
{
|
|
||||||
EOL_FLAG = 0x80000000u,
|
|
||||||
};
|
|
||||||
|
|
||||||
/** The previous piece in the chain. */
|
/** The previous piece in the chain. */
|
||||||
Piece * prev;
|
Piece * prev;
|
||||||
|
|
||||||
@ -36,16 +35,8 @@ public:
|
|||||||
/** Length of the text (in bytes). */
|
/** Length of the text (in bytes). */
|
||||||
uint32_t length;
|
uint32_t length;
|
||||||
|
|
||||||
/**
|
|
||||||
* Flags.
|
|
||||||
*/
|
|
||||||
uint32_t flags;
|
|
||||||
|
|
||||||
/** Get whether this piece is the end of a line. */
|
/** Get whether this piece is the end of a line. */
|
||||||
bool eol() { return (flags & EOL_FLAG) != 0u; }
|
bool eol() { return (length > 0u) && (start[length - 1u] == INTERNAL_EOL); }
|
||||||
|
|
||||||
/** Toggle whether this piece is the end of a line. */
|
|
||||||
void toggle_eol() { flags ^= EOL_FLAG; }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Iterator
|
struct Iterator
|
||||||
|
Loading…
x
Reference in New Issue
Block a user