From ee409eba1a7b9812394df3a53bc41fb7998e28c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Mon, 20 Apr 2020 01:15:30 -0300 Subject: Change gap_start and gap_end to integer offsets --- page.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'page.c') diff --git a/page.c b/page.c index fd4ae6e..edc8bc7 100644 --- a/page.c +++ b/page.c @@ -6,24 +6,24 @@ struct page { uint8_t buffer[PAGE_SIZE]; - uint8_t *gap_start; - uint8_t *gap_end; + uint16_t gap_start; + uint16_t gap_end; struct page *next; struct page *prev; }; struct page *new_page() { struct page *result = malloc(sizeof(struct page)); - result->gap_start = result->buffer; - result->gap_end = result->buffer + PAGE_SIZE; + result->gap_start = 0; + result->gap_end = PAGE_SIZE; result->next = 0; result->prev = 0; return result; } static inline void set_half_page_gap(struct page *page) { - page->gap_start = page->buffer + PAGE_SIZE / 2; - page->gap_end = page->buffer + PAGE_SIZE; + page->gap_start = PAGE_SIZE / 2; + page->gap_end = PAGE_SIZE; } void split_page(struct page *first_half) { @@ -57,14 +57,14 @@ void free_page(struct page **page) { void move_gap(struct page *page, int target) { while(target) { if (target > 0) { - *(page->gap_start) = *(page->gap_end); + page->buffer[page->gap_start] = page->buffer[page->gap_end]; page->gap_start++; page->gap_end++; target--; } else { page->gap_end--; page->gap_start--; - *(page->gap_end) = *(page->gap_start); + page->buffer[page->gap_end] = page->buffer[page->gap_start]; target++; } } @@ -72,7 +72,7 @@ void move_gap(struct page *page, int target) { void insert_into_page(struct page *page, uint8_t c) { if (page->gap_start != page->gap_end) { - *(page->gap_start) = c; + page->buffer[page->gap_start] = c; page->gap_start++; } } -- cgit v1.2.3