[nautilus/antoniof/241-wrong-use-of-g_list_length-to-know-if-a-glist-is-empty] general: Don't iterate GList to check for empty
- From: António Fernandes <antoniof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/antoniof/241-wrong-use-of-g_list_length-to-know-if-a-glist-is-empty] general: Don't iterate GList to check for empty
- Date: Fri, 9 Feb 2018 16:03:22 +0000 (UTC)
commit 02be3ec3dfca458d21dd19fe634daab72980862f
Author: António Fernandes <antoniof gnome org>
Date: Wed Feb 7 19:45:59 2018 +0000
general: Don't iterate GList to check for empty
According to `g_list_length()` API documentaion: "To check whether
the list is non-empty, it is faster to check list against NULL."
Checking `GList`s against `NULL` is already common in this codebase.
Weed out the few checks of `g_list_length()` against `0` or `< 1`.
Closes https://gitlab.gnome.org/GNOME/nautilus/issues/241
src/nautilus-progress-persistence-handler.c | 9 ++++-----
src/nautilus-properties-window.c | 2 +-
src/nautilus-window.c | 4 ++--
3 files changed, 7 insertions(+), 8 deletions(-)
---
diff --git a/src/nautilus-progress-persistence-handler.c b/src/nautilus-progress-persistence-handler.c
index cc104fb6a..77ffdcdd8 100644
--- a/src/nautilus-progress-persistence-handler.c
+++ b/src/nautilus-progress-persistence-handler.c
@@ -127,8 +127,7 @@ nautilus_progress_persistence_handler_make_persistent (NautilusProgressPersisten
GList *windows;
windows = nautilus_application_get_windows (self->app);
- if (self->active_infos > 0 &&
- g_list_length (windows) == 0)
+ if (self->active_infos > 0 && windows == NULL)
{
progress_persistence_handler_update_notification (self);
}
@@ -177,12 +176,12 @@ progress_info_finished_cb (NautilusProgressInfo *info,
windows = nautilus_application_get_windows (self->app);
if (self->active_infos > 0)
{
- if (g_list_length (windows) == 0)
+ if (windows == NULL)
{
progress_persistence_handler_update_notification (self);
}
}
- else if (g_list_length (windows) == 0)
+ else if (windows == NULL)
{
progress_persistence_handler_hide_notification (self);
progress_persistence_handler_show_complete_notification (self);
@@ -200,7 +199,7 @@ handle_new_progress_info (NautilusProgressPersistenceHandler *self,
self->active_infos++;
windows = nautilus_application_get_windows (self->app);
- if (g_list_length (windows) == 0)
+ if (windows == NULL)
{
progress_persistence_handler_update_notification (self);
}
diff --git a/src/nautilus-properties-window.c b/src/nautilus-properties-window.c
index 14302204c..3fb9f6a61 100644
--- a/src/nautilus-properties-window.c
+++ b/src/nautilus-properties-window.c
@@ -2303,7 +2303,7 @@ directory_contents_value_field_update (NautilusPropertiesWindow *window)
}
}
- deep_count_active = (g_list_length (window->details->deep_count_files) > 0);
+ deep_count_active = (window->details->deep_count_files != NULL);
/* If we've already displayed the total once, don't do another visible
* count-up if the deep_count happens to get invalidated.
* But still display the new total, since it might have changed.
diff --git a/src/nautilus-window.c b/src/nautilus-window.c
index 83f4c23b7..0d689ca15 100644
--- a/src/nautilus-window.c
+++ b/src/nautilus-window.c
@@ -1215,7 +1215,7 @@ places_sidebar_drag_action_requested_cb (GtkPlacesSidebar *sidebar,
}
uri = g_file_get_uri (dest_file);
- if (g_list_length (items) < 1)
+ if (items == NULL)
{
goto out;
}
@@ -1848,7 +1848,7 @@ nautilus_window_on_undo_changed (NautilusFileUndoManager *manager,
/* Don't pop up a notification if user canceled the operation or the focus
* is not in the this window. This is an easy way to know from which window
* was the delete operation made */
- if (g_list_length (files) > 0 && gtk_window_has_toplevel_focus (GTK_WINDOW (window)))
+ if (files != NULL && gtk_window_has_toplevel_focus (GTK_WINDOW (window)))
{
popup_notification = TRUE;
label = in_app_notification_undo_deleted_get_label (undo_info);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]