Implement a cache for the monthly view

Add a very simple cache, which is used to store the days that contain an
event or an appointment. This makes redrawing and browsing the calendar
panel much faster.

The cache has a size of 31 integers (which is equivalent to 124 bytes on
a 32 bit system and 248 bytes on a 64 bit system) and invalidates itself
if the current month has changed. If an item is added/changed/removed,
the cache needs to be invalidated manually by calling
calendar_monthly_view_cache_set_invalid(). Note that this will always
invalidate the whole cache, even if only one item at the last day of the
month was removed. This is a trade-off between simplicity and
efficiency.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
This commit is contained in:
Lukas Fleischer
2012-06-27 11:31:08 +02:00
parent 81d97315c7
commit 7a75415a61
4 changed files with 41 additions and 1 deletions

View File

@@ -358,6 +358,8 @@ void interact_day_item_edit(void)
break;
}
calendar_monthly_view_cache_set_invalid();
if (need_check_notify)
notify_check_next_app(1);
}
@@ -571,6 +573,9 @@ void interact_day_item_add(void)
if (apoint_hilt() == 0)
apoint_hilt_increase(1);
}
calendar_monthly_view_cache_set_invalid();
wins_erase_status_bar();
}
@@ -613,6 +618,8 @@ void interact_day_item_delete(unsigned *nb_events, unsigned *nb_apoints)
/* NOTREACHED */
}
calendar_monthly_view_cache_set_invalid();
if (apoint_hilt() > 1)
apoint_hilt_decrease(1);
if (apad.first_onscreen >= to_be_removed)
@@ -858,6 +865,8 @@ void interact_day_item_repeat(void)
/* NOTREACHED */
}
day_erase_item(date, item_nb, ERASE_FORCE);
calendar_monthly_view_cache_set_invalid();
}
/* Free the current cut item, if any. */
@@ -897,6 +906,8 @@ void interact_day_item_cut(unsigned *nb_events, unsigned *nb_apoints)
day_cut.type = p->type;
day_cut.item = p->item;
calendar_monthly_view_cache_set_invalid();
if (p->type == EVNT || p->type == RECUR_EVNT) {
(*nb_events)--;
to_be_removed = 1;
@@ -926,6 +937,8 @@ void interact_day_item_paste(unsigned *nb_events, unsigned *nb_apoints)
item_type = day_paste_item(&day_cut, calendar_get_slctd_day_sec());
day_cut.type = 0;
calendar_monthly_view_cache_set_invalid();
if (item_type == EVNT || item_type == RECUR_EVNT)
(*nb_events)++;
else if (item_type == APPT || item_type == RECUR_APPT)