[folks/wip/nielsdg/prevent-string-copies: 1/2] Prevent some copies by using `var` less



commit 1e9e707885cc295f83437a0be006bda342917eba
Author: Niels De Graef <nielsdegraef gmail com>
Date:   Mon Nov 25 23:13:42 2019 +0100

    Prevent some copies by using `var` less
    
    The problem with Vala's `var` keyword is that it always takes a strong
    reference, even when that is unnecessary (e.g. because you won't change
    the variable, or have reference counting in only one thread). Especially
    for certain boxed types and strings this is not really good, as they
    might trigger full copies of the data.

 backends/eds/lib/edsf-persona-store.vala |  84 +++++++++++------------
 backends/eds/lib/edsf-persona.vala       | 110 +++++++++++++++----------------
 folks/backend-store.vala                 |  10 +--
 folks/debug.vala                         |   4 +-
 folks/individual-aggregator.vala         |  34 +++++-----
 folks/individual.vala                    |  74 ++++++++++-----------
 folks/name-details.vala                  |   2 +-
 folks/postal-address-details.vala        |   2 +-
 8 files changed, 160 insertions(+), 160 deletions(-)
---
diff --git a/backends/eds/lib/edsf-persona-store.vala b/backends/eds/lib/edsf-persona-store.vala
index 4afd9d22..91377357 100644
--- a/backends/eds/lib/edsf-persona-store.vala
+++ b/backends/eds/lib/edsf-persona-store.vala
@@ -292,8 +292,8 @@ public class Edsf.PersonaStore : Folks.PersonaStore
       replacement = "Edsf.PersonaStore.with_source_registry")]
   public PersonaStore (E.Source s)
     {
-      string eds_uid = s.get_uid ();
-      string eds_name = s.get_display_name ();
+      unowned string eds_uid = s.get_uid ();
+      unowned string eds_name = s.get_display_name ();
       Object (id: eds_uid,
               display_name: eds_name,
               source: s);
@@ -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 Set<EmailFieldDetails> 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 LoadableIcon? 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 MultiMap<string, ImFieldDetails> 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 Set<PhoneFieldDetails> phone_numbers =
                 (Set<PhoneFieldDetails>) v.get_object ();
               this._set_contact_attributes_string (contact,
                   phone_numbers, "TEL",
@@ -496,30 +496,30 @@ public class Edsf.PersonaStore : Folks.PersonaStore
           else if (k == Folks.PersonaStore.detail_key (
                 PersonaDetail.POSTAL_ADDRESSES))
             {
-              Set<PostalAddressFieldDetails> postal_fds =
+              unowned Set<PostalAddressFieldDetails> 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 StructuredName 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 Set<string> 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 Location? 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>
+              unowned HashMultiMap<string, WebServiceFieldDetails>
                 web_service_addresses =
                 (HashMultiMap<string, WebServiceFieldDetails>) v.get_object ();
               this._set_contact_web_service_addresses (contact,
@@ -527,7 +527,7 @@ public class Edsf.PersonaStore : Folks.PersonaStore
             }
           else if (k == Folks.PersonaStore.detail_key (PersonaDetail.NOTES))
             {
-              var notes = (Gee.Set<NoteFieldDetails>) v.get_object ();
+              unowned Gee.Set<NoteFieldDetails> notes = (Gee.Set<NoteFieldDetails>) v.get_object ();
               this._set_contact_notes (contact, notes);
             }
           else if (k == Folks.PersonaStore.detail_key (PersonaDetail.GENDER))
@@ -542,7 +542,7 @@ public class Edsf.PersonaStore : Folks.PersonaStore
             }
           else if (k == Folks.PersonaStore.detail_key (PersonaDetail.BIRTHDAY))
             {
-              var birthday = (DateTime?) v.get_boxed ();
+              unowned DateTime? birthday = (DateTime?) v.get_boxed ();
               this._set_contact_birthday (contact, birthday);
             }
           else if (k == Folks.PersonaStore.detail_key (PersonaDetail.ROLES))
@@ -862,7 +862,7 @@ public class Edsf.PersonaStore : Folks.PersonaStore
                * here because it fails to null-terminate the array. Sigh. */
               this._always_writeable_properties = new string[prop_set.size];
               uint i = 0;
-              foreach (var final_prop in prop_set)
+              foreach (unowned string? final_prop in prop_set)
                 {
                   this._always_writeable_properties[i++] = final_prop;
                 }
@@ -1353,7 +1353,7 @@ public class Edsf.PersonaStore : Folks.PersonaStore
               persona.contact.to_string (E.VCardFormat.@30));
         }
 
