diff options
author | Niels De Graef <nielsdegraef@gmail.com> | 2019-11-27 23:29:01 +0100 |
---|---|---|
committer | Niels De Graef <nielsdegraef@gmail.com> | 2020-02-20 07:49:33 +0100 |
commit | 80e185b21854654bcbeb951cd4cf4a65e2e38782 (patch) | |
tree | ec698b6c524eae8b799f68f786b4c79a3e9fc784 | |
parent | 1e9e707885cc295f83437a0be006bda342917eba (diff) | |
download | folks-wip/nielsdg/prevent-string-copies.tar.gz |
edsf: Don't make copies of E.VCardAttributewip/nielsdg/prevent-string-copies
Using `var` in Vala automatically means you take a strong reference,
which in the case of boxed types means that we will copy them (even if
not necessary). We probably want to avoid this inside `Edsf.Persona`,
since that means we might do multiple copies on each contact of a user.
-rw-r--r-- | backends/eds/lib/edsf-persona-store.vala | 4 | ||||
-rw-r--r-- | backends/eds/lib/edsf-persona.vala | 17 |
2 files changed, 12 insertions, 9 deletions
diff --git a/backends/eds/lib/edsf-persona-store.vala b/backends/eds/lib/edsf-persona-store.vala index 91377357..31f47b58 100644 --- a/backends/eds/lib/edsf-persona-store.vala +++ b/backends/eds/lib/edsf-persona-store.vala @@ -1747,7 +1747,7 @@ public class Edsf.PersonaStore : Folks.PersonaStore E.VCardAttribute new_attr = new E.VCardAttribute (null, name); new_attr.add_value (details.value); - vcard.add_attribute (new_attr); + vcard.add_attribute ((owned) new_attr); yield this._commit_modified_property (persona, null); } @@ -2241,7 +2241,7 @@ public class Edsf.PersonaStore : Folks.PersonaStore new_attr.add_value (group); } - vcard.add_attribute (new_attr); + vcard.add_attribute ((owned) new_attr); } internal async void _set_gender (Edsf.Persona persona, diff --git a/backends/eds/lib/edsf-persona.vala b/backends/eds/lib/edsf-persona.vala index ac1a3afc..2dddaf6a 100644 --- a/backends/eds/lib/edsf-persona.vala +++ b/backends/eds/lib/edsf-persona.vala @@ -1178,7 +1178,7 @@ public class Edsf.Persona : Folks.Persona, private void _update_gender () { var gender = Gender.UNSPECIFIED; - var gender_attr = + unowned E.VCardAttribute gender_attr = this.contact.get_attribute (Edsf.Persona.gender_attribute_name); if (gender_attr != null) @@ -1391,7 +1391,8 @@ public class Edsf.Persona : Folks.Persona, null, null, AbstractFieldDetails<string>.hash_static, AbstractFieldDetails<string>.equal_static); - var services = this.contact.get_attribute ("X-FOLKS-WEB-SERVICES-IDS"); + unowned E.VCardAttribute services = + this.contact.get_attribute ("X-FOLKS-WEB-SERVICES-IDS"); if (services != null) { foreach (unowned E.VCardAttributeParam service in ((!) services).get_params ()) @@ -1425,7 +1426,7 @@ public class Edsf.Persona : Folks.Persona, AbstractFieldDetails<string>.equal_static); var attrs = this.contact.get_attributes (E.ContactField.EMAIL); - foreach (var attr in attrs) + foreach (unowned E.VCardAttribute attr in attrs) { var val = attr.get_value (); if (val == null || (!) val == "") @@ -1699,7 +1700,7 @@ public class Edsf.Persona : Folks.Persona, { var addresses = this.contact.get_attributes ( im_eds_map.lookup (im_proto)); - foreach (var attr in addresses) + foreach (unowned E.VCardAttribute attr in addresses) { try { @@ -2013,7 +2014,7 @@ public class Edsf.Persona : Folks.Persona, AbstractFieldDetails<string>.equal_static); var attrs = this.contact.get_attributes (E.ContactField.TEL); - foreach (var attr in attrs) + foreach (unowned E.VCardAttribute attr in attrs) { var val = attr.get_value (); if (val == null || (!) val == "") @@ -2155,7 +2156,8 @@ public class Edsf.Persona : Folks.Persona, { var new_local_ids = new SmallSet<string> (); - var ids = this.contact.get_attribute ("X-FOLKS-CONTACTS-IDS"); + unowned E.VCardAttribute ids = + this.contact.get_attribute ("X-FOLKS-CONTACTS-IDS"); if (ids != null) { unowned GLib.List<string> ids_v = ((!) ids).get_values (); @@ -2219,7 +2221,8 @@ public class Edsf.Persona : Folks.Persona, { bool is_fav = false; - var fav = this.contact.get_attribute ("X-FOLKS-FAVOURITE"); + unowned E.VCardAttribute fav = + this.contact.get_attribute ("X-FOLKS-FAVOURITE"); if (fav != null) { var val = ((!) fav).get_value (); |