From 500b75eea34298329a1b46292036bc59a306bc62 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Wilfried=20G=C3=B6esgens?= Date: Thu, 6 Sep 2007 21:31:49 +0000 Subject: [PATCH] * fetching the 12/24 Hours switch from config over and over is expansive. (gprof tells so) let's cache it in the session. --- webcit/calendar_tools.c | 8 ++++---- webcit/calendar_view.c | 15 ++++++++------- webcit/configure.ac | 1 - webcit/fmt_date.c | 36 +++++++++++++++++++++++++++--------- webcit/preferences.c | 29 +++++++++++++++++++++-------- webcit/webcit.h | 9 +++++++++ 6 files changed, 69 insertions(+), 29 deletions(-) diff --git a/webcit/calendar_tools.c b/webcit/calendar_tools.c index 304530f78..edb17de92 100644 --- a/webcit/calendar_tools.c +++ b/webcit/calendar_tools.c @@ -52,9 +52,9 @@ void display_icaltimetype_as_webform(struct icaltimetype *t, char *prefix) { time_t monthselect_time; struct tm monthselect_tm; char monthselect_str[32]; - char calhourformat[16]; - - get_preference("calhourformat", calhourformat, sizeof calhourformat); + int time_format; + + time_format = get_time_format_cached (); now = time(NULL); localtime_r(&now, &tm_now); @@ -116,7 +116,7 @@ void display_icaltimetype_as_webform(struct icaltimetype *t, char *prefix) { wprintf(""); wprintf(_("12 hour (am/pm)")); wprintf("   "); wprintf(""); wprintf(_("24 hour")); wprintf("\n"); @@ -270,7 +273,7 @@ void display_preferences(void) wprintf("\n"); for (i=0; i<=23; ++i) { - if (!strcasecmp(calhourformat, "24")) { + if (time_format == WC_TIMEFORMAT_24) { wprintf("\n", ((atoi(buf) == i) ? "selected" : ""), i, i @@ -401,7 +404,11 @@ void display_preferences(void) */ void set_preferences(void) { + char *fmt; char ebuf[300]; + int *time_format_cache; + + time_format_cache = &(WC->time_format_cache); if (IsEmptyStr(bstr("change_button"))) { safestrncpy(WC->ImportantMessage, @@ -416,7 +423,13 @@ void set_preferences(void) * we don't send the prefs file to the server repeatedly */ set_preference("roomlistview", bstr("roomlistview"), 0); - set_preference("calhourformat", bstr("calhourformat"), 0); + fmt = bstr("calhourformat"); + set_preference("calhourformat", fmt, 0); + if (!strcasecmp(fmt, "24")) + *time_format_cache = WC_TIMEFORMAT_24; + else + *time_format_cache = WC_TIMEFORMAT_AMPM; + set_preference("use_sig", bstr("use_sig"), 0); set_preference("daystart", bstr("daystart"), 0); set_preference("dayend", bstr("dayend"), 0); diff --git a/webcit/webcit.h b/webcit/webcit.h index 1fff20e76..4636e4f31 100644 --- a/webcit/webcit.h +++ b/webcit/webcit.h @@ -404,6 +404,7 @@ struct wcsession { int selected_language; /**< Language selected by user */ time_t last_pager_check; /**< last time we polled for instant msgs */ int nonce; /**< session nonce (to prevent session riding) */ + int time_format_cache; /**< which timeformat does our user like? */ }; /** values for WC->current_iconbar */ @@ -717,6 +718,7 @@ void end_tab(int tabnum, int num_tabs); void str_wiki_index(char *s); void display_wiki_page(void); char *bmstrcasestr(char *text, char *pattern); +int get_time_format_cached (void); #ifdef HAVE_ICONV iconv_t ctdl_iconv_open(const char *tocode, const char *fromcode); @@ -780,3 +782,10 @@ void http_datestring(char *buf, size_t n, time_t xtime); */ #define WC_EXIT_BIND 101 /* Can't bind to the port */ #define WC_EXIT_SSL 102 /* Can't initialize SSL */ + + +#define WC_TIMEFORMAT_NONE 0 +#define WC_TIMEFORMAT_AMPM 1 +#define WC_TIMEFORMAT_24 2 + + -- 2.30.2