[folks/perf2: 6/6] wip
- From: Niels De Graef <nielsdg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [folks/perf2: 6/6] wip
- Date: Sat, 17 Oct 2020 17:31:06 +0000 (UTC)
commit 252ad2f29a3023eaec2eb3fe2d8ac869480b5d44
Author: Niels De Graef <nielsdegraef gmail com>
Date: Sat Oct 17 19:30:59 2020 +0200
wip
backends/eds/lib/edsf-persona-store.vala | 2 +-
folks/abstract-field-details.vala | 6 ++--
folks/individual.vala | 58 ++++++++++++++++----------------
folks/name-details.vala | 6 ++--
folks/persona.vala | 6 ++--
folks/phone-details.vala | 8 ++---
folks/postal-address-details.vala | 2 +-
folks/utils.vala | 20 +++++++++++
8 files changed, 63 insertions(+), 45 deletions(-)
---
diff --git a/backends/eds/lib/edsf-persona-store.vala b/backends/eds/lib/edsf-persona-store.vala
index 4cac5620..f558a5f2 100644
--- a/backends/eds/lib/edsf-persona-store.vala
+++ b/backends/eds/lib/edsf-persona-store.vala
@@ -861,7 +861,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;
}
diff --git a/folks/abstract-field-details.vala b/folks/abstract-field-details.vala
index ed28cd22..1bfa7802 100644
--- a/folks/abstract-field-details.vala
+++ b/folks/abstract-field-details.vala
@@ -292,8 +292,8 @@ public abstract class Folks.AbstractFieldDetails<T> : Object
GLib.return_val_if_fail (left != null, false);
GLib.return_val_if_fail (right != null, false);
- AbstractFieldDetails left_details = (AbstractFieldDetails) left;
- AbstractFieldDetails right_details = (AbstractFieldDetails) right;
+ unowned var left_details = (AbstractFieldDetails) left;
+ unowned var right_details = (AbstractFieldDetails) right;
return left_details.equal (right_details);
}
@@ -446,7 +446,7 @@ public abstract class Folks.AbstractFieldDetails<T> : Object
{
GLib.return_val_if_fail (value != null, 0);
- AbstractFieldDetails details = (AbstractFieldDetails) value;
+ unowned var details = (AbstractFieldDetails) value;
return details.hash ();
}
}
diff --git a/folks/individual.vala b/folks/individual.vala
index bc63dc11..9b5c1c7f 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)
{
unowned 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)
{
unowned 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)
{
unowned 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)
{
unowned 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)
{
unowned 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);
@@ -1619,7 +1619,7 @@ public class Folks.Individual : Object,
unowned 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))
@@ -1771,7 +1771,7 @@ public class Folks.Individual : Object,
* "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)
{
@@ -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 != "")
{
@@ -2112,7 +2112,7 @@ public class Folks.Individual : Object,
if (new_display_name != this._display_name)
{
- this._display_name = new_display_name;
+ this._display_name = (owned) new_display_name;
debug ("Setting display name ā%sā", new_display_name);
this.notify_property ("display-name");
}
@@ -2125,7 +2125,7 @@ public class Folks.Individual : Object,
unowned var alias = ((AliasDetails) p).alias;
return_val_if_fail (alias != null, false);
- return (alias.strip () != ""); /* empty aliases are unset */
+ return !Utils.is_string_empty (alias); /* empty aliases are unset */
}, (a, b) =>
{
unowned var a_alias = ((AliasDetails) a).alias;
@@ -2134,8 +2134,8 @@ public class Folks.Individual : Object,
return_val_if_fail (a_alias != null, 0);
return_val_if_fail (b_alias != null, 0);
- var a_is_empty = (a_alias.strip () == "") ? 1 : 0;
- var b_is_empty = (b_alias.strip () == "") ? 1 : 0;
+ var a_is_empty = Utils.is_string_empty (a_alias) ? 1 : 0;
+ var b_is_empty = Utils.is_string_empty (b_alias) ? 1 : 0;
/* We prefer to not have an alias which is the same as the Persona's
* display-id, since having such an alias implies that it's the
@@ -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)
@@ -2368,7 +2368,7 @@ public class Folks.Individual : Object,
unowned var name = ((NameDetails) p).full_name;
return_val_if_fail (name != null, false);
- return (name.strip () != ""); /* empty names are unset */
+ return !Utils.is_string_empty (name); /* empty names are unset */
}, (a, b) =>
{
/* Can't compare two set names. */
@@ -2384,7 +2384,7 @@ public class Folks.Individual : Object,
if (new_full_name != this._full_name)
{
- this._full_name = new_full_name;
+ this._full_name = (owned) new_full_name;
this.notify_property ("full-name");
this._update_display_name ();
@@ -2399,7 +2399,7 @@ public class Folks.Individual : Object,
unowned var nickname = ((NameDetails) p).nickname;
return_val_if_fail (nickname != null, false);
- return (nickname.strip () != ""); /* empty names are unset */
+ return !Utils.is_string_empty (nickname); /* empty names are unset */
}, (a, b) =>
{
/* Can't compare two set names. */
@@ -2415,7 +2415,7 @@ public class Folks.Individual : Object,
if (new_nickname != this._nickname)
{
- this._nickname = new_nickname;
+ this._nickname = (owned) new_nickname;
this.notify_property ("nickname");
this._update_display_name ();
@@ -2928,7 +2928,7 @@ public class Folks.Individual : Object,
this._connect_to_persona (p);
/* Increment the Persona count for this PersonaStore */
- var store = p.store;
+ unowned var store = p.store;
var num_from_store = this._stores.get (store);
if (num_from_store == 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..ee72e7d2 100644
--- a/folks/name-details.vala
+++ b/folks/name-details.vala
@@ -214,7 +214,7 @@ public class Folks.StructuredName : Object
}
}
- return output.str;
+ return (owned) output.str;
}
/**
@@ -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 var name_fmt = _("%g%t%m%t%f");
return this.to_string_with_format (name_fmt);
}
@@ -372,7 +372,7 @@ public class Folks.StructuredName : Object
}
}
- return output.str;
+ return (owned) output.str;
}
}
diff --git a/folks/persona.vala b/folks/persona.vala
index ecbadb9f..add9be12 100644
--- a/folks/persona.vala
+++ b/folks/persona.vala
@@ -283,7 +283,7 @@ public abstract class Folks.Persona : Object
assert_not_reached ();
}
- private static string _add_escaped_uid_component (StringBuilder uid, string component)
+ private static void _add_escaped_uid_component (StringBuilder uid, string component)
{
/* Escape colons with backslashes */
for (int i = 0; i < component.length; i++)
@@ -295,8 +295,6 @@ public abstract class Folks.Persona : Object
}
uid.append_c (c);
}
-
- return uid.str;
}
private static string _unescape_uid_component (string component)
@@ -338,7 +336,7 @@ public abstract class Folks.Persona : Object
uid.append_c (':');
Persona._add_escaped_uid_component (uid, persona_id);
- return uid.str;
+ return (owned) uid.str;
}
/**
diff --git a/folks/phone-details.vala b/folks/phone-details.vala
index 141ac073..9e97eb3b 100644
--- a/folks/phone-details.vala
+++ b/folks/phone-details.vala
@@ -91,10 +91,10 @@ public class Folks.PhoneFieldDetails : AbstractFieldDetails<string>
*/
public override bool values_equal (AbstractFieldDetails<string> that)
{
- var _that_fd = that as PhoneFieldDetails;
+ unowned var _that_fd = that as PhoneFieldDetails;
if (_that_fd == null)
return false;
- PhoneFieldDetails that_fd = (!) _that_fd;
+ unowned PhoneFieldDetails that_fd = (!) _that_fd;
var n1 = PhoneFieldDetails._drop_extension (this.get_normalised ());
var n2 = PhoneFieldDetails._drop_extension (that_fd.get_normalised ());
@@ -185,7 +185,7 @@ public class Folks.PhoneFieldDetails : AbstractFieldDetails<string>
builder.append_c (digit);
}
- return builder.str;
+ return (owned) builder.str;
}
/**
@@ -214,7 +214,7 @@ public class Folks.PhoneFieldDetails : AbstractFieldDetails<string>
builder.append_c (digit);
}
- return builder.str;
+ return (owned) builder.str;
}
}
diff --git a/folks/postal-address-details.vala b/folks/postal-address-details.vala
index f08d874e..d40bd1a7 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 var 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);
}
diff --git a/folks/utils.vala b/folks/utils.vala
index 2339e273..a69086a9 100644
--- a/folks/utils.vala
+++ b/folks/utils.vala
@@ -273,4 +273,24 @@ public class Folks.Utils : Object
return true;
}
+
+ /**
+ * Checks whether the given string is empty, ignoring any trailing or leading
+ * whitespace. Basically, it's the same as executing (str.strip() != ""), but
+ * without unnecessarily creating a string copy.
+ *
+ * @param str The string to check for
+ * @since 0.14.1
+ */
+ public static bool is_string_empty (string str)
+ {
+ int length = str.length;
+ for (int i = 0; i < length; i++)
+ {
+ if (! str[i].isspace ())
+ return false;
+ }
+
+ return true;
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]