-      var contact = persona.contact;
+      unowned E.Contact contact = persona.contact;
 
       ulong signal_id = 0;
       uint timeout_id = 0;
@@ -1362,7 +1362,7 @@ public class Edsf.PersonaStore : Folks.PersonaStore
         {
           var received_notification = false;
           var has_yielded = false;
-          var signal_name = property_name ?? "contact";
+          weak string signal_name = property_name ?? "contact";
 
           signal_id = persona.notify[signal_name].connect ((obj, pspec) =>
             {
@@ -1496,7 +1496,7 @@ public class Edsf.PersonaStore : Folks.PersonaStore
             {
               param.add_value (ws_fd.value);
             }
-          attr_n.add_param (param);
+          attr_n.add_param ((owned) param);
         }
       contact.add_attribute ((owned) attr_n);
     }
@@ -1519,7 +1519,7 @@ public class Edsf.PersonaStore : Folks.PersonaStore
 
   private void _set_contact_urls (E.Contact contact, Set<UrlFieldDetails> urls)
     {
-      var vcard = (E.VCard) contact;
+      unowned E.VCard vcard = (E.VCard) contact;
       vcard.remove_attributes (null, "X-URIS");
       contact.set (ContactField.HOMEPAGE_URL, null);
       contact.set (ContactField.VIDEO_URL, null);
@@ -1570,7 +1570,7 @@ public class Edsf.PersonaStore : Folks.PersonaStore
                   break;
                 }
 
-              attr.add_param (param);
+              attr.add_param ((owned) param);
             }
 
           if (set_attr_already == true)
@@ -1738,7 +1738,7 @@ public class Edsf.PersonaStore : Folks.PersonaStore
   internal async void _change_extended_field (Edsf.Persona persona,
       string name, ExtendedFieldDetails details) throws PropertyError
     {
-      var vcard = (E.VCard) persona.contact;
+      unowned E.VCard vcard = (E.VCard) persona.contact;
       unowned E.VCardAttribute? prev_attr = vcard.get_attribute (name);
 
       if (prev_attr != null)
@@ -1831,7 +1831,7 @@ public class Edsf.PersonaStore : Folks.PersonaStore
                 {
                   param.add_value (param_val);
                 }
-              attr.add_param (param);
+              attr.add_param ((owned) param);
             }
           attributes.prepend ((owned) attr);
         }
