Commit 64ab5aa9 authored by Niels De Graef's avatar Niels De Graef

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.
parent 2a0ac05e
......@@ -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)
{
......
......@@ -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;
......
......@@ -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);
......
......@@ -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