[folks] Use SmallSet.copy() where it makes sense
- From: Simon McVittie <smcv src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [folks] Use SmallSet.copy() where it makes sense
- Date: Thu, 4 Apr 2013 14:13:17 +0000 (UTC)
commit eebdc677e00a0114ebcf90cf8546998367f6fa96
Author: Simon McVittie <simon mcvittie collabora co uk>
Date: Wed Apr 3 18:12:23 2013 +0100
Use SmallSet.copy() where it makes sense
It isn't more than fractionally faster in tests/eds/perf, but might help.
Bug: https://bugzilla.gnome.org/show_bug.cgi?id=687161
Signed-off-by: Simon McVittie <simon mcvittie collabora co uk>
Reviewed-by: Philip Withnall <philip tecnocode co uk>
backends/eds/lib/edsf-persona.vala | 21 ++++++---------------
folks/anti-linkable.vala | 6 ++----
folks/individual-aggregator.vala | 15 ++++-----------
3 files changed, 12 insertions(+), 30 deletions(-)
---
diff --git a/backends/eds/lib/edsf-persona.vala b/backends/eds/lib/edsf-persona.vala
index eb10f79..78dacf5 100644
--- a/backends/eds/lib/edsf-persona.vala
+++ b/backends/eds/lib/edsf-persona.vala
@@ -614,11 +614,7 @@ public class Edsf.Persona : Folks.Persona,
}
/* Replace the current set of groups with a modified one. */
- var new_groups = new SmallSet<string> ();
- foreach (var category_name in this.groups)
- {
- new_groups.add (category_name);
- }
+ var new_groups = SmallSet<string>.copy (this.groups);
if (is_member == false)
{
@@ -697,21 +693,16 @@ public class Edsf.Persona : Folks.Persona,
return;
}
- var new_system_groups = new SmallSet<string> ();
- foreach (var sg in this._system_groups)
- {
- if (sg == GOOGLE_PERSONAL_GROUP_NAME && !in_personal)
- {
- continue;
- }
-
- new_system_groups.add (sg);
- }
+ var new_system_groups = SmallSet<string>.copy (this._system_groups);
if (in_personal)
{
new_system_groups.add (GOOGLE_PERSONAL_GROUP_NAME);
}
+ else
+ {
+ new_system_groups.remove (GOOGLE_PERSONAL_GROUP_NAME);
+ }
yield ((Edsf.PersonaStore) this.store)._set_system_groups (this, new_system_groups);
}
diff --git a/folks/anti-linkable.vala b/folks/anti-linkable.vala
index a53af5f..93a82c7 100644
--- a/folks/anti-linkable.vala
+++ b/folks/anti-linkable.vala
@@ -115,8 +115,7 @@ public interface Folks.AntiLinkable : Folks.Persona
public async void add_anti_links (Set<Persona> other_personas)
throws PropertyError
{
- var new_anti_links = new SmallSet<string> ();
- new_anti_links.add_all (this.anti_links);
+ var new_anti_links = SmallSet.copy (this.anti_links);
foreach (var p in other_personas)
{
@@ -148,8 +147,7 @@ public interface Folks.AntiLinkable : Folks.Persona
public async void remove_anti_links (Set<Persona> other_personas)
throws PropertyError
{
- var new_anti_links = new SmallSet<string> ();
- new_anti_links.add_all (this.anti_links);
+ var new_anti_links = SmallSet.copy (this.anti_links);
foreach (var p in other_personas)
{
diff --git a/folks/individual-aggregator.vala b/folks/individual-aggregator.vala
index 84bb9e7..8313e3d 100644
--- a/folks/individual-aggregator.vala
+++ b/folks/individual-aggregator.vala
@@ -1943,13 +1943,7 @@ public class Folks.IndividualAggregator : Object
{
/* Removing personas changes the persona set so we need to make a copy
* first */
- var personas = new SmallSet<Persona> ();
- /* FIXME: this is O(n**2) but if we know that individual.personas
- * is a SmallSet, we can do it in O(n) */
- foreach (var p in individual.personas)
- {
- personas.add (p);
- }
+ var personas = SmallSet<Persona>.copy (individual.personas);
foreach (var persona in personas)
{
@@ -2180,8 +2174,8 @@ public class Folks.IndividualAggregator : Object
* In the worst case, this will double the number of personas, since if
* none of the personas have anti-links writeable, each will have to be
* linked with a new writeable persona. */
- var individual_personas = new SmallSet<Persona> (); /* as we modify it */
- individual_personas.add_all (individual.personas);
+ /* Copy it, since we modify it */
+ var individual_personas = SmallSet<Persona>.copy (individual.personas);
debug (" Inserting anti-links:");
foreach (var pers in individual_personas)
@@ -2199,8 +2193,7 @@ public class Folks.IndividualAggregator : Object
writeable_persona.uid, writeable_persona);
/* Make sure not to anti-link the new persona to pers. */
- var anti_link_personas = new SmallSet<Persona> ();
- anti_link_personas.add_all (individual_personas);
+ var anti_link_personas = SmallSet<Persona>.copy (individual_personas);
anti_link_personas.remove (pers);
var al = writeable_persona as AntiLinkable;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]