remove EOL Piece flag; use \n in memory to represent EOL

(cursor movement needs to be updated yet)
This commit is contained in:
Josh Holtrop 2016-10-15 09:42:33 -04:00
parent 85ab570ce5
commit 4ebe81c062
3 changed files with 8 additions and 26 deletions

View File

@ -38,7 +38,7 @@ bool Buffer::load_from_file(const char * filename)
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);
if (m_file_buffer == NULL)
{
@ -60,7 +60,8 @@ bool Buffer::load_from_file(const char * filename)
auto next = it;
next++;
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();

View File

@ -19,9 +19,6 @@ void PieceTable::append_initial_line_piece(uint8_t * start, uint32_t length, boo
piece->next = end_piece;
piece->start = start;
piece->length = length;
piece->flags = 0u;
if (eol)
piece->flags |= Piece::EOL_FLAG;
end_piece->prev->next = piece;
end_piece->prev = piece;
m_num_lines++;
@ -357,12 +354,10 @@ void PieceTable::begin_insert(const Cursor & cursor, bool before)
Piece * new_piece_1 = add_piece();
new_piece_1->start = piece->start;
new_piece_1->length = offset;
new_piece_1->flags = 0u;
Piece * new_piece_2 = add_piece();
new_piece_2->start = piece->start + offset;
new_piece_2->length = piece->length - offset;
new_piece_2->flags = piece->flags;
new_piece_1->prev = piece->prev;
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->start = &m_append_buffer[m_append_buffer_index];
m_inserting_piece->length = 0u;
m_inserting_piece->flags = 0u;
m_inserting_piece->prev = m_insert_before_piece;
m_inserting_piece->next = m_insert_before_piece->next;
@ -425,7 +419,6 @@ void PieceTable::insertion_test(Cursor & c)
Piece * piece = add_piece();
piece->start = &m_append_buffer[m_append_buffer_index];
piece->length = 3u;
piece->flags = 0u;
m_append_buffer[m_append_buffer_index++] = 'x';
m_append_buffer[m_append_buffer_index++] = 'y';
m_append_buffer[m_append_buffer_index++] = 'z';
@ -443,12 +436,10 @@ void PieceTable::insertion_test(Cursor & c)
Piece * piece2 = add_piece();
piece2->start = c.iterator.piece->start;
piece2->length = c.iterator.offset;
piece2->flags = 0u;
Piece * piece3 = add_piece();
piece3->start = c.iterator.piece->start + c.iterator.offset;
piece3->length = c.iterator.piece->length - c.iterator.offset;
piece3->flags = c.iterator.piece->flags;
piece2->next = piece;
piece->prev = piece2;
@ -464,7 +455,6 @@ void PieceTable::insertion_test(Cursor & c)
{
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][1] = piece;
change->links[1][1][0] = piece;

View File

@ -16,14 +16,13 @@ public:
PIECE_INDEX_START = 0,
PIECE_INDEX_END = 1,
};
enum
{
INTERNAL_EOL = '\n',
};
struct Piece
{
enum
{
EOL_FLAG = 0x80000000u,
};
/** The previous piece in the chain. */
Piece * prev;
@ -36,16 +35,8 @@ public:
/** Length of the text (in bytes). */
uint32_t length;
/**
* Flags.
*/
uint32_t flags;
/** Get whether this piece is the end of a line. */
bool eol() { return (flags & EOL_FLAG) != 0u; }
/** Toggle whether this piece is the end of a line. */
void toggle_eol() { flags ^= EOL_FLAG; }
bool eol() { return (length > 0u) && (start[length - 1u] == INTERNAL_EOL); }
};
struct Iterator