@@ -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;
@@ -1953,7 +1953,7 @@ public class Edsf.PersonaStore : Folks.PersonaStore
 
       if (_bday != null)
         {
-          var bday = (!) _bday;
+          unowned DateTime bday = (!) _bday;
           var bdaylocal = bday.to_local();
           E.ContactDate contact_bday;
 
@@ -1962,7 +1962,7 @@ public class Edsf.PersonaStore : Folks.PersonaStore
           contact_bday.month = (uint) bdaylocal.get_month ();
           contact_bday.day = (uint) bdaylocal.get_day_of_month ();
 
-          _contact_bday = contact_bday;
+          _contact_bday = (owned) contact_bday;
         }
 
       contact.set (E.Contact.field_id ("birth_date"), _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 E.VCard 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;
+      weak string? org = null;
+      weak string? org_unit = null;
+      weak string? office = null;
+      weak string? title = null;
+      weak string? role = null;
+      weak string? manager = null;
+      weak 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
@@ -2038,11 +2038,11 @@ public class Edsf.PersonaStore : Folks.PersonaStore
 
               var param1 = new E.VCardAttributeParam ("organisation_name");
               param1.add_value (role_fd.value.organisation_name);
-              attr.add_param (param1);
+              attr.add_param ((owned) param1);
 
               var param2 = new E.VCardAttributeParam ("title");
               param2.add_value (role_fd.value.title);
-              attr.add_param (param2);
+              attr.add_param ((owned) param2);
 
               foreach (var param_name in role_fd.parameters.get_keys ())
                 {
@@ -2051,7 +2051,7 @@ public class Edsf.PersonaStore : Folks.PersonaStore
                     {
                       param3.add_value (param_val);
                     }
-                  attr.add_param (param3);
+                  attr.add_param ((owned) param3);
                 }
 
               contact.add_attribute ((owned) attr);
@@ -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;
+      const string group_ids_str = "X-GOOGLE-SYSTEM-GROUP-IDS";
+      unowned E.VCard vcard = (E.VCard) contact;
       unowned E.VCardAttribute? prev_attr = vcard.get_attribute (group_ids_str);
 
       if (prev_attr != null)
@@ -2303,7 +2303,7 @@ public class Edsf.PersonaStore : Folks.PersonaStore
   private void _set_contact_anti_links (E.Contact contact,
       Set<string> anti_links)
     {
-      var vcard = (E.VCard) contact;
+      unowned E.VCard vcard = (E.VCard) contact;
       vcard.remove_attributes (null, PersonaStore.anti_links_attribute_name);
 
       var persona_uid =
@@ -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 d3bb45de..ac1a3afc 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 */
 
@@ -1005,7 +1005,7 @@ public class Edsf.Persona : Folks.Persona,
       var _contact_id =
           Edsf.Persona._get_property_from_contact<string> (contact, "id");
       assert (_contact_id != null && _contact_id != "");
-      var contact_id = (!) _contact_id;
+      unowned string contact_id = (!) _contact_id;
 
       var uid = Folks.Persona.build_uid (BACKEND_NAME, store.id, contact_id);
       var iid = Edsf.Persona.build_iid (store.id, contact_id);
@@ -1087,7 +1087,7 @@ public class Edsf.Persona : Folks.Persona,
            * otherwise this can have a different  behaviour depending
            * on the state of the current Persona depending on whether
            * this.local_ids was called before or not. */
-          foreach (var id in this.local_ids)
+          foreach (string id in this.local_ids)
             {
               callback (id);
             }
@@ -1214,7 +1214,7 @@ public class Edsf.Persona : Folks.Persona,
 
       if (_bday != null)
         {
-          var bday = (!) _bday;
+          unowned E.ContactDate 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
@@ -1341,13 +1341,13 @@ public class Edsf.Persona : Folks.Persona,
     {
       RoleFieldDetails? _default_role = null;
 
-      var org = this._get_property<string> ("org");
-      var org_unit = this._get_property<string> ("org_unit");
-      var office = this._get_property<string> ("office");
-      var title = this._get_property<string> ("title");
-      var role = this._get_property<string> ("role");
-      var manager = this._get_property<string> ("manager");
-      var assistant = this._get_property<string> ("assistant");
+      unowned string? org = this._get_property<unowned string> ("org");
+      unowned string? org_unit = this._get_property<unowned string> ("org_unit");
+      unowned string? office = this._get_property<unowned string> ("office");
+      unowned string? title = this._get_property<unowned string> ("title");
+      unowned string? role = this._get_property<unowned string> ("role");
+      unowned string? manager = this._get_property<unowned string> ("manager");
+      unowned string? assistant = this._get_property<unowned string> ("assistant");
 
       if (org != null ||
           org_unit != null ||
@@ -1394,7 +1394,7 @@ public class Edsf.Persona : Folks.Persona,
       var services = this.contact.get_attribute ("X-FOLKS-WEB-SERVICES-IDS");
       if (services != null)
         {
-          foreach (var service in ((!) services).get_params ())
+          foreach (unowned E.VCardAttributeParam service in ((!) services).get_params ())
             {
               var service_name = service.get_name ().down ();
               foreach (var service_id in service.get_values ())
@@ -1494,14 +1494,14 @@ public class Edsf.Persona : Folks.Persona,
 
   private void _update_names ()
     {
-      var _full_name = this._get_property<string> ("full_name");
+      unowned string? _full_name = this._get_property<unowned string> ("full_name");
 
       if (_full_name == null)
         {
           _full_name = "";
         }
 
-      var full_name = (!) _full_name;
+      unowned string full_name = (!) _full_name;
 
       if (this._full_name != full_name)
         {
@@ -1509,14 +1509,14 @@ public class Edsf.Persona : Folks.Persona,
           this.notify_property ("full-name");
         }
 
-      var _nickname = this._get_property<string> ("nickname");
+      unowned string? _nickname = this._get_property<unowned string> ("nickname");
 
       if (_nickname == null)
         {
           _nickname = "";
         }
 
-      var nickname = (!) _nickname;
+      unowned string nickname = (!) _nickname;
 
       if (this._nickname != nickname)
         {
@@ -1528,13 +1528,13 @@ public class Edsf.Persona : Folks.Persona,
       var _cn = this._get_property<E.ContactName> ("name");
       if (_cn != null)
         {
-          var cn = (!) _cn;
+          unowned E.ContactName 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);
@@ -1559,12 +1559,12 @@ public class Edsf.Persona : Folks.Persona,
           return null;
         }
 
-      var p = (!) _p;
+      unowned ContactPhoto p = (!) _p;
 
       switch (p.type)
         {
           case ContactPhotoType.URI:
-            var uri = p.get_uri ();
+            unowned string? uri = p.get_uri ();
             if (uri == null)
               {
                 return null;
@@ -1585,7 +1585,7 @@ public class Edsf.Persona : Folks.Persona,
 
             return new FileIcon (File.new_for_uri ((!) uri));
           case ContactPhotoType.INLINED:
-            var data = p.get_inlined ();
+            unowned uint8[]? data = p.get_inlined ();
             var mime_type = p.get_mime_type ();
             if (data == null || mime_type == null)
               {
@@ -1604,7 +1604,7 @@ public class Edsf.Persona : Folks.Persona,
       var p = this._get_property<E.ContactPhoto> ("photo");
 
       // Convert the ContactPhoto to a LoadableIcon and store or update it.
-      var new_avatar = this._contact_photo_to_loadable_icon (p);
+      LoadableIcon? new_avatar = this._contact_photo_to_loadable_icon (p);
 
       if (this._avatar != null && new_avatar == null)
         {
@@ -1645,10 +1645,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 string url_property = mapping.vcard_field_name;
+          unowned string folks_type = mapping.folks_type;
 
           var u = this._get_property<string> (url_property);
           if (u != null && u != "")
@@ -1695,7 +1695,7 @@ public class Edsf.Persona : Folks.Persona,
           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));
@@ -1743,10 +1743,10 @@ public class Edsf.Persona : Folks.Persona,
        */
       foreach (var email in this._email_addresses)
         {
-          var _proto = this._im_proto_from_addr (email.value);
+          unowned string? _proto = this._im_proto_from_addr (email.value);
           if (_proto != null)
             {
-              var proto = (!) _proto;
+              unowned string proto = (!) _proto;
 
               /* Has this already been added? */
               var exists = false;
@@ -1812,7 +1812,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. */
@@ -1836,7 +1836,7 @@ public class Edsf.Persona : Folks.Persona,
 
       if (this._groups != null)
         {
-          foreach (var category_name in this._groups)
+          foreach (unowned string category_name in this._groups)
             {
               /* Skip the “Starred in Android” group for Google personas; we handle
                * it later. */
@@ -1857,13 +1857,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 Edsf.PersonaStore 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 E.VCard vcard = (E.VCard) this.contact;
           unowned E.VCardAttribute? attr =
              vcard.get_attribute ("X-GOOGLE-SYSTEM-GROUP-IDS");
           if (attr != null)
@@ -1872,7 +1872,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);
 
@@ -1888,7 +1888,7 @@ public class Edsf.Persona : Folks.Persona,
 
               if (this._system_groups != null)
                 {
-                  foreach (var system_group_id in this._system_groups)
+                  foreach (unowned string system_group_id in this._system_groups)
                     {
                       if (!new_sysgroups.contains (system_group_id))
                         {
@@ -1925,7 +1925,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. */
@@ -1968,12 +1968,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 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);
@@ -2045,14 +2045,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 string address_format = "";
+      unowned string po_box = "";
+      unowned string extension = "";
+      unowned string street = "";
+      unowned string locality = "";
+      unowned string region = "";
+      unowned string postal_code = "";
+      unowned string country = "";
 
       if (l != null)
         {
@@ -2160,7 +2160,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 != "")
                 {
@@ -2240,7 +2240,7 @@ public class Edsf.Persona : Folks.Persona,
     {
       var new_anti_links = new SmallSet<string> ();
 
-      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 () != Edsf.PersonaStore.anti_links_attribute_name)
@@ -2279,7 +2279,7 @@ public class Edsf.Persona : Folks.Persona,
           prop_name);
     }
 
-  private string? _im_proto_from_addr (string addr)
+  private unowned string? _im_proto_from_addr (string addr)
     {
       if (addr.index_of ("@") == -1)
         return null;
@@ -2289,7 +2289,7 @@ public class Edsf.Persona : Folks.Persona,
       if (tokens.length != 2)
         return null;
 
-      var domain = tokens[1];
+      unowned string domain = tokens[1];
       if (domain.index_of (".") == -1)
         return null;
 
diff --git a/folks/backend-store.vala b/folks/backend-store.vala
index 4d2b3f5a..2a6beb8e 100644
--- a/folks/backend-store.vala
+++ b/folks/backend-store.vala
@@ -140,8 +140,8 @@ public class Folks.BackendStore : Object {
   construct
     {
       /* Treat this as a library init function */
-      var debug_no_colour = Environment.get_variable ("FOLKS_DEBUG_NO_COLOUR");
-      var debug_no_color = Environment.get_variable ("FOLKS_DEBUG_NO_COLOR");
+      unowned string? debug_no_colour = Environment.get_variable ("FOLKS_DEBUG_NO_COLOUR");
+      unowned string? debug_no_color = Environment.get_variable ("FOLKS_DEBUG_NO_COLOR");
       this._debug =
           Debug.dup_with_flags (Environment.get_variable ("G_MESSAGES_DEBUG"),
               (debug_no_colour == null || debug_no_colour == "0") &&
@@ -217,7 +217,7 @@ public class Folks.BackendStore : Object {
 
           foreach (var persona_store in backend.persona_stores.values)
             {
-              string? trust_level = null;
+              unowned string? trust_level = null;
 
               switch (persona_store.trust_level)
                 {
@@ -757,7 +757,7 @@ public class Folks.BackendStore : Object {
         {
           return;
         }
-      var file_path = (!) _file_path;
+      unowned string file_path = (!) _file_path;
 
       if (this._modules.has_key (file_path))
         return;
@@ -848,7 +848,7 @@ public class Folks.BackendStore : Object {
        * Regression tests and benchmarks can use this to restrict themselves
        * to a small set of backends for which they have done the necessary
        * setup/configuration/sandboxing. */
-      var envvar = Environment.get_variable ("FOLKS_BACKENDS_ALLOWED");
+      unowned string? envvar = Environment.get_variable ("FOLKS_BACKENDS_ALLOWED");
 
       if (envvar != null)
         {
diff --git a/folks/debug.vala b/folks/debug.vala
index 4d1bb02d..5db3164f 100644
--- a/folks/debug.vala
+++ b/folks/debug.vala
@@ -222,7 +222,7 @@ public class Folks.Debug : Object
       if (debug_flags != null && debug_flags != "")
         {
           var domains_split = ((!) debug_flags).split (",");
-          foreach (var domain in domains_split)
+          foreach (unowned string domain in domains_split)
             {
               var domain_lower = domain.down ();
 
@@ -454,7 +454,7 @@ public class Folks.Debug : Object
             {
               break;
             }
-          var key = (!) _key;
+          unowned string key = (!) _key;
 
           string? val = valist.arg ();
 
diff --git a/folks/individual-aggregator.vala b/folks/individual-aggregator.vala
index 5e5f386d..4f6a04cb 100644
--- a/folks/individual-aggregator.vala
+++ b/folks/individual-aggregator.vala
@@ -140,7 +140,7 @@ public class Folks.IndividualAggregator : Object
    * key: iid or value of some linkable property (email/IM address etc.)
    * value: owned non-empty set of owned Individual refs
    */
-  private HashTable<string, GenericArray<Individual>> _link_map;
+  private HashTable<unowned string, GenericArray<Individual>> _link_map;
 
   private bool _linking_enabled = true;
   private bool _is_prepared = false;
@@ -453,7 +453,7 @@ public class Folks.IndividualAggregator : Object
       this._stores = new HashMap<string, PersonaStore> ();
       this._individuals = new HashMap<string, Individual> ();
       this._individuals_ro = this._individuals.read_only_view;
-      this._link_map = new HashTable<string, GenericArray<Individual>> (
+      this._link_map = new HashTable<unowned string, GenericArray<Individual>> (
           str_hash, str_equal);
 
       this._backends = new SmallSet<Backend> ();
@@ -596,7 +596,7 @@ public class Folks.IndividualAggregator : Object
 
       foreach (var individual in this.individuals.values)
         {
-          string? trust_level = null;
+          unowned string? trust_level = null;
 
           switch (individual.trust_level)
             {
@@ -643,7 +643,7 @@ public class Folks.IndividualAggregator : Object
           this._link_map.size ());
       debug.indent ();
 
-      var iter = HashTableIter<string, GenericArray<Individual>> (
+      var iter = HashTableIter<unowned string, GenericArray<Individual>> (
           this._link_map);
       unowned string link_key;
       unowned GenericArray<Individual> individuals;
@@ -1295,7 +1295,7 @@ public class Folks.IndividualAggregator : Object
                         {
                           for (uint i = 0; i < ((!) candidates).length; i++)
                             {
-                              var candidate_ind = ((!) candidates)[i];
+                              unowned Individual candidate_ind = ((!) candidates)[i];
 
                               if (candidate_ind.trust_level !=
                                       TrustLevel.NONE &&
@@ -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 Persona persona = (!) (obj as Persona);
 
       debug ("Linkable property '%s' changed for persona '%s' " +
           "(is user: %s, IID: %s).", pspec.name, persona.uid,
@@ -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 AntiLinkable? 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 AntiLinkable? 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)
@@ -1580,7 +1580,7 @@ public class Folks.IndividualAggregator : Object
       debug ("Removing Individual '%s' from the link map.", individual.id);
 
       var iter =
-          HashTableIter<string, GenericArray<Individual>> (this._link_map);
+          HashTableIter<unowned string, GenericArray<Individual>> (this._link_map);
       unowned string link_key;
       unowned GenericArray<Individual> inds;
 
@@ -1791,7 +1791,7 @@ public class Folks.IndividualAggregator : Object
       if (this._debug.debug_output_enabled == true)
         {
           var link_map_iter =
-              HashTableIter<string, GenericArray<Individual>> (this._link_map);
+              HashTableIter<unowned string, GenericArray<Individual>> (this._link_map);
           unowned string link_key;
           unowned GenericArray<Individual> inds;
 
@@ -1799,7 +1799,7 @@ public class Folks.IndividualAggregator : Object
             {
               for (uint i = 0; i < inds.length; i++)
                 {
-                  var individual = inds[i];
+                  unowned Individual individual = inds[i];
                   assert (individual != null);
 
                   if (this._individuals.get (individual.id) != individual)
@@ -1832,7 +1832,7 @@ public class Folks.IndividualAggregator : Object
   private void _is_primary_store_changed_cb (Object object, ParamSpec pspec)
     {
       /* Ensure that we only have one primary PersonaStore */
-      var store = (PersonaStore) object;
+      unowned PersonaStore store = (PersonaStore) object;
       assert ((store.is_primary_store == true &&
               store == this._primary_store) ||
           (store.is_primary_store == false &&
@@ -1919,7 +1919,7 @@ public class Folks.IndividualAggregator : Object
   private void _persona_store_is_user_set_default_changed_cb (Object obj,
       ParamSpec pspec)
     {
-      var store = (PersonaStore) obj;
+      unowned PersonaStore store = (PersonaStore) obj;
 
       debug ("PersonaStore.is-user-set-default changed for store %p " +
           "(type ID: %s, ID: %s)", store, store.type_id, store.id);
@@ -2156,7 +2156,7 @@ public class Folks.IndividualAggregator : Object
        * anti-link map to ensure that linking the personas actually succeeds. */
       foreach (var p in personas)
         {
-          var al = p as AntiLinkable;
+          unowned AntiLinkable? al = p as AntiLinkable;
           if (al != null)
             {
               try
@@ -2189,7 +2189,7 @@ public class Folks.IndividualAggregator : Object
             AbstractFieldDetails<string>.equal_static);
 
       /* List of local_ids */
-      var local_ids = new SmallSet<string> ();
+      var local_ids = new SmallSet<unowned string> ();
 
       foreach (var persona in personas)
         {
diff --git a/folks/individual.vala b/folks/individual.vala
index 8738bd3f..f6fca123 100644
--- a/folks/individual.vala
+++ b/folks/individual.vala
@@ -178,7 +178,7 @@ public class Folks.Individual : Object,
 
       /* Try to write it to only the writeable Personas which have the
        * "avatar" property as writeable. */
-      foreach (var p in this._persona_set)
+      foreach (unowned Persona p in this._persona_set)
         {
           var _a = p as AvatarDetails;
           if (_a == null)
@@ -365,7 +365,7 @@ public class Folks.Individual : Object,
 
       /* Try to write it to only the writeable Personas which have "alias"
        * as a writeable property. */
-      foreach (var p in this._persona_set)
+      foreach (unowned Persona p in this._persona_set)
         {
           var _a = p as AliasDetails;
           if (_a == null)
@@ -474,7 +474,7 @@ public class Folks.Individual : Object,
 
       /* Try to write it to only the writeable Personas which have "nickname"
        * as a writeable property. */
-      foreach (var p in this._persona_set)
+      foreach (unowned Persona p in this._persona_set)
         {
           var _n = p as NameDetails;
           if (_n == null)
@@ -725,7 +725,7 @@ public class Folks.Individual : Object,
        * NOTE: We don't check whether the persona's store is writeable, as we
        * want is-favourite status to propagate to all stores, if possible. This
        * is one property which is harmless to propagate. */
-      foreach (var p in this._persona_set)
+      foreach (unowned Persona p in this._persona_set)
         {
           var _a = p as FavouriteDetails;
           if (_a == null)
@@ -803,7 +803,7 @@ public class Folks.Individual : Object,
 
       /* Try to write it to only the Personas which have "groups" as a
        * writeable property. */
-      foreach (var p in this._persona_set)
+      foreach (unowned Persona p in this._persona_set)
         {
           var _g = p as GroupDetails;
           if (_g == null)
@@ -996,7 +996,7 @@ public class Folks.Individual : Object,
 
       /* Try to get it from the writeable Personas which have "extended-info"
        * as a writeable property. */
-      foreach (var p in this._persona_set)
+      foreach (unowned Persona p in this._persona_set)
         {
           if ("extended-info" in p.writeable_properties)
             {
@@ -1027,7 +1027,7 @@ public class Folks.Individual : Object,
 
       /* Try to write it to only the writeable Personas which have "extended-info"
        * as a writeable property. */
-      foreach (var p in this._persona_set)
+      foreach (unowned Persona p in this._persona_set)
         {
           if ("extended-info" in p.writeable_properties)
             {
@@ -1077,7 +1077,7 @@ public class Folks.Individual : Object,
       PropertyError? persona_error = null;
 
       /* Try to remove it from all writeable Personas. */
-      foreach (var p in this._persona_set)
+      foreach (unowned Persona p in this._persona_set)
         {
           if ("extended-info" in p.writeable_properties)
             {
@@ -1239,7 +1239,7 @@ public class Folks.Individual : Object,
    */
   public async void change_group (string group, bool is_member)
     {
-      foreach (var p in this._persona_set)
+      foreach (unowned Persona p in this._persona_set)
         {
           if (p is GroupDetails)
             ((GroupDetails) p).change_group.begin (group, is_member);
@@ -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 Persona 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)
             {
@@ -1619,7 +1619,7 @@ public class Folks.Individual : Object,
 
       Persona? candidate_p = null;
 
-      foreach (var p in this._persona_set)
+      foreach (unowned Persona p in this._persona_set)
         {
           /* We only care about personas implementing the given interface. */
           if (p.get_type ().is_a (interface_type))
@@ -1764,14 +1764,14 @@ public class Folks.Individual : Object,
       if (!created && !force_update)
          return;
 
-      var new_groups = new SmallSet<string> ();
+      var new_groups = new SmallSet<unowned string> ();
 
       /* FIXME: this should partition the personas by store (maybe we should
        * keep that mapping in general in this class), and execute
        * "groups-changed" on the store (with the set of personas), to allow the
        * back-end to optimize it (like Telepathy will for MembersChanged for the
        * groups channel list) */
-      foreach (var p in this._persona_set)
+      foreach (unowned Persona p in this._persona_set)
         {
           if (p is GroupDetails)
             {
@@ -1784,7 +1784,7 @@ public class Folks.Individual : Object,
             }
         }
 
-      foreach (var group in new_groups)
+      foreach (unowned string group in new_groups)
         {
           if (this._groups.add (group) && emit_notification)
             {
@@ -1793,8 +1793,8 @@ public class Folks.Individual : Object,
         }
 
       /* buffer the removals, so we don't remove while iterating */
-      var removes = new GLib.List<string> ();
-      foreach (var group in this._groups)
+      var removes = new GLib.List<unowned string> ();
+      foreach (unowned string group in this._groups)
         {
           if (!new_groups.contains (group))
             removes.prepend (group);
@@ -1802,7 +1802,7 @@ public class Folks.Individual : Object,
 
       removes.foreach ((l) =>
         {
-          unowned string group = (string) l;
+          unowned string group = l;
           this._groups.remove (group);
           if (emit_notification)
             {
@@ -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 string presence_message = ""; /* must not be null */
+          unowned string presence_status = ""; /* must not be null */
           string[] client_types = {};
           var presence_type = Folks.PresenceType.UNSET;
 
@@ -1885,7 +1885,7 @@ 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;
       if (a != null && a.alias != null)
@@ -1918,7 +1918,7 @@ 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;
       if (e != null)
@@ -1935,7 +1935,7 @@ 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;
       if (e != null)
@@ -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
@@ -1989,7 +1989,7 @@ public class Folks.Individual : Object,
 
       /* Find the primary persona first. The primary persona's values will be
        * preferred in every case where they're set. */
-      foreach (var p in this._persona_set)
+      foreach (unowned Persona p in this._persona_set)
         {
           if (p.store.is_primary_store)
             {
@@ -2001,7 +2001,7 @@ public class Folks.Individual : Object,
       /* See if any persona has an alias set. */
       new_display_name = this._look_up_alias_for_display_name (primary_persona);
 
-      foreach (var p in this._persona_set)
+      foreach (unowned Persona p in this._persona_set)
         {
           if (new_display_name != "")
             {
@@ -2017,7 +2017,7 @@ public class Folks.Individual : Object,
           new_display_name =
               this._look_up_name_details_for_display_name (primary_persona);
 
-          foreach (var p in this._persona_set)
+          foreach (unowned Persona p in this._persona_set)
             {
               if (new_display_name != "")
                 {
@@ -2035,7 +2035,7 @@ public class Folks.Individual : Object,
           new_display_name =
               this._look_up_email_address_for_display_name (primary_persona);
 
-          foreach (var p in this._persona_set)
+          foreach (unowned Persona p in this._persona_set)
             {
               if (new_display_name != "")
                 {
@@ -2053,7 +2053,7 @@ public class Folks.Individual : Object,
           new_display_name =
               this._look_up_phone_number_for_display_name (primary_persona);
 
-          foreach (var p in this._persona_set)
+          foreach (unowned Persona p in this._persona_set)
             {
               if (new_display_name != "")
                 {
@@ -2071,7 +2071,7 @@ public class Folks.Individual : Object,
           new_display_name =
               this._look_up_display_id_for_display_name (primary_persona);
 
-          foreach (var p in this._persona_set)
+          foreach (unowned Persona p in this._persona_set)
             {
               if (new_display_name != "")
                 {
@@ -2089,7 +2089,7 @@ public class Folks.Individual : Object,
           new_display_name =
               this._look_up_postal_address_for_display_name (primary_persona);
 
-          foreach (var p in this._persona_set)
+          foreach (unowned Persona p in this._persona_set)
             {
               if (new_display_name != "")
                 {
@@ -2203,7 +2203,7 @@ public class Folks.Individual : Object,
     {
       var trust_level = TrustLevel.PERSONAS;
 
-      foreach (var p in this._persona_set)
+      foreach (unowned Persona p in this._persona_set)
         {
           if (p.is_user == false &&
               p.store.trust_level == PersonaStoreTrust.NONE)
@@ -2396,10 +2396,10 @@ public class Folks.Individual : Object,
     {
       this._update_single_valued_property (typeof (NameDetails), (p) =>
         {
-          var nickname = ((NameDetails) p).nickname;
+          unowned string nickname = ((NameDetails) p).nickname;
           return_val_if_fail (nickname != null, false);
 
-          return (nickname.strip () != ""); /* empty names are unset */
+          return (((!) nickname).strip () != ""); /* empty names are unset */
         }, (a, b) =>
         {
           /* Can't compare two set names. */
@@ -2820,8 +2820,8 @@ public class Folks.Individual : Object,
         {
           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 string? a_event_id = ((BirthdayDetails) a).calendar_event_id;
+          unowned string? 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;
@@ -2947,7 +2947,7 @@ public class Folks.Individual : Object,
         }
 
       /* Determine which Personas have been removed */
-      foreach (var p in this._persona_set)
+      foreach (unowned Persona p in this._persona_set)
         {
           if (personas == null || !((!) personas).contains (p))
             {
diff --git a/folks/name-details.vala b/folks/name-details.vala
index d5fb1415..f05fb905 100644
--- a/folks/name-details.vala
+++ b/folks/name-details.vala
@@ -265,7 +265,7 @@ public class Folks.StructuredName : Object
        * punctuation, please file a bug against libfolks:
        *   https://gitlab.gnome.org/GNOME/folks/issues
        */
-      var name_fmt = _("%g%t%m%t%f");
+      unowned string name_fmt = _("%g%t%m%t%f");
 
       return this.to_string_with_format (name_fmt);
     }
diff --git a/folks/postal-address-details.vala b/folks/postal-address-details.vala
index f08d874e..3dd69a8e 100644
--- a/folks/postal-address-details.vala
+++ b/folks/postal-address-details.vala
@@ -229,7 +229,7 @@ public class Folks.PostalAddress : Object
    */
   public string to_string ()
     {
-      var str = _("%s, %s, %s, %s, %s, %s, %s");
+      unowned string str = _("%s, %s, %s, %s, %s, %s, %s");
       return str.printf (this.po_box, this.extension, this.street,
           this.locality, this.region, this.postal_code, this.country);
     }


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