diff options
author | Juan Manuel Tomás <jtomas1815@gmail.com> | 2020-04-20 01:15:30 -0300 |
---|---|---|
committer | Juan Manuel Tomás <jtomas1815@gmail.com> | 2020-04-20 01:15:30 -0300 |
commit | ee409eba1a7b9812394df3a53bc41fb7998e28c6 (patch) | |
tree | 62cf115777888ae5879ec4e9f80db1db6ba9283a /page.c | |
parent | 7e9998311d5d5c657ea2a15091382c23ffeecd3b (diff) | |
download | jet-ee409eba1a7b9812394df3a53bc41fb7998e28c6.tar.gz jet-ee409eba1a7b9812394df3a53bc41fb7998e28c6.zip |
Change gap_start and gap_end to integer offsets
Diffstat (limited to 'page.c')
-rw-r--r-- | page.c | 18 |
1 files changed, 9 insertions, 9 deletions
@@ -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++; } } |