[folks/perf2: 1/6] Cut down on the amount of owned variables




commit 453faf141607b89341b5bcca8ffaf367a9ab851c
Author: Niels De Graef <nielsdegraef gmail com>
Date:   Sat Oct 3 11:41:00 2020 +0200

    Cut down on the amount of owned variables
    
    In a lot of places in Folks, we unnecessarily create a lot of owned
    variables. Although the performance impact of a string copy or a
    refcount increment is normally completely not a concern, we also do this
    in a lot of hot code paths (e.g., for each contact that is loaded). This
    in turn mostly impacts larger address books.

 backends/eds/lib/edsf-persona-store.vala |  70 +++++++++----------
 backends/eds/lib/edsf-persona.vala       |  86 +++++++++++------------
 folks/individual-aggregator.vala         |  34 ++++-----
 folks/individual.vala                    | 116 +++++++++++++++----------------
 tools/inspect/utils.vala                 |  28 ++++----
 5 files changed, 167 insertions(+), 167 deletions(-)
---
diff --git a/backends/eds/lib/edsf-persona-store.vala b/backends/eds/lib/edsf-persona-store.vala
index 8543edec..be2fb15a 100644
--- a/backends/eds/lib/edsf-persona-store.vala
+++ b/backends/eds/lib/edsf-persona-store.vala
@@ -437,7 +437,7 @@ public class Edsf.PersonaStore : Folks.PersonaStore
           if (k == Folks.PersonaStore.detail_key (
                 PersonaDetail.FULL_NAME))
             {
-              string? full_name = v.get_string ();
+              unowned string? full_name = v.get_string ();
               if (full_name != null && (!) full_name == "")
                 {
                   full_name = null;
@@ -448,7 +448,7 @@ public class Edsf.PersonaStore : Folks.PersonaStore
           else if (k == Folks.PersonaStore.detail_key (
                 PersonaDetail.NICKNAME))
             {
-              string? nickname = v.get_string ();
+              unowned string? nickname = v.get_string ();
               if (nickname != null && (!) nickname == "")
                 {
                   nickname = null;
@@ -459,7 +459,7 @@ public class Edsf.PersonaStore : Folks.PersonaStore
           else if (k == Folks.PersonaStore.detail_key (
                 PersonaDetail.EMAIL_ADDRESSES))
             {
-              Set<EmailFieldDetails> email_addresses =
+              unowned var email_addresses =
                 (Set<EmailFieldDetails>) v.get_object ();
               this._set_contact_attributes_string (contact,
                   email_addresses,
@@ -469,7 +469,7 @@ public class Edsf.PersonaStore : Folks.PersonaStore
             {
               try
                 {
-                  var avatar = (LoadableIcon?) v.get_object ();
+                  unowned var avatar = (LoadableIcon?) v.get_object ();
                   yield this._set_contact_avatar (contact, avatar);
                 }
               catch (PropertyError e1)
@@ -481,13 +481,13 @@ public class Edsf.PersonaStore : Folks.PersonaStore
           else if (k == Folks.PersonaStore.detail_key (
                 PersonaDetail.IM_ADDRESSES))
             {
-              var im_fds = (MultiMap<string, ImFieldDetails>) v.get_object ();
+              unowned var im_fds = (MultiMap<string, ImFieldDetails>) v.get_object ();
               this._set_contact_im_fds (contact, im_fds);
             }
           else if (k == Folks.PersonaStore.detail_key (
                 PersonaDetail.PHONE_NUMBERS))
             {
-              Set<PhoneFieldDetails> phone_numbers =
+              unowned var phone_numbers =
                 (Set<PhoneFieldDetails>) v.get_object ();
               this._set_contact_attributes_string (contact,
                   phone_numbers, "TEL",
@@ -496,38 +496,37 @@ public class Edsf.PersonaStore : Folks.PersonaStore
           else if (k == Folks.PersonaStore.detail_key (
                 PersonaDetail.POSTAL_ADDRESSES))
             {
-              Set<PostalAddressFieldDetails> postal_fds =
+              unowned var postal_fds =
                 (Set<PostalAddressFieldDetails>) v.get_object ();
               this._set_contact_postal_addresses (contact, postal_fds);
             }
           else if (k == Folks.PersonaStore.detail_key (
                 PersonaDetail.STRUCTURED_NAME))
             {
-              StructuredName sname = (StructuredName) v.get_object ();
+              unowned var sname = (StructuredName) v.get_object ();
               this._set_contact_name (contact, sname);
             }
           else if (k == Folks.PersonaStore.detail_key (PersonaDetail.LOCAL_IDS))
             {
-              Set<string> local_ids = (Set<string>) v.get_object ();
+              unowned var local_ids = (Set<string>) v.get_object ();
               this._set_contact_local_ids (contact, local_ids);
             }
           else if (k == Folks.PersonaStore.detail_key (PersonaDetail.LOCATION))
             {
-              var location = (Location?) v.get_object ();
+              unowned var location = (Location?) v.get_object ();
               this._set_contact_location (contact, location);
             }
           else if (k == Folks.PersonaStore.detail_key
               (PersonaDetail.WEB_SERVICE_ADDRESSES))
             {
-              HashMultiMap<string, WebServiceFieldDetails>
-                web_service_addresses =
+              unowned var web_service_addresses =
                 (HashMultiMap<string, WebServiceFieldDetails>) v.get_object ();
               this._set_contact_web_service_addresses (contact,
                   web_service_addresses);
             }
           else if (k == Folks.PersonaStore.detail_key (PersonaDetail.NOTES))
             {
-              var notes = (Gee.Set<NoteFieldDetails>) v.get_object ();
+              unowned var notes = (Gee.Set<NoteFieldDetails>) v.get_object ();
               this._set_contact_notes (contact, notes);
             }
           else if (k == Folks.PersonaStore.detail_key (PersonaDetail.GENDER))
@@ -537,17 +536,17 @@ public class Edsf.PersonaStore : Folks.PersonaStore
             }
           else if (k == Folks.PersonaStore.detail_key (PersonaDetail.URLS))
             {
-              Set<UrlFieldDetails> urls = (Set<UrlFieldDetails>) v.get_object ();
+              unowned var urls = (Set<UrlFieldDetails>) v.get_object ();
               this._set_contact_urls (contact, urls);
             }
           else if (k == Folks.PersonaStore.detail_key (PersonaDetail.BIRTHDAY))
             {
-              var birthday = (DateTime?) v.get_boxed ();
+              unowned var birthday = (DateTime?) v.get_boxed ();
               this._set_contact_birthday (contact, birthday);
             }
           else if (k == Folks.PersonaStore.detail_key (PersonaDetail.ROLES))
             {
-              Set<RoleFieldDetails> roles =
+              unowned var roles =
                 (Set<RoleFieldDetails>) v.get_object ();
               this._set_contact_roles (contact, roles);
             }
@@ -1362,7 +1361,7 @@ public class Edsf.PersonaStore : Folks.PersonaStore
         {
           var received_notification = false;
           var has_yielded = false;
-          var signal_name = property_name ?? "contact";
+          unowned var signal_name = property_name ?? "contact";
 
           signal_id = persona.notify[signal_name].connect ((obj, pspec) =>
             {
@@ -1543,7 +1542,8 @@ public class Edsf.PersonaStore : Folks.PersonaStore
                     {
                       /* Handle TYPEs which need mapping to custom vCard attrs
                        * for EDS. */
-                      foreach (var mapping in Edsf.Persona._url_properties)
+                      foreach (unowned Edsf.Persona.UrlTypeMapping mapping
+                          in Edsf.Persona._url_properties)
                         {
                           if (param_val.down () == mapping.folks_type)
                             {
@@ -1857,7 +1857,7 @@ public class Edsf.PersonaStore : Folks.PersonaStore
               _("Full name is not writeable on this contact."));
         }
 
-      string? _full_name = full_name;
+      unowned string? _full_name = full_name;
       if (full_name == "")
         {
           _full_name = null;
@@ -1879,7 +1879,7 @@ public class Edsf.PersonaStore : Folks.PersonaStore
               _("Nickname is not writeable on this contact."));
         }
 
-      string? _nickname = nickname;
+      unowned string? _nickname = nickname;
       if (nickname == "")
         {
           _nickname = null;
@@ -1953,7 +1953,7 @@ public class Edsf.PersonaStore : Folks.PersonaStore
 
       if (_bday != null)
         {
-          var bday = (!) _bday;
+          unowned var bday = (!) _bday;
           var bdaylocal = bday.to_local();
           E.ContactDate contact_bday;
 
@@ -1987,16 +1987,16 @@ public class Edsf.PersonaStore : Folks.PersonaStore
   private void _set_contact_roles (E.Contact contact,
       Set<RoleFieldDetails> roles)
     {
-      var vcard = (E.VCard) contact;
+      unowned var vcard = (E.VCard) contact;
       vcard.remove_attributes (null, "X-ROLES");
 
-      string? org = null;
-      string? org_unit = null;
-      string? office = null;
-      string? title = null;
-      string? role = null;
-      string? manager = null;
-      string? assistant = null;
+      unowned string? org = null;
+      unowned string? org_unit = null;
+      unowned string? office = null;
+      unowned string? title = null;
+      unowned string? role = null;
+      unowned string? manager = null;
+      unowned string? assistant = null;
 
       /* Because e-d-s supports only fields for one Role we save the
        * first in the Set to the fields available and the rest goes
@@ -2096,7 +2096,7 @@ public class Edsf.PersonaStore : Folks.PersonaStore
 
       if (_sname != null)
         {
-          var sname = (!) _sname;
+          unowned var sname = (!) _sname;
 
           contact_name.family = sname.family_name;
           contact_name.given = sname.given_name;
@@ -2128,7 +2128,7 @@ public class Edsf.PersonaStore : Folks.PersonaStore
   private void _set_contact_im_fds (E.Contact contact,
       MultiMap<string, ImFieldDetails> im_fds)
     {
-      var im_eds_map = Edsf.Persona._get_im_eds_map ();
+      unowned var im_eds_map = Edsf.Persona._get_im_eds_map ();
 
       /* First let's remove everything */
       foreach (var field_id in im_eds_map.get_values ())
@@ -2223,8 +2223,8 @@ public class Edsf.PersonaStore : Folks.PersonaStore
 
   private void _set_contact_system_groups (E.Contact contact, Set<string> system_groups)
     {
-      var group_ids_str = "X-GOOGLE-SYSTEM-GROUP-IDS";
-      var vcard = (E.VCard) contact;
+      unowned var group_ids_str = "X-GOOGLE-SYSTEM-GROUP-IDS";
+      unowned var vcard = (E.VCard) contact;
       unowned E.VCardAttribute? prev_attr = vcard.get_attribute (group_ids_str);
 
       if (prev_attr != null)
@@ -2497,7 +2497,7 @@ public class Edsf.PersonaStore : Folks.PersonaStore
               continue;
             }
 
-          string iid = (!) _iid;
+          unowned string iid = (!) _iid;
           var old_persona = this._personas.get (iid);
           var new_persona = new Persona (this, c);
 
@@ -2548,7 +2548,7 @@ public class Edsf.PersonaStore : Folks.PersonaStore
               continue;
             }
 
-          string iid = (!) _iid;
+          unowned string iid = (!) _iid;
           Persona? persona = this._personas.get (iid);
           if (persona != null)
             {
diff --git a/backends/eds/lib/edsf-persona.vala b/backends/eds/lib/edsf-persona.vala
index 7c467a04..30b240a3 100644
--- a/backends/eds/lib/edsf-persona.vala
+++ b/backends/eds/lib/edsf-persona.vala
@@ -100,8 +100,8 @@ public class Edsf.Persona : Folks.Persona,
    * them. */
   private struct UrlTypeMapping
     {
-      string vcard_field_name;
-      string folks_type;
+      unowned string vcard_field_name;
+      unowned string folks_type;
     }
 
   internal const UrlTypeMapping[] _url_properties =
@@ -169,7 +169,7 @@ public class Edsf.Persona : Folks.Persona,
       null /* FIXME: https://bugzilla.gnome.org/show_bug.cgi?id=682698 */
     };
 
-  private static GLib.HashTable<string, E.ContactField>? _im_eds_map = null;
+  private static GLib.HashTable<unowned string, E.ContactField>? _im_eds_map = null;
 
   private E.Contact _contact; /* should be set on construct */
 
@@ -1214,7 +1214,7 @@ public class Edsf.Persona : Folks.Persona,
 
       if (_bday != null)
         {
-          var bday = (!) _bday;
+          unowned var bday = (!) _bday;
 
           /* 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
@@ -1274,7 +1274,7 @@ public class Edsf.Persona : Folks.Persona,
           new_roles.add ((!) default_role_fd);
         }
 
-      var vcard = (E.VCard) this.contact;
+      unowned E.VCard vcard = (E.VCard) this.contact;
       foreach (unowned E.VCardAttribute attr in vcard.get_attributes ())
         {
           if (attr.get_name () != "X-ROLES")
@@ -1395,10 +1395,10 @@ public class Edsf.Persona : Folks.Persona,
           this.contact.get_attribute ("X-FOLKS-WEB-SERVICES-IDS");
       if (services != null)
         {
-          foreach (var service in ((!) services).get_params ())
+          foreach (unowned VCardAttributeParam service in ((!) services).get_params ())
             {
               var service_name = service.get_name ().down ();
-              foreach (var service_id in service.get_values ())
+              foreach (unowned string service_id in service.get_values ())
                 {
                   if (service_id == "")
                     {
@@ -1529,13 +1529,13 @@ public class Edsf.Persona : Folks.Persona,
       var _cn = this._get_property<E.ContactName> ("name");
       if (_cn != null)
         {
-          var cn = (!) _cn;
+          unowned var cn = (!) _cn;
 
-          string family_name = cn.family;
-          string given_name  = cn.given;
-          string additional_names = cn.additional;
-          string prefixes = cn.prefixes;
-          string suffixes = cn.suffixes;
+          unowned string family_name = cn.family;
+          unowned string given_name  = cn.given;
+          unowned string additional_names = cn.additional;
+          unowned string prefixes = cn.prefixes;
+          unowned string suffixes = cn.suffixes;
           structured_name = new StructuredName (family_name, given_name,
                                                 additional_names, prefixes,
                                                 suffixes);
@@ -1560,12 +1560,12 @@ public class Edsf.Persona : Folks.Persona,
           return null;
         }
 
-      var p = (!) _p;
+      unowned var p = (!) _p;
 
       switch (p.type)
         {
           case ContactPhotoType.URI:
-            var uri = p.get_uri ();
+            unowned var uri = p.get_uri ();
             if (uri == null)
               {
                 return null;
@@ -1586,8 +1586,8 @@ public class Edsf.Persona : Folks.Persona,
 
             return new FileIcon (File.new_for_uri ((!) uri));
           case ContactPhotoType.INLINED:
-            var data = p.get_inlined ();
-            var mime_type = p.get_mime_type ();
+            unowned var data = p.get_inlined ();
+            unowned var mime_type = p.get_mime_type ();
             if (data == null || mime_type == null)
               {
                 return null;
@@ -1646,10 +1646,10 @@ public class Edsf.Persona : Folks.Persona,
           AbstractFieldDetails<string>.equal_static);
 
       /* First we get the standard Evo urls.. */
-      foreach (var mapping in Persona._url_properties)
+      foreach (unowned UrlTypeMapping mapping in Persona._url_properties)
         {
-          var url_property = mapping.vcard_field_name;
-          var folks_type = mapping.folks_type;
+          unowned var url_property = mapping.vcard_field_name;
+          unowned var folks_type = mapping.folks_type;
 
           var u = this._get_property<string> (url_property);
           if (u != null && u != "")
@@ -1661,7 +1661,7 @@ public class Edsf.Persona : Folks.Persona,
         }
 
       /* Now we go for extra URLs */
-      var vcard = (E.VCard) this.contact;
+      unowned E.VCard vcard = (E.VCard) this.contact;
       foreach (unowned E.VCardAttribute attr in vcard.get_attributes ())
         {
           if (attr.get_name () == "X-URIS")
@@ -1691,12 +1691,12 @@ public class Edsf.Persona : Folks.Persona,
 
   private void _update_im_addresses ()
     {
-      var im_eds_map = Persona._get_im_eds_map ();
+      unowned var im_eds_map = Persona._get_im_eds_map ();
       var new_im_addresses = new HashMultiMap<string, ImFieldDetails> (null,
           null, AbstractFieldDetails<string>.hash_static,
           AbstractFieldDetails<string>.equal_static);
 
-      foreach (var im_proto in im_eds_map.get_keys ())
+      foreach (unowned string im_proto in im_eds_map.get_keys ())
         {
           var addresses = this.contact.get_attributes (
               im_eds_map.lookup (im_proto));
@@ -1744,10 +1744,10 @@ public class Edsf.Persona : Folks.Persona,
        */
       foreach (var email in this._email_addresses)
         {
-          var _proto = this._im_proto_from_addr (email.value);
+          unowned var _proto = this._im_proto_from_addr (email.value);
           if (_proto != null)
             {
-              var proto = (!) _proto;
+              unowned var proto = (!) _proto;
 
               /* Has this already been added? */
               var exists = false;
@@ -1813,7 +1813,7 @@ public class Edsf.Persona : Folks.Persona,
       var new_categories = new SmallSet<string> ();
       bool any_added_categories = false;
 
-      foreach (var category_name in category_names)
+      foreach (unowned string category_name in category_names)
         {
           /* Skip the “Starred in Android” group for Google personas; we handle
            * it later. */
@@ -1858,13 +1858,13 @@ public class Edsf.Persona : Folks.Persona,
       this._groups_ro = this._groups.read_only_view;
 
       /* Check our new set of system groups if this is a Google address book. */
-      var store = (Edsf.PersonaStore) this.store;
+      unowned var store = (Edsf.PersonaStore) this.store;
       var in_google_personal_group = false;
       var should_notify_sysgroups = false;
 
       if (store._is_google_contacts_address_book ())
         {
-          var vcard = (E.VCard) this.contact;
+          unowned var vcard = (E.VCard) this.contact;
           unowned E.VCardAttribute? attr =
              vcard.get_attribute ("X-GOOGLE-SYSTEM-GROUP-IDS");
           if (attr != null)
@@ -1873,7 +1873,7 @@ public class Edsf.Persona : Folks.Persona,
               var new_sysgroups = new SmallSet<string> ();
               bool any_added_sysgroups = false;
 
-              foreach (var system_group_id in system_group_ids)
+              foreach (unowned string system_group_id in system_group_ids)
                 {
                   new_sysgroups.add (system_group_id);
 
@@ -1926,7 +1926,7 @@ public class Edsf.Persona : Folks.Persona,
         {
           this._is_favourite = false;
 
-          foreach (var category_name in category_names)
+          foreach (unowned string category_name in category_names)
             {
               /* We link the “Starred in Android” group to Google Contacts
                * address books. See: bgo#661490. */
@@ -1969,12 +1969,12 @@ public class Edsf.Persona : Folks.Persona,
   /**
    * build a table of im protocols / im protocol aliases
    */
-  internal static GLib.HashTable<string, E.ContactField> _get_im_eds_map ()
+  internal static unowned GLib.HashTable<unowned string, E.ContactField> _get_im_eds_map ()
     {
       if (Edsf.Persona._im_eds_map == null)
         {
           var table =
-              new GLib.HashTable<string, E.ContactField> (str_hash,
+              new GLib.HashTable<unowned string, E.ContactField> (str_hash,
                   str_equal);
 
           table.insert ("aim", ContactField.IM_AIM);
@@ -2046,14 +2046,14 @@ public class Edsf.Persona : Folks.Persona,
       unowned GLib.List<string>? values = attr.get_values();
       unowned GLib.List<string>? l = values;
 
-      var address_format = "";
-      var po_box = "";
-      var extension = "";
-      var street = "";
-      var locality = "";
-      var region = "";
-      var postal_code = "";
-      var country = "";
+      unowned var address_format = "";
+      unowned var po_box = "";
+      unowned var extension = "";
+      unowned var street = "";
+      unowned var locality = "";
+      unowned var region = "";
+      unowned var postal_code = "";
+      unowned var country = "";
 
       if (l != null)
         {
@@ -2162,7 +2162,7 @@ public class Edsf.Persona : Folks.Persona,
         {
           unowned GLib.List<string> ids_v = ((!) ids).get_values ();
 
-          foreach (var local_id in ids_v)
+          foreach (unowned string local_id in ids_v)
             {
               if (local_id != "")
                 {
@@ -2243,7 +2243,7 @@ public class Edsf.Persona : Folks.Persona,
     {
       var new_anti_links = new SmallSet<string> ();
 
-      var vcard = (E.VCard) this.contact;
+      unowned var vcard = (E.VCard) this.contact;
       foreach (unowned E.VCardAttribute attr in vcard.get_attributes ())
         {
           if (attr.get_name () != Edsf.PersonaStore.anti_links_attribute_name)
@@ -2292,7 +2292,7 @@ public class Edsf.Persona : Folks.Persona,
       if (tokens.length != 2)
         return null;
 
-      var domain = tokens[1];
+      unowned var domain = tokens[1];
       if (domain.index_of (".") == -1)
         return null;
 
diff --git a/folks/individual-aggregator.vala b/folks/individual-aggregator.vala
index df1f58d4..aa2fc8b9 100644
--- a/folks/individual-aggregator.vala
+++ b/folks/individual-aggregator.vala
@@ -1245,7 +1245,7 @@ public class Folks.IndividualAggregator : Object
                 {
                   for (uint i = 0; i < ((!) candidates).length; i++)
                     {
-                      var candidate_ind = ((!) candidates)[i];
+                      unowned var candidate_ind = ((!) candidates)[i];
 
                       if (candidate_ind.trust_level != TrustLevel.NONE &&
                           candidate_ind.has_anti_link_with_persona (
@@ -1425,7 +1425,7 @@ public class Folks.IndividualAggregator : Object
        * changed, so that persona might require re-linking. We do this in a
        * simplistic and hacky way (which should work) by simply treating the
        * persona as if it's been removed and re-added. */
-      var persona = (!) (obj as Persona);
+      unowned var persona = (!) (obj as Persona);
 
       debug ("Linkable property '%s' changed for persona '%s' " +
           "(is user: %s, IID: %s).", pspec.name, persona.uid,
@@ -1440,7 +1440,7 @@ public class Folks.IndividualAggregator : Object
 
   private void _persona_anti_links_changed_cb (Object obj, ParamSpec pspec)
     {
-      var persona = obj as Persona;
+      unowned var persona = obj as Persona;
 
       /* The anti-links associated with the persona has changed, so that persona
        * might require re-linking. We do this in a simplistic and hacky way
@@ -1458,7 +1458,7 @@ public class Folks.IndividualAggregator : Object
 
   private void _connect_to_persona (Persona persona)
     {
-      foreach (var prop_name in persona.linkable_properties)
+      foreach (unowned string prop_name in persona.linkable_properties)
         {
           /* FIXME: https://bugzilla.gnome.org/show_bug.cgi?id=682698 */
           if (prop_name == null)
@@ -1468,7 +1468,7 @@ public class Folks.IndividualAggregator : Object
               this._persona_linkable_property_changed_cb);
         }
 
-      var al = persona as AntiLinkable;
+      unowned var al = persona as AntiLinkable;
       if (al != null)
         {
           al.notify["anti-links"].connect (this._persona_anti_links_changed_cb);
@@ -1477,14 +1477,14 @@ public class Folks.IndividualAggregator : Object
 
   private void _disconnect_from_persona (Persona persona)
     {
-      var al = persona as AntiLinkable;
+      unowned var al = persona as AntiLinkable;
       if (al != null)
         {
           al.notify["anti-links"].disconnect (
               this._persona_anti_links_changed_cb);
         }
 
-      foreach (var prop_name in persona.linkable_properties)
+      foreach (unowned string prop_name in persona.linkable_properties)
         {
           /* FIXME: https://bugzilla.gnome.org/show_bug.cgi?id=682698 */
           if (prop_name == null)
@@ -1502,20 +1502,20 @@ public class Folks.IndividualAggregator : Object
    */
   private void _link_map_set (string key, Individual individual)
     {
-      GenericArray<Individual>? inds = this._link_map[key];
+      unowned GenericArray<Individual>? inds = this._link_map[key];
 
       if (inds == null)
         {
-          inds = new GenericArray<Individual> ();
-          this._link_map.insert (key, (!) inds);
+          var new_inds = new GenericArray<Individual> ();
+          this._link_map.insert (key, new_inds);
+          new_inds.add (individual);
+          return;
         }
-      else
+
+      for (uint i = 0; i < ((!) inds).length; i++)
         {
-          for (uint i = 0; i < ((!) inds).length; i++)
-            {
-              if (((!) inds)[i] == individual)
-                return;
-            }
+          if (((!) inds)[i] == individual)
+            return;
         }
 
       ((!) inds).add (individual);
@@ -1633,7 +1633,7 @@ public class Folks.IndividualAggregator : Object
           /* Find the Individual containing the Persona (if any) and mark them
            * for removal (any other Personas they have which aren't being
            * removed will be re-linked into other Individuals). */
-          Individual? ind = persona.individual;
+          unowned Individual? ind = persona.individual;
           if (ind != null)
             {
               removed_individuals.add ((!) ind);
diff --git a/folks/individual.vala b/folks/individual.vala
index 8738bd3f..bc63dc11 100644
--- a/folks/individual.vala
+++ b/folks/individual.vala
@@ -180,12 +180,12 @@ public class Folks.Individual : Object,
        * "avatar" property as writeable. */
       foreach (var p in this._persona_set)
         {
-          var _a = p as AvatarDetails;
+          unowned var _a = p as AvatarDetails;
           if (_a == null)
             {
               continue;
             }
-          var a = (!) _a;
+          unowned var a = (!) _a;
 
           if ("avatar" in p.writeable_properties)
             {
@@ -367,12 +367,12 @@ public class Folks.Individual : Object,
        * as a writeable property. */
       foreach (var p in this._persona_set)
         {
-          var _a = p as AliasDetails;
+          unowned var _a = p as AliasDetails;
           if (_a == null)
             {
               continue;
             }
-          var a = (!) _a;
+          unowned var a = (!) _a;
 
           if ("alias" in p.writeable_properties)
             {
@@ -476,12 +476,12 @@ public class Folks.Individual : Object,
        * as a writeable property. */
       foreach (var p in this._persona_set)
         {
-          var _n = p as NameDetails;
+          unowned var _n = p as NameDetails;
           if (_n == null)
             {
               continue;
             }
-          var n = (!) _n;
+          unowned var n = (!) _n;
 
           if ("nickname" in p.writeable_properties)
             {
@@ -727,12 +727,12 @@ public class Folks.Individual : Object,
        * is one property which is harmless to propagate. */
       foreach (var p in this._persona_set)
         {
-          var _a = p as FavouriteDetails;
+          unowned var _a = p as FavouriteDetails;
           if (_a == null)
             {
               continue;
             }
-          var a = (!) _a;
+          unowned var a = (!) _a;
 
           if ("is-favourite" in p.writeable_properties)
             {
@@ -805,12 +805,12 @@ public class Folks.Individual : Object,
        * writeable property. */
       foreach (var p in this._persona_set)
         {
-          var _g = p as GroupDetails;
+          unowned var _g = p as GroupDetails;
           if (_g == null)
             {
               continue;
             }
-          var g = (!) _g;
+          unowned var g = (!) _g;
 
           if ("groups" in p.writeable_properties)
             {
@@ -892,7 +892,7 @@ public class Folks.Individual : Object,
           /* Iterate over all personas and sum up their IM interaction counts*/
           foreach (var persona in this._persona_set)
             {
-              var my_interaction_details = persona as InteractionDetails;
+              unowned var my_interaction_details = persona as InteractionDetails;
               if (my_interaction_details != null)
                 {
                   counter = counter + my_interaction_details.im_interaction_count;
@@ -916,7 +916,7 @@ public class Folks.Individual : Object,
               /* Iterate over all personas and get the latest IM interaction datetime */
               foreach (var persona in this._persona_set)
                 {
-                  var my_interaction_details = persona as InteractionDetails;
+                  unowned var my_interaction_details = persona as InteractionDetails;
                   if (my_interaction_details != null &&
                       my_interaction_details.last_im_interaction_datetime != null)
                     {
@@ -944,7 +944,7 @@ public class Folks.Individual : Object,
           /* Iterate over all personas and sum up their call interaction counts*/
           foreach (var persona in this._persona_set)
             {
-              var my_interaction_details = persona as InteractionDetails;
+              unowned var my_interaction_details = persona as InteractionDetails;
               if (my_interaction_details != null)
                 {
                   counter = counter + my_interaction_details.call_interaction_count;
@@ -1000,7 +1000,7 @@ public class Folks.Individual : Object,
         {
           if ("extended-info" in p.writeable_properties)
             {
-              var e = p as ExtendedInfo;
+              unowned var e = p as ExtendedInfo;
               var details = e.get_extended_field (name);
               if (details != null)
                 {
@@ -1031,7 +1031,7 @@ public class Folks.Individual : Object,
         {
           if ("extended-info" in p.writeable_properties)
             {
-              var e = p as ExtendedInfo;
+              unowned var e = p as ExtendedInfo;
               try
                 {
                   yield e.change_extended_field (name, value);
@@ -1081,7 +1081,7 @@ public class Folks.Individual : Object,
         {
           if ("extended-info" in p.writeable_properties)
             {
-              var e = p as ExtendedInfo;
+              unowned var e = p as ExtendedInfo;
               try
                 {
                   yield e.remove_extended_field (name);
@@ -1353,7 +1353,7 @@ public class Folks.Individual : Object,
 
   private void _persona_notify_cb (Object obj, ParamSpec ps)
     {
-      var persona = (Persona) obj;  /* will abort on failure */
+      unowned var persona = (Persona) obj;  /* will abort on failure */
 
       /* It should not be possible for two Individuals to be simultaneously
        * connected to the same Persona (as _connect_to_persona() will disconnect
@@ -1383,7 +1383,7 @@ public class Folks.Individual : Object,
           return;
         }
 
-      foreach (var notifier in Individual._notifiers)
+      foreach (unowned _Notifier notifier in Individual._notifiers)
         {
           if (ps.name == notifier.property)
             {
@@ -1617,7 +1617,7 @@ public class Folks.Individual : Object,
           return order;
         };
 
-      Persona? candidate_p = null;
+      unowned Persona? candidate_p = null;
 
       foreach (var p in this._persona_set)
         {
@@ -1775,7 +1775,7 @@ public class Folks.Individual : Object,
         {
           if (p is GroupDetails)
             {
-              var persona = (GroupDetails) p;
+              unowned var persona = (GroupDetails) p;
 
               foreach (var group in persona.groups)
                 {
@@ -1824,8 +1824,8 @@ public class Folks.Individual : Object,
           return PresenceDetails.typecmp (a_presence, b_presence);
         }, "presence", (p) =>
         {
-          var presence_message = ""; /* must not be null */
-          var presence_status = ""; /* must not be null */
+          unowned var presence_message = ""; /* must not be null */
+          unowned var presence_status = ""; /* must not be null */
           string[] client_types = {};
           var presence_type = Folks.PresenceType.UNSET;
 
@@ -1885,9 +1885,9 @@ public class Folks.Individual : Object,
         });
     }
 
-  private string _look_up_alias_for_display_name (Persona? p)
+  private unowned string _look_up_alias_for_display_name (Persona? p)
     {
-      var a = p as AliasDetails;
+      unowned var a = p as AliasDetails;
       if (a != null && a.alias != null)
         {
           return a.alias;
@@ -1898,7 +1898,7 @@ public class Folks.Individual : Object,
 
   private string _look_up_name_details_for_display_name (Persona? p)
     {
-      var n = p as NameDetails;
+      unowned var n = p as NameDetails;
       if (n != null)
         {
           if (n.full_name != "")
@@ -1918,9 +1918,9 @@ public class Folks.Individual : Object,
       return "";
     }
 
-  private string _look_up_email_address_for_display_name (Persona? p)
+  private unowned string _look_up_email_address_for_display_name (Persona? p)
     {
-      var e = p as EmailDetails;
+      unowned var e = p as EmailDetails;
       if (e != null)
         {
           foreach (var email_fd in ((!) e).email_addresses)
@@ -1935,9 +1935,9 @@ public class Folks.Individual : Object,
       return "";
     }
 
-  private string _look_up_phone_number_for_display_name (Persona? p)
+  private unowned string _look_up_phone_number_for_display_name (Persona? p)
     {
-      var e = p as PhoneDetails;
+      unowned var e = p as PhoneDetails;
       if (e != null)
         {
           foreach (var phone_fd in ((!) e).phone_numbers)
@@ -1952,7 +1952,7 @@ public class Folks.Individual : Object,
       return "";
     }
 
-  private string _look_up_display_id_for_display_name (Persona? p)
+  private unowned string _look_up_display_id_for_display_name (Persona? p)
     {
       // Sometimes, the display_id will fall back to the IID.
       // The last condition makes sure we don't use that as a display name
@@ -1966,7 +1966,7 @@ public class Folks.Individual : Object,
 
   private string _look_up_postal_address_for_display_name (Persona? p)
     {
-      var address_details = p as PostalAddressDetails;
+      unowned var address_details = p as PostalAddressDetails;
       if (address_details != null)
         {
           foreach (var pa_fd in ((!) address_details).postal_addresses)
@@ -1984,7 +1984,7 @@ public class Folks.Individual : Object,
 
   private void _update_display_name ()
     {
-      Persona? primary_persona = null;
+      unowned Persona? primary_persona = null;
       var new_display_name = "";
 
       /* Find the primary persona first. The primary persona's values will be
@@ -2122,14 +2122,14 @@ public class Folks.Individual : Object,
     {
       this._update_single_valued_property (typeof (AliasDetails), (p) =>
         {
-          var alias = ((AliasDetails) p).alias;
+          unowned var alias = ((AliasDetails) p).alias;
           return_val_if_fail (alias != null, false);
 
           return (alias.strip () != ""); /* empty aliases are unset */
         }, (a, b) =>
         {
-          var a_alias = ((AliasDetails) a).alias;
-          var b_alias = ((AliasDetails) b).alias;
+          unowned var a_alias = ((AliasDetails) a).alias;
+          unowned var b_alias = ((AliasDetails) b).alias;
 
           return_val_if_fail (a_alias != null, 0);
           return_val_if_fail (b_alias != null, 0);
@@ -2161,8 +2161,8 @@ public class Folks.Individual : Object,
            * display ID or something else undesirable. */
           if (this._alias != alias)
             {
-              this._alias = alias;
               debug ("Setting alias ‘%s’", alias);
+              this._alias = (owned) alias;
               this.notify_property ("alias");
 
               this._update_display_name ();
@@ -2181,7 +2181,7 @@ public class Folks.Individual : Object,
           return 0;
         }, "avatar", (p) =>
         {
-          LoadableIcon? avatar = null;
+          unowned LoadableIcon? avatar = null;
 
           if (p != null)
             {
@@ -2234,7 +2234,7 @@ public class Folks.Individual : Object,
               foreach (var persona in this._persona_set)
                 {
                   /* We only care about personas implementing the given interface. */
-                  var im_details = persona as ImDetails;
+                  unowned var im_details = persona as ImDetails;
                   if (im_details != null)
                     {
                       var iter = im_details.im_addresses.map_iterator ();
@@ -2278,7 +2278,7 @@ public class Folks.Individual : Object,
               foreach (var persona in this._persona_set)
                 {
                   /* We only care about personas implementing the given interface. */
-                  var web_service_details = persona as WebServiceDetails;
+                  unowned var web_service_details = persona as WebServiceDetails;
                   if (web_service_details != null)
                     {
                       var iter = web_service_details.web_service_addresses.map_iterator ();
@@ -2329,7 +2329,7 @@ public class Folks.Individual : Object,
     {
       this._update_single_valued_property (typeof (NameDetails), (p) =>
         {
-          var name = ((NameDetails) p).structured_name;
+          unowned var name = ((NameDetails) p).structured_name;
           return (name != null && !((!) name).is_empty ());
         }, (a, b) =>
         {
@@ -2337,7 +2337,7 @@ public class Folks.Individual : Object,
           return 0;
         }, "structured-name", (p) =>
         {
-          StructuredName? name = null;
+          unowned StructuredName? name = null;
 
           if (p != null)
             {
@@ -2365,7 +2365,7 @@ public class Folks.Individual : Object,
     {
       this._update_single_valued_property (typeof (NameDetails), (p) =>
         {
-          var name = ((NameDetails) p).full_name;
+          unowned var name = ((NameDetails) p).full_name;
           return_val_if_fail (name != null, false);
 
           return (name.strip () != ""); /* empty names are unset */
@@ -2396,7 +2396,7 @@ public class Folks.Individual : Object,
     {
       this._update_single_valued_property (typeof (NameDetails), (p) =>
         {
-          var nickname = ((NameDetails) p).nickname;
+          unowned var nickname = ((NameDetails) p).nickname;
           return_val_if_fail (nickname != null, false);
 
           return (nickname.strip () != ""); /* empty names are unset */
@@ -2513,7 +2513,7 @@ public class Folks.Individual : Object,
                   /* We only care about personas implementing the given
                    * interface. If the same URL exists multiple times we merge
                    * the parameters. */
-                  var url_details = persona as UrlDetails;
+                  unowned var url_details = persona as UrlDetails;
                   if (url_details != null)
                     {
                       foreach (var url_fd in ((!) url_details).urls)
@@ -2570,7 +2570,7 @@ public class Folks.Individual : Object,
                   /* We only care about personas implementing the given
                    * interface. If the same phone number exists multiple times
                    * we merge the parameters. */
-                  var phone_details = persona as PhoneDetails;
+                  unowned var phone_details = persona as PhoneDetails;
                   if (phone_details != null)
                     {
                       foreach (var phone_fd in ((!) phone_details).phone_numbers)
@@ -2627,7 +2627,7 @@ public class Folks.Individual : Object,
                   /* We only care about personas implementing the given
                    * interface. If the same e-mail address exists multiple times
                    * we merge the parameters. */
-                  var email_details = persona as EmailDetails;
+                  unowned var email_details = persona as EmailDetails;
                   if (email_details != null)
                     {
                       foreach (var email_fd in ((!) email_details).email_addresses)
@@ -2716,7 +2716,7 @@ public class Folks.Individual : Object,
 
               foreach (var persona in this._persona_set)
                 {
-                  var local_id_details = persona as LocalIdDetails;
+                  unowned var local_id_details = persona as LocalIdDetails;
                   if (local_id_details != null)
                     {
                       foreach (var id in ((!) local_id_details).local_ids)
@@ -2786,7 +2786,7 @@ public class Folks.Individual : Object,
 
               foreach (var persona in this._persona_set)
                 {
-                  var postal_address_details = persona as PostalAddressDetails;
+                  unowned var postal_address_details = persona as PostalAddressDetails;
                   if (postal_address_details != null)
                     {
                       foreach (var pafd in
@@ -2814,14 +2814,14 @@ public class Folks.Individual : Object,
     {
       this._update_single_valued_property (typeof (BirthdayDetails), (p) =>
         {
-          var details = ((BirthdayDetails) p);
+          unowned var details = ((BirthdayDetails) p);
           return details.birthday != null && details.calendar_event_id != null;
         }, (a, b) =>
         {
-          var a_birthday = ((BirthdayDetails) a).birthday;
-          var b_birthday = ((BirthdayDetails) b).birthday;
-          var a_event_id = ((BirthdayDetails) a).calendar_event_id;
-          var b_event_id = ((BirthdayDetails) b).calendar_event_id;
+          unowned var a_birthday = ((BirthdayDetails) a).birthday;
+          unowned var b_birthday = ((BirthdayDetails) b).birthday;
+          unowned var a_event_id = ((BirthdayDetails) a).calendar_event_id;
+          unowned var b_event_id = ((BirthdayDetails) b).calendar_event_id;
 
           var a_birthday_is_set = (a_birthday != null) ? 1 : 0;
           var b_birthday_is_set = (b_birthday != null) ? 1 : 0;
@@ -2881,7 +2881,7 @@ public class Folks.Individual : Object,
 
               foreach (var persona in this._persona_set)
                 {
-                  var note_details = persona as NoteDetails;
+                  unowned var note_details = persona as NoteDetails;
                   if (note_details != null)
                     {
                       foreach (var n in ((!) note_details).notes)
@@ -3020,7 +3020,7 @@ public class Folks.Individual : Object,
        */
       if (this._persona_set.size > 0)
         {
-          Persona? chosen_persona = null;
+          unowned Persona? chosen_persona = null;
 
           foreach (var persona in this._persona_set)
             {
@@ -3030,7 +3030,7 @@ public class Folks.Individual : Object,
                   continue;
                 }
 
-              var _chosen_persona = (!) chosen_persona;
+              unowned var _chosen_persona = (!) chosen_persona;
 
               if ((_chosen_persona.store.is_primary_store == false &&
                       persona.store.is_primary_store == true) ||
@@ -3094,11 +3094,11 @@ public class Folks.Individual : Object,
    */
   public bool has_anti_link_with_persona (Persona p)
     {
-      var al = p as AntiLinkable;
+      unowned var al = p as AntiLinkable;
 
       foreach (var persona in this._persona_set)
         {
-          var pl = persona as AntiLinkable;
+          unowned var pl = persona as AntiLinkable;
 
           if ((al != null && ((!) al).has_anti_link_with_persona (persona)) ||
               (pl != null && ((!) pl).has_anti_link_with_persona (p)))
diff --git a/tools/inspect/utils.vala b/tools/inspect/utils.vala
index 55f0bc99..4bdffbd9 100644
--- a/tools/inspect/utils.vala
+++ b/tools/inspect/utils.vala
@@ -70,7 +70,7 @@ private class Folks.Inspect.Utils
       unowned string[] array = (string[]) src;
       string output = "{ ";
       bool first = true;
-      foreach (var element in array)
+      foreach (unowned string element in array)
         {
           if (first == false)
             output += ", ";
@@ -131,7 +131,7 @@ private class Folks.Inspect.Utils
       var properties = individual.get_class ().list_properties ();
 
       Utils.indent ();
-      foreach (var pspec in properties)
+      foreach (unowned ParamSpec pspec in properties)
         {
           Value prop_value;
           string output_string;
@@ -170,7 +170,7 @@ private class Folks.Inspect.Utils
       var properties = persona.get_class ().list_properties ();
 
       Utils.indent ();
-      foreach (var pspec in properties)
+      foreach (unowned ParamSpec pspec in properties)
         {
           Value prop_value;
           string output_string;
@@ -206,7 +206,7 @@ private class Folks.Inspect.Utils
       var properties = store.get_class ().list_properties ();
 
       Utils.indent ();
-      foreach (var pspec in properties)
+      foreach (unowned ParamSpec pspec in properties)
         {
           Value prop_value;
           string output_string;
@@ -248,13 +248,13 @@ private class Folks.Inspect.Utils
       /* Overrides for various known properties */
       if (object_type.is_a (typeof (Individual)) && prop_name == "personas")
         {
-          Set<Persona> personas = (Set<Persona>) prop_value.get_object ();
+          unowned var personas = (Set<Persona>) prop_value.get_object ();
           return "List of %u personas".printf (personas.size);
         }
       else if (object_type.is_a (typeof (PersonaStore)) &&
           prop_name == "personas")
         {
-          Map<string, Persona> personas =
+          unowned var personas =
               (Map<string, Persona>) prop_value.get_object ();
           return "Set of %u personas".printf (personas.size);
         }
@@ -263,7 +263,7 @@ private class Folks.Inspect.Utils
                prop_name == "supported-fields" ||
                prop_name == "anti-links")
         {
-          Set<string> groups = (Set<string>) prop_value.get_object ();
+          unowned var groups = (Set<string>) prop_value.get_object ();
           output_string = "{ ";
           bool first = true;
 
@@ -281,7 +281,7 @@ private class Folks.Inspect.Utils
       else if (prop_name == "avatar")
         {
           string ret = null;
-          LoadableIcon? avatar = (LoadableIcon) prop_value.get_object ();
+          unowned var avatar = (LoadableIcon) prop_value.get_object ();
 
           if (avatar != null &&
               avatar is FileIcon && ((FileIcon) avatar).get_file () != null)
@@ -299,7 +299,7 @@ private class Folks.Inspect.Utils
       else if (prop_name == "file")
         {
           string ret = null;
-          File? file = (File) prop_value.get_object ();
+          unowned File? file = (File) prop_value.get_object ();
 
           if (file != null)
             {
@@ -311,7 +311,7 @@ private class Folks.Inspect.Utils
       else if (prop_name == "im-addresses" ||
                prop_name == "web-service-addresses")
         {
-          var prop_list =
+          unowned var prop_list =
               (MultiMap<string, AbstractFieldDetails<string>>)
                   prop_value.get_object ();
           output_string = "{ ";
@@ -346,7 +346,7 @@ private class Folks.Inspect.Utils
         {
           output_string = "{ ";
           bool first = true;
-          var prop_list =
+          unowned var prop_list =
               (Set<AbstractFieldDetails<string>>) prop_value.get_object ();
 
           foreach (var p in prop_list)
@@ -374,7 +374,7 @@ private class Folks.Inspect.Utils
         {
           output_string = "{ ";
           bool first = true;
-          var prop_list =
+          unowned var prop_list =
               (Set<PostalAddressFieldDetails>) prop_value.get_object ();
 
           foreach (var p in prop_list)
@@ -392,7 +392,7 @@ private class Folks.Inspect.Utils
         }
       else if (prop_name == "notes")
         {
-          Set<NoteFieldDetails> notes =
+          unowned var notes =
               prop_value.get_object () as Set<NoteFieldDetails>;
 
           output_string = "{ ";
@@ -413,7 +413,7 @@ private class Folks.Inspect.Utils
         }
       else if (prop_name == "roles")
         {
-          var roles = (Set<RoleFieldDetails>) prop_value.get_object ();
+          unowned var roles = (Set<RoleFieldDetails>) prop_value.get_object ();
 
           output_string = "{ ";
           bool first = true;


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