From 69fb6b91be751156b98010d852923df397790768 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Thu, 25 Jun 2015 16:50:21 +0300 Subject: [PATCH] (i18n_checktimelength): minor optimization. Signed-off-by: Andrew Borodin --- lib/timefmt.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/timefmt.c b/lib/timefmt.c index 9da8723b4..f86f68cf4 100644 --- a/lib/timefmt.c +++ b/lib/timefmt.c @@ -74,12 +74,15 @@ size_t i18n_checktimelength (void) { size_t length = 0; - const time_t testtime = time (NULL); - struct tm *lt = localtime (&testtime); + time_t testtime; + struct tm *lt; if (i18n_timelength_cache <= MAX_I18NTIMELENGTH) return i18n_timelength_cache; + testtime = time (NULL); + lt = localtime (&testtime); + if (lt == NULL) { /* huh, localtime() doesnt seem to work ... falling back to "(invalid)" */ @@ -88,6 +91,7 @@ i18n_checktimelength (void) else { char buf[MB_LEN_MAX * MAX_I18NTIMELENGTH + 1]; + size_t tlen; /* We are interested in the longest possible date */ lt->tm_sec = lt->tm_min = lt->tm_hour = lt->tm_mday = 10; @@ -96,12 +100,15 @@ i18n_checktimelength (void) for (lt->tm_mon = 0; lt->tm_mon < 12; lt->tm_mon++) { strftime (buf, sizeof (buf) - 1, user_recent_timeformat, lt); - length = max ((size_t) str_term_width1 (buf), length); + tlen = (size_t) str_term_width1 (buf); + length = max (tlen, length); strftime (buf, sizeof (buf) - 1, user_old_timeformat, lt); - length = max ((size_t) str_term_width1 (buf), length); + tlen = (size_t) str_term_width1 (buf); + length = max (tlen, length); } - length = max ((size_t) str_term_width1 (_(INVALID_TIME_TEXT)), length); + tlen = (size_t) str_term_width1 (_(INVALID_TIME_TEXT)); + length = max (tlen, length); } /* Don't handle big differences. Use standard value (email bug, please) */