summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiels De Graef <nielsdegraef@gmail.com>2020-11-07 12:47:58 +0100
committerNiels De Graef <nielsdegraef@gmail.com>2020-11-07 12:47:58 +0100
commit8fbb47ecf848cc74a4a555e9c674614c5a7282d6 (patch)
treeec6e09ea73bd864859f19a0fa8386ac77f26741e
parentf1e30bd8270e14ab39752f397e5b7bce94254591 (diff)
downloadgnome-contacts-8fbb47ecf848cc74a4a555e9c674614c5a7282d6.tar.gz
Reduce the amount of unnecessary refcounting
In a lot of places, we're accidentally taking a strong reference to a variable, which means that internally, we'll be using a lot of `g_object_ref()` and `g_object_unref()` for no good reason. Especially on some hot paths (and large address books), this can make a tiny bit of a difference in terms of performance.
-rw-r--r--src/contacts-contact-list.vala30
-rw-r--r--src/contacts-store.vala2
-rw-r--r--src/contacts-type-descriptor.vala2
-rw-r--r--src/contacts-typeset.vala2
-rw-r--r--src/contacts-utils.vala16
-rw-r--r--src/contacts-window.vala14
6 files changed, 33 insertions, 33 deletions
diff --git a/src/contacts-contact-list.vala b/src/contacts-contact-list.vala
index c12beab..96f49f6 100644
--- a/src/contacts-contact-list.vala
+++ b/src/contacts-contact-list.vala
@@ -27,7 +27,7 @@ public class Contacts.ContactList : Gtk.ListBox {
private class ContactDataRow : Gtk.ListBoxRow {
private const int LIST_AVATAR_SIZE = 48;
- public Individual individual;
+ public unowned Individual individual;
private Gtk.Label label;
private Avatar avatar;
public Gtk.CheckButton selector_button;
@@ -147,16 +147,16 @@ public class Contacts.ContactList : Gtk.ListBox {
}
private int compare_rows (Gtk.ListBoxRow row_a, Gtk.ListBoxRow row_b) {
- var a = ((ContactDataRow) row_a).individual;
- var b = ((ContactDataRow) row_b).individual;
+ unowned var a = ((ContactDataRow) row_a).individual;
+ unowned var b = ((ContactDataRow) row_b).individual;
// Always prefer favourites over non-favourites.
if (a.is_favourite != b.is_favourite)
return a.is_favourite? -1 : 1;
// Both are (non-)favourites: sort by either first name or surname (user preference)
- unowned string? a_name = this.sort_on_surname? try_get_surname(a) : a.display_name;
- unowned string? b_name = this.sort_on_surname? try_get_surname(b) : b.display_name;
+ unowned var a_name = this.sort_on_surname? try_get_surname (a) : a.display_name;
+ unowned var b_name = this.sort_on_surname? try_get_surname (b) : b.display_name;
return a_name.collate (b_name);
}
@@ -170,7 +170,7 @@ public class Contacts.ContactList : Gtk.ListBox {
}
private void update_header (Gtk.ListBoxRow row, Gtk.ListBoxRow? before) {
- var current = ((ContactDataRow) row).individual;
+ unowned var current = ((ContactDataRow) row).individual;
if (before == null) {
if (current.is_favourite)
@@ -180,7 +180,7 @@ public class Contacts.ContactList : Gtk.ListBox {
return;
}
- var previous = ((ContactDataRow) before).individual;
+ unowned var previous = ((ContactDataRow) before).individual;
if (!current.is_favourite && previous.is_favourite) {
row.set_header (create_header_label (_("All Contacts")));
} else {
@@ -268,9 +268,9 @@ public class Contacts.ContactList : Gtk.ListBox {
}
- private ContactDataRow? find_row_for_contact (Individual individual) {
- foreach (var widget in get_children ()) {
- var row = ((ContactDataRow) widget);
+ private unowned ContactDataRow? find_row_for_contact (Individual individual) {
+ foreach (weak Gtk.Widget widget in get_children ()) {
+ unowned var row = ((ContactDataRow) widget);
if (row.individual == individual)
return row;
}
@@ -280,8 +280,8 @@ public class Contacts.ContactList : Gtk.ListBox {
public LinkedList<Individual> get_marked_contacts () {
var cs = new LinkedList<Individual> ();
- foreach (var widget in get_children ()) {
- var row = widget as ContactDataRow;
+ foreach (weak Gtk.Widget widget in get_children ()) {
+ unowned var row = widget as ContactDataRow;
if (row.selector_button.active)
cs.add (row.individual);
}
@@ -290,8 +290,8 @@ public class Contacts.ContactList : Gtk.ListBox {
public LinkedList<Individual> get_marked_contacts_and_hide () {
var cs = new LinkedList<Individual> ();
- foreach (var widget in get_children ()) {
- var row = widget as ContactDataRow;
+ foreach (weak Gtk.Widget widget in get_children ()) {
+ unowned var row = widget as ContactDataRow;
if (row.selector_button.active) {
row.visible = false;
cs.add (row.individual);
@@ -305,7 +305,7 @@ public class Contacts.ContactList : Gtk.ListBox {
base.button_press_event (event);
if (event.button == Gdk.BUTTON_SECONDARY) {
- var row = (ContactDataRow) get_row_at_y ((int) Math.round (event.y));
+ unowned var row = (ContactDataRow) get_row_at_y ((int) Math.round (event.y));
if (row != null) {
select_row (row);
row.selector_button.active = this.state != UiState.SELECTING || !row.selector_button.active;
diff --git a/src/contacts-store.vala b/src/contacts-store.vala
index daadd19..a9c6a57 100644
--- a/src/contacts-store.vala
+++ b/src/contacts-store.vala
@@ -49,7 +49,7 @@ public class Contacts.Store : GLib.Object {
FileUtils.get_contents (path, out contents);
var rows = contents.split ("\n");
- foreach (var r in rows) {
+ foreach (unowned string r in rows) {
var ids = r.split (" ");
if (ids.length == 2) {
dont_suggest_link.set (ids[0], ids[1]);
diff --git a/src/contacts-type-descriptor.vala b/src/contacts-type-descriptor.vala
index efc96ce..90f0489 100644
--- a/src/contacts-type-descriptor.vala
+++ b/src/contacts-type-descriptor.vala
@@ -31,7 +31,7 @@ public class Contacts.TypeDescriptor : Object {
OTHER,
CUSTOM;
- public string to_string () {
+ public unowned string to_string () {
switch (this) {
case VCARD:
return "vcard";
diff --git a/src/contacts-typeset.vala b/src/contacts-typeset.vala
index f771436..63b4518 100644
--- a/src/contacts-typeset.vala
+++ b/src/contacts-typeset.vala
@@ -82,7 +82,7 @@ public class Contacts.TypeSet : Object {
/**
* Returns the display name for the type of the given AbstractFieldDetails.
*/
- public string format_type (AbstractFieldDetails detail) {
+ public unowned string format_type (AbstractFieldDetails detail) {
var d = lookup_descriptor_for_field_details (detail);
return d.display_name;
}
diff --git a/src/contacts-utils.vala b/src/contacts-utils.vala
index 8f3b8c1..1540b0c 100644
--- a/src/contacts-utils.vala
+++ b/src/contacts-utils.vala
@@ -334,7 +334,7 @@ namespace Contacts.Utils {
public Tpf.Persona? find_im_persona (Individual individual, string protocol, string im_address) {
var iid = protocol + ":" + im_address;
foreach (var p in individual.personas) {
- var tp = p as Tpf.Persona;
+ unowned var tp = p as Tpf.Persona;
if (tp != null && tp.iid == iid) {
return tp;
}
@@ -355,8 +355,8 @@ namespace Contacts.Utils {
public Gee.List<Persona> get_personas_for_display (Individual individual) {
CompareDataFunc<Persona> compare_persona_by_store = (a, b) => {
- var store_a = a.store;
- var store_b = b.store;
+ unowned var store_a = a.store;
+ unowned var store_b = b.store;
// In the same store, sort Google 'other' contacts last
if (store_a == store_b) {
@@ -470,7 +470,7 @@ namespace Contacts.Utils {
if (!persona_is_google (persona))
return false;
- var p = persona as Edsf.Persona;
+ unowned var p = persona as Edsf.Persona;
return p != null && !p.in_google_personal_group;
}
@@ -478,7 +478,7 @@ namespace Contacts.Utils {
if (!persona_is_google_other (persona))
return false;
- var u = persona as UrlDetails;
+ unowned var u = persona as UrlDetails;
if (u != null && u.urls.size == 1) {
foreach (var url in u.urls) {
if (/https?:\/\/www.google.com\/profiles\/[0-9]+$/.match(url.value))
@@ -489,7 +489,7 @@ namespace Contacts.Utils {
}
public string format_persona_store_name_for_contact (Persona persona) {
- var store = persona.store;
+ unowned var store = persona.store;
if (store.type_id == "eds") {
if (persona_is_google_profile (persona))
return _("Google Circles");
@@ -502,7 +502,7 @@ namespace Contacts.Utils {
}
#if HAVE_TELEPATHY
if (store.type_id == "telepathy") {
- var account = (store as Tpf.PersonaStore).account;
+ unowned var account = (store as Tpf.PersonaStore).account;
return Contacts.ImService.get_display_name (account.service);
}
#endif
@@ -595,7 +595,7 @@ namespace Contacts.Utils {
public void fetch_contact_info (Individual individual) {
/* TODO: Ideally Folks should have API for this (#675131) */
foreach (var p in individual.personas) {
- var tp = p as Tpf.Persona;
+ unowned var tp = p as Tpf.Persona;
if (tp != null) {
tp.contact.request_contact_info_async.begin (null);
}
diff --git a/src/contacts-window.vala b/src/contacts-window.vala
index 759832b..10ee929 100644
--- a/src/contacts-window.vala
+++ b/src/contacts-window.vala
@@ -126,7 +126,7 @@ public class Contacts.Window : Hdy.ApplicationWindow {
}
private void restore_window_size_and_position_from_settings () {
- var screen = get_screen();
+ unowned var screen = get_screen ();
if (screen != null && this.window_width <= screen.get_width () && this.window_height <= screen.get_height ()) {
set_default_size (this.window_width, this.window_height);
}
@@ -150,7 +150,7 @@ public class Contacts.Window : Hdy.ApplicationWindow {
public override void size_allocate (Gtk.Allocation allocation) {
base.size_allocate (allocation);
- var screen = get_screen ();
+ unowned var screen = get_screen ();
if (screen != null && !this.window_maximized) {
// Get the size via ::get_size instead of the allocation
// so that the window isn't ever-expanding.
@@ -249,9 +249,9 @@ public class Contacts.Window : Hdy.ApplicationWindow {
}
private void set_selection_mode (bool selection_mode) {
- var left_ctx = this.left_header.get_style_context ();
- var separator_ctx = this.header_separator.get_style_context ();
- var right_ctx = this.right_header.get_style_context ();
+ unowned var left_ctx = this.left_header.get_style_context ();
+ unowned var separator_ctx = this.header_separator.get_style_context ();
+ unowned var right_ctx = this.right_header.get_style_context ();
if (selection_mode) {
left_ctx.add_class ("selection-mode");
separator_ctx.add_class ("selection-mode");
@@ -278,7 +278,7 @@ public class Contacts.Window : Hdy.ApplicationWindow {
this.state = UiState.UPDATING;
- var name = this.contact_pane.individual.display_name;
+ unowned var name = this.contact_pane.individual.display_name;
this.right_header.title = _("Editing %s").printf (name);
this.contact_pane.edit_contact ();
}
@@ -431,7 +431,7 @@ public class Contacts.Window : Hdy.ApplicationWindow {
this.cancel_button.clicked.connect (() => stop_editing (true));
this.contact_pane.notify["individual"].connect (() => {
- var individual = this.contact_pane.individual;
+ unowned var individual = this.contact_pane.individual;
if (individual == null)
return;
this.unlink_button.set_visible (individual.personas.size > 1);