diff options
author | Lukas Fleischer <calcurse@cryptocrack.de> | 2014-05-16 09:45:11 +0200 |
---|---|---|
committer | Lukas Fleischer <calcurse@cryptocrack.de> | 2014-05-18 11:03:16 +0200 |
commit | f513fa4627fe88f7c45bbeaa0d2842201c108a01 (patch) | |
tree | 771344d526fb4c012c706c8b417fef7a0a527933 | |
parent | 45af8c58803077801debb8534acd63b48a7938df (diff) | |
download | calcurse-f513fa4627fe88f7c45bbeaa0d2842201c108a01.tar.gz calcurse-f513fa4627fe88f7c45bbeaa0d2842201c108a01.zip |
Store appointments for the current day in a vector
This allows for more efficient access to items at specific positions.
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
-rw-r--r-- | src/calcurse.h | 2 | ||||
-rw-r--r-- | src/day.c | 36 | ||||
-rw-r--r-- | src/utils.c | 2 |
3 files changed, 21 insertions, 19 deletions
diff --git a/src/calcurse.h b/src/calcurse.h index 421a02a..54344bb 100644 --- a/src/calcurse.h +++ b/src/calcurse.h @@ -697,7 +697,7 @@ void custom_keys_config(void); void custom_config_main(void); /* day.c */ -void day_free_list(void); +void day_free_vector(void); char *day_item_get_mesg(struct day_item *); char *day_item_get_note(struct day_item *); void day_item_erase_note(struct day_item *); @@ -42,27 +42,27 @@ #include "calcurse.h" -static llist_t day_items; +static vector_t day_items; static void day_free(struct day_item *day) { mem_free(day); } -static void day_init_list(void) +static void day_init_vector(void) { - LLIST_INIT(&day_items); + VECTOR_INIT(&day_items, 16); } /* - * Free the current day linked list containing the events and appointments. + * Free the current day vector containing the events and appointments. * Must not free associated message and note, because their are not dynamically * allocated (only pointers to real objects are stored in this structure). */ -void day_free_list(void) +void day_free_vector(void) { - LLIST_FREE_INNER(&day_items, day_free); - LLIST_FREE(&day_items); + VECTOR_FREE_INNER(&day_items, day_free); + VECTOR_FREE(&day_items); } static int day_cmp_start(struct day_item *a, struct day_item *b) @@ -88,7 +88,7 @@ static void day_add_item(int type, long start, union aptev_ptr item) day->start = start; day->item = item; - LLIST_ADD_SORTED(&day_items, day, day_cmp_start); + VECTOR_ADD(&day_items, day); } /* Get the message of an item. */ @@ -341,14 +341,16 @@ day_store_items(long date, unsigned *pnb_events, unsigned *pnb_apoints, int nb_events, nb_recur_events; int nb_apoints, nb_recur_apoints; - day_free_list(); - day_init_list(); + day_free_vector(); + day_init_vector(); nb_recur_events = day_store_recur_events(date, regex); nb_events = day_store_events(date, regex); nb_recur_apoints = day_store_recur_apoints(date, regex); nb_apoints = day_store_apoints(date, regex); + VECTOR_SORT(&day_items, day_cmp_start); + if (pnb_apoints) *pnb_apoints = nb_apoints + nb_recur_apoints; if (pnb_events) @@ -470,15 +472,15 @@ display_item(struct day_item *day, int incolor, int width, int y, int x) */ void day_write_pad(long date, int width, int length, int incolor) { - llist_item_t *i; + int i; int line, item_number; const int x_pos = 0; unsigned draw_line = 0; line = item_number = 0; - LLIST_FOREACH(&day_items, i) { - struct day_item *day = LLIST_TS_GET_DATA(i); + VECTOR_FOREACH(&day_items, i) { + struct day_item *day = VECTOR_NTH(&day_items, i); /* First print the events for current day. */ if (day->type < RECUR_APPT) { @@ -509,12 +511,12 @@ void day_write_pad(long date, int width, int length, int incolor) void day_write_stdout(long date, const char *fmt_apt, const char *fmt_rapt, const char *fmt_ev, const char *fmt_rev, int *limit) { - llist_item_t *i; + int i; - LLIST_FOREACH(&day_items, i) { + VECTOR_FOREACH(&day_items, i) { if (*limit == 0) break; - struct day_item *day = LLIST_TS_GET_DATA(i); + struct day_item *day = VECTOR_NTH(&day_items, i); switch (day->type) { case APPT: @@ -727,7 +729,7 @@ int day_paste_item(struct day_item *p, long date) /* Returns a structure containing the selected item. */ struct day_item *day_get_item(int item_number) { - return LLIST_GET_DATA(LLIST_NTH(&day_items, item_number - 1)); + return VECTOR_NTH(&day_items, item_number - 1); } /* Attach a note to an appointment or event. */ diff --git a/src/utils.c b/src/utils.c index 493a180..0bcd9db 100644 --- a/src/utils.c +++ b/src/utils.c @@ -102,7 +102,7 @@ void free_user_data(void) { unsigned i; - day_free_list(); + day_free_vector(); event_llist_free(); apoint_llist_free(); recur_apoint_llist_free(); |