[epiphany/gnome-3-36] Exit early in suggestion model to prevent unnecessary row creation



commit c67892ed8a202615be8b3efd532fbb361065de64
Author: Jan-Michael Brummer <jan brummer tabos org>
Date:   Sun Mar 15 15:26:53 2020 +0100

    Exit early in suggestion model to prevent unnecessary row creation
    
    Fixes: https://gitlab.gnome.org/GNOME/epiphany/issues/1096

 src/ephy-suggestion-model.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
---
diff --git a/src/ephy-suggestion-model.c b/src/ephy-suggestion-model.c
index 97965a01a..3cbdc0ffc 100644
--- a/src/ephy-suggestion-model.c
+++ b/src/ephy-suggestion-model.c
@@ -28,6 +28,7 @@
 #include <glib/gi18n.h>
 
 #define MAX_COMPLETION_HISTORY_URLS 8
+#define MAX_URL_ENTRIES             25
 
 struct _EphySuggestionModel {
   GObject parent;
@@ -252,7 +253,7 @@ static gboolean
 append_suggestion (EphySuggestionModel *self,
                    EphySuggestion      *suggestion)
 {
-  if (self->num_custom_entries < 25) {
+  if (self->num_custom_entries < MAX_URL_ENTRIES) {
     g_sequence_append (self->items, suggestion);
     self->num_custom_entries++;
 
@@ -304,6 +305,8 @@ add_bookmarks (EphySuggestionModel *self,
       if (append_suggestion (self, suggestion)) {
         new_urls = g_list_prepend (new_urls, g_strdup (url));
         added++;
+      } else {
+        break;
       }
     }
   }
@@ -344,6 +347,8 @@ add_history (EphySuggestionModel *self,
 
     if (append_suggestion (self, suggestion))
       added++;
+    else
+      break;
   }
 
   return added;
@@ -406,7 +411,6 @@ add_tabs (EphySuggestionModel *self,
   shell = ephy_embed_shell_get_default ();
   application = G_APPLICATION (shell);
   window = EPHY_WINDOW (gtk_application_get_active_window (GTK_APPLICATION (application)));
-  self->num_custom_entries = 0;
 
   if (!window)
     return 0;
@@ -494,6 +498,7 @@ query_completed_cb (EphyHistoryService *service,
   self->urls = g_sequence_new (g_free);
   g_clear_pointer (&self->items, g_sequence_free);
   self->items = g_sequence_new (g_object_unref);
+  self->num_custom_entries = 0;
 
   if (strlen (query) > 0) {
     added = add_tabs (self, query);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]