summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan Manuel Tomás <jtomas1815@gmail.com>2020-04-21 11:30:53 -0300
committerJuan Manuel Tomás <jtomas1815@gmail.com>2020-04-21 11:30:53 -0300
commit014db29b31127490295314fee7637fbb39cc82f5 (patch)
treef9a2a770783a2b835dffcbb9a59b96ebc451c663
parentee2ab4fc801e716ae69fe0548d3477fbdd43036d (diff)
downloadjet-014db29b31127490295314fee7637fbb39cc82f5.tar.gz
jet-014db29b31127490295314fee7637fbb39cc82f5.zip
Revert page split and change element count
-rw-r--r--page.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/page.c b/page.c
index 09bf860..65d344f 100644
--- a/page.c
+++ b/page.c
@@ -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);