From c6c21c2c1c811508f4cb467dcd5288af20870334 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Tue, 28 Apr 2020 14:49:57 -0300 Subject: Improve performance on very large files --- point.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'point.c') diff --git a/point.c b/point.c index 8ef0c41..82f27d2 100644 --- a/point.c +++ b/point.c @@ -14,22 +14,22 @@ uint16_t index_to_offset(struct point *point) { } } +bool same_point(struct point *a, struct point *b) { + return a->page == b->page && a->index == b->index; +} + uint8_t element(struct point *point) { if (point->index == point->page->element_count) { - return point->page->next->elements[0]; + if (!point->page->next) { + return EOF; + } else { + return point->page->next->elements[0]; + } } else { return point->page->elements[index_to_offset(point)]; } } -bool same_location(struct point *a, struct point *b) { - return a->page == b->page && a->index == b->index; -} - -bool at_eof(struct point *point) { - return point->index == point->page->element_count && !point->page->next; -} - void move_point_forward(struct point *point) { if (point->index < point->page->element_count) { point->index++; -- cgit v1.2.3