diff options
author | Juan Manuel Tomás <jtomas1815@gmail.com> | 2020-04-21 11:30:53 -0300 |
---|---|---|
committer | Juan Manuel Tomás <jtomas1815@gmail.com> | 2020-04-21 11:30:53 -0300 |
commit | 014db29b31127490295314fee7637fbb39cc82f5 (patch) | |
tree | f9a2a770783a2b835dffcbb9a59b96ebc451c663 | |
parent | ee2ab4fc801e716ae69fe0548d3477fbdd43036d (diff) | |
download | jet-014db29b31127490295314fee7637fbb39cc82f5.tar.gz jet-014db29b31127490295314fee7637fbb39cc82f5.zip |
Revert page split and change element count
-rw-r--r-- | page.c | 25 |
1 files changed, 14 insertions, 11 deletions
@@ -58,23 +58,25 @@ struct page *new_page() { return result; } -void split_page(struct page *front) { - struct page *back = new_page(); +void split_page(struct page *back) { + struct page *front = new_page(); - memcpy(back->buffer, front->buffer, PAGE_SIZE / 2); + memcpy(front->buffer, back->buffer + PAGE_SIZE / 2, PAGE_SIZE / 2); - front->gap_start = 0; - front->gap_end = PAGE_SIZE / 2; + front->gap_start = PAGE_SIZE / 2; + front->gap_end = PAGE_SIZE; + front->element_count = PAGE_SIZE / 2; back->gap_start = PAGE_SIZE / 2; back->gap_end = PAGE_SIZE; + back->element_count = PAGE_SIZE / 2; - if (front->prev) { - front->prev->next = back; + if (back->next) { + back->next->prev = front; } - back->prev = front->prev; - back->next = front; + front->next = back->next; front->prev = back; + back->next = front; } void free_page(struct page *page) { @@ -112,9 +114,10 @@ void insert_at_point(struct point *point, uint8_t c) { struct page *page = point->current_page; if (page->gap_start == page->gap_end) { split_page(page); - if (point->index < PAGE_SIZE / 2) { - page = page->prev; + if (point->index >= PAGE_SIZE / 2) { + page = page->next; point->current_page = page; + point->index -= PAGE_SIZE / 2; } } move_gap(page, point->index); |