* modest_text_utils_get_display_date: we do a quick check whether the date
authorDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Fri, 27 Jul 2007 13:35:24 +0000 (13:35 +0000)
committerDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Fri, 27 Jul 2007 13:35:24 +0000 (13:35 +0000)
  is within the last 24h before doing the expensive extra strftime. As this
  function is called for every header in the header view, this should help
  a bit (it was showing up high in the profile before)

pmo-trunk-r2825

src/modest-text-utils.c

index 6122f69..3b497bb 100644 (file)
@@ -1023,19 +1023,29 @@ gchar*
 modest_text_utils_get_display_date (time_t date)
 {
        time_t now;
 modest_text_utils_get_display_date (time_t date)
 {
        time_t now;
-       const guint BUF_SIZE = 64; 
+       static const guint BUF_SIZE = 64; 
+       static const guint ONE_DAY = 24 * 60 * 60; /* seconds in one day */
        gchar date_buf[BUF_SIZE];  
        gchar date_buf[BUF_SIZE];  
-       gchar now_buf [BUF_SIZE];  
-       
+       gchar today_buf [BUF_SIZE];  
+
+       modest_text_utils_strftime (date_buf, BUF_SIZE, "%x", date); 
+
        now = time (NULL);
 
        now = time (NULL);
 
-       /* use the localized dates */
-       modest_text_utils_strftime (date_buf, BUF_SIZE, "%x", date); 
-       modest_text_utils_strftime (now_buf,  BUF_SIZE, "%x", now); 
-       
-       /* if this is today, get the time instead of the date */
-       if (strcmp (date_buf, now_buf) == 0)
-               modest_text_utils_strftime (date_buf, BUF_SIZE, "%X", date);
+       /* we check if the date is within the last 24h, if not, we don't
+        * have to do the extra, expensive strftime, which was very visible
+        * in the profiles.
+        */
+       if (abs(now - date) < ONE_DAY) {
+               
+               /* it's within the last 24 hours, but double check */
+               /* use the localized dates */
+               modest_text_utils_strftime (today_buf,  BUF_SIZE, "%x", now); 
+
+               /* if it's today, use the time instead */
+               if (strcmp (date_buf, today_buf) == 0)
+                       modest_text_utils_strftime (date_buf, BUF_SIZE, "%X", date);
+       }
        
        return g_strdup(date_buf);
 }
        
        return g_strdup(date_buf);
 }