[folks] eds: Re-use a GTimeZone instance for converting birthday timezones



commit 3150a055e00a9fccea4811dc672960cd1fad8e95
Author: Philip Withnall <philip tecnocode co uk>
Date:   Sat Sep 17 17:23:19 2011 +0100

    eds: Re-use a GTimeZone instance for converting birthday timezones
    
    Every time a GTimeZone is created, /etc/localtime is opened. Reduce this
    overhead by sharing a single GTimeZone instance between all Edsf.Personas
    for all time.
    
    This makes our strace a little tidier.

 backends/eds/lib/edsf-persona.vala |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)
---
diff --git a/backends/eds/lib/edsf-persona.vala b/backends/eds/lib/edsf-persona.vala
index 602b695..207f6d8 100644
--- a/backends/eds/lib/edsf-persona.vala
+++ b/backends/eds/lib/edsf-persona.vala
@@ -548,6 +548,10 @@ public class Edsf.Persona : Folks.Persona,
       set { this.change_calendar_event_id.begin (value); } /* not writeable */
     }
 
+  /* We cache the timezone we use for converting birthdays to UTC since creating
+   * it requires mmapping /etc/localtime, which means lots of syscalls. */
+  private static TimeZone _local_time_zone = new TimeZone.local ();
+
   private DateTime? _birthday = null;
   /**
    * { inheritDoc}
@@ -830,9 +834,11 @@ public class Edsf.Persona : Folks.Persona,
         {
           /* Since e-d-s stores birthdays as a plain date, we take the
            * given date in local time and convert it to UTC as mandated
-           * by the BirthdayDetails interface */
-          var d = new DateTime.local ((int) bday.year, (int) bday.month,
-              (int) bday.day, 0, 0, 0.0);
+           * by the BirthdayDetails interface.
+           * We cache the timezone since creating it requires mmapping
+           * /etc/localtime, which means lots of syscalls. */
+          var d = new DateTime (this._local_time_zone,
+              (int) bday.year, (int) bday.month, (int) bday.day, 0, 0, 0.0);
           if (this._birthday == null ||
               (this._birthday != null &&
                   !this._birthday.equal (d.to_utc ())))



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]