Optimize array iterations in the browser

This commit is contained in:
Christian Dywan 2009-03-31 21:19:18 +02:00
parent 3f802e3beb
commit b083c5bbd0

View file

@ -681,12 +681,9 @@ midori_browser_edit_bookmark_dialog_new (MidoriBrowser* browser,
selected = gtk_combo_box_get_active_text (GTK_COMBO_BOX (combo_folder)); selected = gtk_combo_box_get_active_text (GTK_COMBO_BOX (combo_folder));
if (g_strcmp0 (selected, _("Toplevel folder"))) if (g_strcmp0 (selected, _("Toplevel folder")))
{ {
guint i, n; guint i = 0;
KatzeItem* item;
if ((n = katze_array_get_length (browser->bookmarks))) while ((item = katze_array_get_nth_item (browser->bookmarks, i++)))
for (i = 0; i < n; i++)
{
KatzeItem* item = katze_array_get_nth_item (browser->bookmarks, i);
if (KATZE_IS_ARRAY (item)) if (KATZE_IS_ARRAY (item))
if (!g_strcmp0 (katze_item_get_name (item), selected)) if (!g_strcmp0 (katze_item_get_name (item), selected))
{ {
@ -694,7 +691,6 @@ midori_browser_edit_bookmark_dialog_new (MidoriBrowser* browser,
break; break;
} }
} }
}
g_free (selected); g_free (selected);
if (!new_bookmark) if (!new_bookmark)
katze_array_remove_item (katze_item_get_parent (bookmark), bookmark); katze_array_remove_item (katze_item_get_parent (bookmark), bookmark);
@ -4527,7 +4523,7 @@ static void
midori_browser_set_bookmarks (MidoriBrowser* browser, midori_browser_set_bookmarks (MidoriBrowser* browser,
KatzeArray* bookmarks) KatzeArray* bookmarks)
{ {
guint i, n; guint i;
KatzeItem* item; KatzeItem* item;
if (browser->bookmarks == bookmarks) if (browser->bookmarks == bookmarks)
@ -4545,12 +4541,9 @@ midori_browser_set_bookmarks (MidoriBrowser* browser,
if (!browser->bookmarks) if (!browser->bookmarks)
return; return;
n = katze_array_get_length (browser->bookmarks); i = 0;
for (i = 0; i < n; i++) while ((item = katze_array_get_nth_item (browser->bookmarks, i++)))
{
item = katze_array_get_nth_item (browser->bookmarks, i);
browser_bookmarks_add_item_cb (browser->bookmarks, item, browser); browser_bookmarks_add_item_cb (browser->bookmarks, item, browser);
}
g_signal_connect (browser->bookmarks, "add-item", g_signal_connect (browser->bookmarks, "add-item",
G_CALLBACK (browser_bookmarks_add_item_cb), browser); G_CALLBACK (browser_bookmarks_add_item_cb), browser);
g_signal_connect (browser->bookmarks, "remove-item", g_signal_connect (browser->bookmarks, "remove-item",