Implement and use KATZE_ARRAY_FOREACH_ITEM

Iterating an array by a GList is considerably faster than
continuously retrieving items, however it is also a lot
more complicated. So the new macro takes care of that and
uses a new semi-private function to avoid copying the list.

Note that the macro can't be nested, which basically isn't
useful in practise anyway.
This commit is contained in:
Christian Dywan 2010-09-11 23:39:51 +02:00
parent db2c204b08
commit 40dc38fd21
29 changed files with 72 additions and 127 deletions

View file

@ -1367,7 +1367,6 @@ adblock_activate_cb (MidoriExtension* extension,
#endif #endif
KatzeArray* browsers; KatzeArray* browsers;
MidoriBrowser* browser; MidoriBrowser* browser;
guint i;
#if !HAVE_WEBKIT_RESOURCE_REQUEST #if !HAVE_WEBKIT_RESOURCE_REQUEST
SoupSession* session = webkit_get_default_session (); SoupSession* session = webkit_get_default_session ();
@ -1391,8 +1390,7 @@ adblock_activate_cb (MidoriExtension* extension,
adblock_reload_rules (extension, FALSE); adblock_reload_rules (extension, FALSE);
browsers = katze_object_get_object (app, "browsers"); browsers = katze_object_get_object (app, "browsers");
i = 0; KATZE_ARRAY_FOREACH_ITEM (browser, browsers)
while ((browser = katze_array_get_nth_item (browsers, i++)))
adblock_app_add_browser_cb (app, browser, extension); adblock_app_add_browser_cb (app, browser, extension);
g_signal_connect (app, "add-browser", g_signal_connect (app, "add-browser",
G_CALLBACK (adblock_app_add_browser_cb), extension); G_CALLBACK (adblock_app_add_browser_cb), extension);

View file

@ -1447,13 +1447,12 @@ addons_deactivate_cb (MidoriExtension* extension,
KatzeArray* browsers; KatzeArray* browsers;
MidoriBrowser* browser; MidoriBrowser* browser;
GSource* source; GSource* source;
guint i = 0;
addons_disable_monitors (extension); addons_disable_monitors (extension);
addons_save_settings (NULL, extension); addons_save_settings (NULL, extension);
browsers = katze_object_get_object (app, "browsers"); browsers = katze_object_get_object (app, "browsers");
while ((browser = katze_array_get_nth_item (browsers, i++))) KATZE_ARRAY_FOREACH_ITEM (browser, browsers)
addons_browser_destroy (browser, extension); addons_browser_destroy (browser, extension);
source = g_object_get_data (G_OBJECT (extension), "monitor-timer"); source = g_object_get_data (G_OBJECT (extension), "monitor-timer");
@ -1556,7 +1555,6 @@ addons_activate_cb (MidoriExtension* extension,
{ {
KatzeArray* browsers; KatzeArray* browsers;
MidoriBrowser* browser; MidoriBrowser* browser;
guint i;
browsers = katze_object_get_object (app, "browsers"); browsers = katze_object_get_object (app, "browsers");
addons_update_elements (extension, ADDONS_USER_STYLES); addons_update_elements (extension, ADDONS_USER_STYLES);
@ -1564,8 +1562,7 @@ addons_activate_cb (MidoriExtension* extension,
addons_update_elements (extension, ADDONS_USER_SCRIPTS); addons_update_elements (extension, ADDONS_USER_SCRIPTS);
addons_monitor_directories (extension, ADDONS_USER_SCRIPTS); addons_monitor_directories (extension, ADDONS_USER_SCRIPTS);
i = 0; KATZE_ARRAY_FOREACH_ITEM (browser, browsers)
while ((browser = katze_array_get_nth_item (browsers, i++)))
addons_app_add_browser_cb (app, browser, extension); addons_app_add_browser_cb (app, browser, extension);
g_object_unref (browsers); g_object_unref (browsers);

View file

@ -185,11 +185,9 @@ colorful_tabs_activate_cb (MidoriExtension* extension,
{ {
KatzeArray* browsers; KatzeArray* browsers;
MidoriBrowser* browser; MidoriBrowser* browser;
guint i;
browsers = katze_object_get_object (app, "browsers"); browsers = katze_object_get_object (app, "browsers");
i = 0; KATZE_ARRAY_FOREACH_ITEM (browser, browsers)
while ((browser = katze_array_get_nth_item (browsers, i++)))
colorful_tabs_app_add_browser_cb (app, browser, extension); colorful_tabs_app_add_browser_cb (app, browser, extension);
g_signal_connect (app, "add-browser", g_signal_connect (app, "add-browser",
G_CALLBACK (colorful_tabs_app_add_browser_cb), extension); G_CALLBACK (colorful_tabs_app_add_browser_cb), extension);

View file

@ -315,7 +315,6 @@ CookieManager *cookie_manager_new(MidoriExtension *extension, MidoriApp *app)
{ {
CookieManager *cm; CookieManager *cm;
CookieManagerPrivate *priv; CookieManagerPrivate *priv;
guint i;
KatzeArray *browsers; KatzeArray *browsers;
MidoriBrowser *browser; MidoriBrowser *browser;
@ -327,8 +326,7 @@ CookieManager *cookie_manager_new(MidoriExtension *extension, MidoriApp *app)
/* add the cookie manager panel page to existing browsers */ /* add the cookie manager panel page to existing browsers */
browsers = katze_object_get_object(app, "browsers"); browsers = katze_object_get_object(app, "browsers");
i = 0; KATZE_ARRAY_FOREACH_ITEM (browser, browsers)
while ((browser = katze_array_get_nth_item(browsers, i++)))
cookie_manager_app_add_browser_cb(app, browser, cm); cookie_manager_app_add_browser_cb(app, browser, cm);
g_object_unref(browsers); g_object_unref(browsers);

View file

@ -80,11 +80,9 @@ copy_tabs_activate_cb (MidoriExtension* extension,
{ {
KatzeArray* browsers; KatzeArray* browsers;
MidoriBrowser* browser; MidoriBrowser* browser;
guint i;
browsers = katze_object_get_object (app, "browsers"); browsers = katze_object_get_object (app, "browsers");
i = 0; KATZE_ARRAY_FOREACH_ITEM (browser, browsers)
while ((browser = katze_array_get_nth_item (browsers, i++)))
copy_tabs_app_add_browser_cb (app, browser, extension); copy_tabs_app_add_browser_cb (app, browser, extension);
g_object_unref (browsers); g_object_unref (browsers);
g_signal_connect (app, "add-browser", g_signal_connect (app, "add-browser",

View file

@ -271,7 +271,6 @@ feed_panel_disconnect_feed (FeedPanel* panel,
KatzeArray* feed) KatzeArray* feed)
{ {
KatzeItem* item; KatzeItem* item;
guint i;
g_return_if_fail (KATZE_IS_ARRAY (feed)); g_return_if_fail (KATZE_IS_ARRAY (feed));
@ -282,8 +281,7 @@ feed_panel_disconnect_feed (FeedPanel* panel,
g_signal_handlers_disconnect_by_func (feed, g_signal_handlers_disconnect_by_func (feed,
feed_panel_move_item_cb, panel); feed_panel_move_item_cb, panel);
i = 0; KATZE_ARRAY_FOREACH_ITEM (item, feed)
while ((item = katze_array_get_nth_item (feed, i++)))
{ {
if (KATZE_IS_ARRAY (item)) if (KATZE_IS_ARRAY (item))
feed_panel_disconnect_feed (panel, KATZE_ARRAY (item)); feed_panel_disconnect_feed (panel, KATZE_ARRAY (item));

View file

@ -157,18 +157,18 @@ feed_save_items (MidoriExtension* extension,
{ {
KatzeItem* item; KatzeItem* item;
gchar** sfeeds; gchar** sfeeds;
gint i; gint i, n;
gint n;
g_return_if_fail (KATZE_IS_ARRAY (feed)); g_return_if_fail (KATZE_IS_ARRAY (feed));
n = katze_array_get_length (feed); n = katze_array_get_length (feed);
sfeeds = g_new (gchar*, n + 1); sfeeds = g_new (gchar*, n + 1);
for (i = 0; i < n; i++) i = 0;
KATZE_ARRAY_FOREACH_ITEM (item, feed)
{ {
item = katze_array_get_nth_item (feed, i);
sfeeds[i] = (gchar*) katze_item_get_uri (KATZE_ITEM (item)); sfeeds[i] = (gchar*) katze_item_get_uri (KATZE_ITEM (item));
i++;
} }
sfeeds[n] = NULL; sfeeds[n] = NULL;
@ -498,11 +498,9 @@ feed_activate_cb (MidoriExtension* extension,
{ {
KatzeArray* browsers; KatzeArray* browsers;
MidoriBrowser* browser; MidoriBrowser* browser;
guint i;
browsers = katze_object_get_object (app, "browsers"); browsers = katze_object_get_object (app, "browsers");
i = 0; KATZE_ARRAY_FOREACH_ITEM (browser, browsers)
while ((browser = katze_array_get_nth_item (browsers, i++)))
feed_app_add_browser_cb (app, browser, extension); feed_app_add_browser_cb (app, browser, extension);
g_object_unref (browsers); g_object_unref (browsers);

View file

@ -425,7 +425,6 @@ formhistory_activate_cb (MidoriExtension* extension,
char* errmsg = NULL, *errmsg2 = NULL; char* errmsg = NULL, *errmsg2 = NULL;
KatzeArray* browsers; KatzeArray* browsers;
MidoriBrowser* browser; MidoriBrowser* browser;
guint i;
global_keys = g_hash_table_new_full (g_str_hash, g_str_equal, global_keys = g_hash_table_new_full (g_str_hash, g_str_equal,
(GDestroyNotify)g_free, (GDestroyNotify)g_free,
@ -464,8 +463,7 @@ formhistory_activate_cb (MidoriExtension* extension,
} }
browsers = katze_object_get_object (app, "browsers"); browsers = katze_object_get_object (app, "browsers");
i = 0; KATZE_ARRAY_FOREACH_ITEM (browser, browsers)
while ((browser = katze_array_get_nth_item (browsers, i++)))
formhistory_app_add_browser_cb (app, browser, extension); formhistory_app_add_browser_cb (app, browser, extension);
g_signal_connect (app, "add-browser", g_signal_connect (app, "add-browser",
G_CALLBACK (formhistory_app_add_browser_cb), extension); G_CALLBACK (formhistory_app_add_browser_cb), extension);

View file

@ -281,14 +281,12 @@ mouse_gestures_activate_cb (MidoriExtension* extension,
{ {
KatzeArray* browsers; KatzeArray* browsers;
MidoriBrowser* browser; MidoriBrowser* browser;
guint i;
gesture = mouse_gesture_new (); gesture = mouse_gesture_new ();
gesture->button = midori_extension_get_integer (extension, "button"); gesture->button = midori_extension_get_integer (extension, "button");
browsers = katze_object_get_object (app, "browsers"); browsers = katze_object_get_object (app, "browsers");
i = 0; KATZE_ARRAY_FOREACH_ITEM (browser, browsers)
while ((browser = katze_array_get_nth_item (browsers, i++)))
mouse_gestures_app_add_browser_cb (app, browser, extension); mouse_gestures_app_add_browser_cb (app, browser, extension);
g_signal_connect (app, "add-browser", g_signal_connect (app, "add-browser",
G_CALLBACK (mouse_gestures_app_add_browser_cb), extension); G_CALLBACK (mouse_gestures_app_add_browser_cb), extension);

View file

@ -139,11 +139,9 @@ page_holder_activate_cb (MidoriExtension* extension,
{ {
KatzeArray* browsers; KatzeArray* browsers;
MidoriBrowser* browser; MidoriBrowser* browser;
guint i;
browsers = katze_object_get_object (app, "browsers"); browsers = katze_object_get_object (app, "browsers");
i = 0; KATZE_ARRAY_FOREACH_ITEM (browser, browsers)
while ((browser = katze_array_get_nth_item (browsers, i++)))
page_holder_app_add_browser_cb (app, browser, extension); page_holder_app_add_browser_cb (app, browser, extension);
g_object_unref (browsers); g_object_unref (browsers);
g_signal_connect (app, "add-browser", g_signal_connect (app, "add-browser",

View file

@ -297,11 +297,9 @@ shortcuts_activate_cb (MidoriExtension* extension,
{ {
KatzeArray* browsers; KatzeArray* browsers;
MidoriBrowser* browser; MidoriBrowser* browser;
guint i;
browsers = katze_object_get_object (app, "browsers"); browsers = katze_object_get_object (app, "browsers");
i = 0; KATZE_ARRAY_FOREACH_ITEM (browser, browsers)
while ((browser = katze_array_get_nth_item (browsers, i++)))
shortcuts_app_add_browser_cb (app, browser, extension); shortcuts_app_add_browser_cb (app, browser, extension);
g_signal_connect (app, "add-browser", g_signal_connect (app, "add-browser",
G_CALLBACK (shortcuts_app_add_browser_cb), extension); G_CALLBACK (shortcuts_app_add_browser_cb), extension);

View file

@ -131,10 +131,9 @@ clock_deactivate_cb (MidoriExtension* extension,
KatzeArray* browsers; KatzeArray* browsers;
MidoriBrowser* browser; MidoriBrowser* browser;
GtkWidget* label; GtkWidget* label;
guint i = 0;
browsers = katze_object_get_object (app, "browsers"); browsers = katze_object_get_object (app, "browsers");
while ((browser = katze_array_get_nth_item (browsers, i++))) KATZE_ARRAY_FOREACH_ITEM (browser, browsers)
{ {
clock_browser_destroy_cb (browser, NULL); clock_browser_destroy_cb (browser, NULL);
label = g_object_get_data (G_OBJECT (browser), "clock-label"); label = g_object_get_data (G_OBJECT (browser), "clock-label");
@ -155,10 +154,9 @@ clock_activate_cb (MidoriExtension* extension,
{ {
KatzeArray* browsers; KatzeArray* browsers;
MidoriBrowser* browser; MidoriBrowser* browser;
guint i = 0;
browsers = katze_object_get_object (app, "browsers"); browsers = katze_object_get_object (app, "browsers");
while ((browser = katze_array_get_nth_item (browsers, i++))) KATZE_ARRAY_FOREACH_ITEM (browser, browsers)
clock_app_add_browser_cb (app, browser, extension); clock_app_add_browser_cb (app, browser, extension);
g_signal_connect (app, "add-browser", g_signal_connect (app, "add-browser",
G_CALLBACK (clock_app_add_browser_cb), extension); G_CALLBACK (clock_app_add_browser_cb), extension);

View file

@ -131,11 +131,9 @@ statusbar_features_activate_cb (MidoriExtension* extension,
{ {
KatzeArray* browsers; KatzeArray* browsers;
MidoriBrowser* browser; MidoriBrowser* browser;
guint i;
browsers = katze_object_get_object (app, "browsers"); browsers = katze_object_get_object (app, "browsers");
i = 0; KATZE_ARRAY_FOREACH_ITEM (browser, browsers)
while ((browser = katze_array_get_nth_item (browsers, i++)))
statusbar_features_app_add_browser_cb (app, browser, extension); statusbar_features_app_add_browser_cb (app, browser, extension);
g_signal_connect (app, "add-browser", g_signal_connect (app, "add-browser",
G_CALLBACK (statusbar_features_app_add_browser_cb), extension); G_CALLBACK (statusbar_features_app_add_browser_cb), extension);

View file

@ -590,11 +590,9 @@ tab_panel_activate_cb (MidoriExtension* extension,
{ {
KatzeArray* browsers; KatzeArray* browsers;
MidoriBrowser* browser; MidoriBrowser* browser;
guint i;
browsers = katze_object_get_object (app, "browsers"); browsers = katze_object_get_object (app, "browsers");
i = 0; KATZE_ARRAY_FOREACH_ITEM (browser, browsers)
while ((browser = katze_array_get_nth_item (browsers, i++)))
tab_panel_app_add_browser_cb (app, browser, extension); tab_panel_app_add_browser_cb (app, browser, extension);
g_object_unref (browsers); g_object_unref (browsers);
g_signal_connect (app, "add-browser", g_signal_connect (app, "add-browser",

View file

@ -61,11 +61,9 @@ tabs_minimized_activate_cb (MidoriExtension* extension,
{ {
KatzeArray* browsers; KatzeArray* browsers;
MidoriBrowser* browser; MidoriBrowser* browser;
guint i;
browsers = katze_object_get_object (app, "browsers"); browsers = katze_object_get_object (app, "browsers");
i = 0; KATZE_ARRAY_FOREACH_ITEM (browser, browsers)
while ((browser = katze_array_get_nth_item (browsers, i++)))
tabs_minimized_app_add_browser_cb (app, browser, extension); tabs_minimized_app_add_browser_cb (app, browser, extension);
g_object_unref (browsers); g_object_unref (browsers);
g_signal_connect (app, "add-browser", g_signal_connect (app, "add-browser",

View file

@ -592,11 +592,9 @@ static void tb_editor_activate_cb(MidoriExtension *extension, MidoriApp *app)
{ {
KatzeArray *browsers; KatzeArray *browsers;
MidoriBrowser *browser; MidoriBrowser *browser;
guint i;
browsers = katze_object_get_object(app, "browsers"); browsers = katze_object_get_object(app, "browsers");
i = 0; KATZE_ARRAY_FOREACH_ITEM (browser, browsers)
while ((browser = katze_array_get_nth_item(browsers, i++)))
tb_editor_app_add_browser_cb(app, browser, extension); tb_editor_app_add_browser_cb(app, browser, extension);
g_signal_connect(app, "add-browser", G_CALLBACK(tb_editor_app_add_browser_cb), extension); g_signal_connect(app, "add-browser", G_CALLBACK(tb_editor_app_add_browser_cb), extension);
g_object_unref(browsers); g_object_unref(browsers);

View file

@ -438,7 +438,6 @@ web_cache_activate_cb (MidoriExtension* extension,
const gchar* cache_path = midori_extension_get_string (extension, "path"); const gchar* cache_path = midori_extension_get_string (extension, "path");
KatzeArray* browsers; KatzeArray* browsers;
MidoriBrowser* browser; MidoriBrowser* browser;
guint i;
SoupSession* session = webkit_get_default_session (); SoupSession* session = webkit_get_default_session ();
katze_mkdir_with_parents (cache_path, 0700); katze_mkdir_with_parents (cache_path, 0700);
@ -446,8 +445,7 @@ web_cache_activate_cb (MidoriExtension* extension,
G_CALLBACK (web_cache_session_request_queued_cb), extension); G_CALLBACK (web_cache_session_request_queued_cb), extension);
browsers = katze_object_get_object (app, "browsers"); browsers = katze_object_get_object (app, "browsers");
i = 0; KATZE_ARRAY_FOREACH_ITEM (browser, browsers)
while ((browser = katze_array_get_nth_item (browsers, i++)))
web_cache_app_add_browser_cb (app, browser, extension); web_cache_app_add_browser_cb (app, browser, extension);
g_signal_connect (app, "add-browser", g_signal_connect (app, "add-browser",
G_CALLBACK (web_cache_app_add_browser_cb), extension); G_CALLBACK (web_cache_app_add_browser_cb), extension);

View file

@ -479,6 +479,12 @@ katze_array_get_items (KatzeArray* array)
return g_list_copy (array->items); return g_list_copy (array->items);
} }
GList*
katze_array_peek_items (KatzeArray* array)
{
return array->items;
}
/** /**
* katze_array_clear: * katze_array_clear:
* @array: a #KatzeArray * @array: a #KatzeArray

View file

@ -80,6 +80,17 @@ katze_array_move_item (KatzeArray* array,
GList* GList*
katze_array_get_items (KatzeArray* array); katze_array_get_items (KatzeArray* array);
GList*
katze_array_peek_items (KatzeArray* array);
GList* kalistglobal;
#define KATZE_ARRAY_FOREACH_ITEM(kaitem, kaarray) \
for (kalistglobal = katze_array_peek_items (kaarray), \
kaitem = kalistglobal ? kalistglobal->data : NULL; \
kalistglobal != NULL; \
kalistglobal = g_list_next (kalistglobal), \
kaitem = kalistglobal ? kalistglobal->data : NULL)
void void
katze_array_clear (KatzeArray* array); katze_array_clear (KatzeArray* array);

View file

@ -1136,9 +1136,8 @@ katze_bookmark_populate_tree_view (KatzeArray* array,
KatzeItem* child; KatzeItem* child;
GtkTreeIter iter; GtkTreeIter iter;
GtkTreeIter root_iter; GtkTreeIter root_iter;
guint i = 0;
while ((child = katze_array_get_nth_item (KATZE_ARRAY (array), i))) KATZE_ARRAY_FOREACH_ITEM (child, array)
{ {
if (KATZE_ITEM_IS_BOOKMARK (child)) if (KATZE_ITEM_IS_BOOKMARK (child))
{ {
@ -1155,7 +1154,6 @@ katze_bookmark_populate_tree_view (KatzeArray* array,
gtk_tree_store_insert_with_values (model, &iter, &root_iter, gtk_tree_store_insert_with_values (model, &iter, &root_iter,
0, 0, NULL, -1); 0, 0, NULL, -1);
} }
i++;
} }
} }

View file

@ -244,8 +244,7 @@ settings_save_to_file (MidoriWebSettings* settings,
if (extensions) if (extensions)
{ {
i = 0; KATZE_ARRAY_FOREACH_ITEM (extension, extensions)
while ((extension = katze_array_get_nth_item (extensions, i++)))
if (midori_extension_is_active (extension)) if (midori_extension_is_active (extension))
g_key_file_set_boolean (key_file, "extensions", g_key_file_set_boolean (key_file, "extensions",
g_object_get_data (G_OBJECT (extension), "filename"), TRUE); g_object_get_data (G_OBJECT (extension), "filename"), TRUE);
@ -315,7 +314,7 @@ search_engines_save_to_file (KatzeArray* search_engines,
GError** error) GError** error)
{ {
GKeyFile* key_file; GKeyFile* key_file;
guint i, j, n_properties; guint j, n_properties;
KatzeItem* item; KatzeItem* item;
const gchar* name; const gchar* name;
GParamSpec** pspecs; GParamSpec** pspecs;
@ -326,8 +325,7 @@ search_engines_save_to_file (KatzeArray* search_engines,
key_file = g_key_file_new (); key_file = g_key_file_new ();
pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (search_engines), pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (search_engines),
&n_properties); &n_properties);
i = 0; KATZE_ARRAY_FOREACH_ITEM (item, search_engines)
while ((item = katze_array_get_nth_item (search_engines, i++)))
{ {
name = katze_item_get_name (item); name = katze_item_get_name (item);
for (j = 0; j < n_properties; j++) for (j = 0; j < n_properties; j++)
@ -508,8 +506,7 @@ static void
midori_session_add_delay (KatzeArray* session) midori_session_add_delay (KatzeArray* session)
{ {
KatzeItem* item; KatzeItem* item;
gint i = 0; KATZE_ARRAY_FOREACH_ITEM (item, session)
while ((item = katze_array_get_nth_item (session, i++)))
katze_item_set_meta_integer (item, "delay", 1); katze_item_set_meta_integer (item, "delay", 1);
} }
@ -1196,9 +1193,8 @@ midori_browser_action_last_session_activate_cb (GtkAction* action,
GError* error = NULL; GError* error = NULL;
if (midori_array_from_file (old_session, config_file, "xbel", &error)) if (midori_array_from_file (old_session, config_file, "xbel", &error))
{ {
guint i = 0;
KatzeItem* item; KatzeItem* item;
while ((item = katze_array_get_nth_item (old_session, i++))) KATZE_ARRAY_FOREACH_ITEM (item, old_session)
midori_browser_add_item (browser, item); midori_browser_add_item (browser, item);
} }
else else
@ -1223,7 +1219,6 @@ midori_load_session (gpointer data)
gchar* config_file; gchar* config_file;
KatzeArray* session; KatzeArray* session;
KatzeItem* item; KatzeItem* item;
guint i;
gint64 current; gint64 current;
MidoriStartup load_on_startup; MidoriStartup load_on_startup;
gchar** command = g_object_get_data (G_OBJECT (app), "execute-command"); gchar** command = g_object_get_data (G_OBJECT (app), "execute-command");
@ -1277,8 +1272,7 @@ midori_load_session (gpointer data)
midori_session_add_delay (_session); midori_session_add_delay (_session);
session = midori_browser_get_proxy_array (browser); session = midori_browser_get_proxy_array (browser);
i = 0; KATZE_ARRAY_FOREACH_ITEM (item, _session)
while ((item = katze_array_get_nth_item (_session, i++)))
{ {
g_object_set_data (G_OBJECT (item), "midori-view-append", (void*)1); g_object_set_data (G_OBJECT (item), "midori-view-append", (void*)1);
midori_browser_add_item (browser, item); midori_browser_add_item (browser, item);
@ -2056,8 +2050,7 @@ main (int argc,
G_CALLBACK (midori_search_engines_modify_cb), search_engines); G_CALLBACK (midori_search_engines_modify_cb), search_engines);
if (!katze_array_is_empty (search_engines)) if (!katze_array_is_empty (search_engines))
{ {
i = 0; KATZE_ARRAY_FOREACH_ITEM (item, search_engines)
while ((item = katze_array_get_nth_item (search_engines, i++)))
g_signal_connect_after (item, "notify", g_signal_connect_after (item, "notify",
G_CALLBACK (midori_search_engines_modify_cb), search_engines); G_CALLBACK (midori_search_engines_modify_cb), search_engines);
} }

View file

@ -589,7 +589,6 @@ string_append_item (GString* string,
metadata = katze_item_metadata_to_xbel (item); metadata = katze_item_metadata_to_xbel (item);
if (KATZE_IS_ARRAY (item)) if (KATZE_IS_ARRAY (item))
{ {
guint i = 0;
KatzeItem* _item; KatzeItem* _item;
KatzeArray* array = KATZE_ARRAY (item); KatzeArray* array = KATZE_ARRAY (item);
@ -597,7 +596,7 @@ string_append_item (GString* string,
/* FIXME: " folded=\"no\" */ /* FIXME: " folded=\"no\" */
string_append_xml_element (string, "title", katze_item_get_name (item)); string_append_xml_element (string, "title", katze_item_get_name (item));
string_append_xml_element (string, "desc", katze_item_get_text (item)); string_append_xml_element (string, "desc", katze_item_get_text (item));
while ((_item = katze_array_get_nth_item (array, i++))) KATZE_ARRAY_FOREACH_ITEM (_item, array)
string_append_item (string, _item); string_append_item (string, _item);
g_string_append (string, metadata); g_string_append (string, metadata);
g_string_append (string, "</folder>\n"); g_string_append (string, "</folder>\n");
@ -679,7 +678,6 @@ katze_array_to_xbel (KatzeArray* array,
GError** error) GError** error)
{ {
gchar* metadata = katze_item_metadata_to_xbel (KATZE_ITEM (array)); gchar* metadata = katze_item_metadata_to_xbel (KATZE_ITEM (array));
guint i;
KatzeItem* item; KatzeItem* item;
GString* markup = g_string_new ( GString* markup = g_string_new (
@ -693,8 +691,7 @@ katze_array_to_xbel (KatzeArray* array,
string_append_xml_element (markup, "title", katze_item_get_name (KATZE_ITEM (array))); string_append_xml_element (markup, "title", katze_item_get_name (KATZE_ITEM (array)));
string_append_xml_element (markup, "desc", katze_item_get_text (KATZE_ITEM (array))); string_append_xml_element (markup, "desc", katze_item_get_text (KATZE_ITEM (array)));
g_string_append (markup, metadata); g_string_append (markup, metadata);
i = 0; KATZE_ARRAY_FOREACH_ITEM (item, array)
while ((item = katze_array_get_nth_item (array, i++)))
string_append_item (markup, item); string_append_item (markup, item);
g_string_append (markup, "</xbel>\n"); g_string_append (markup, "</xbel>\n");

View file

@ -3764,16 +3764,14 @@ midori_browser_bookmark_open_in_tab_activate_cb (GtkWidget* menuitem,
if (KATZE_IS_ARRAY (item)) if (KATZE_IS_ARRAY (item))
{ {
KatzeItem* child; KatzeItem* child;
guint i = 0;
while ((child = katze_array_get_nth_item (KATZE_ARRAY (item), i))) KATZE_ARRAY_FOREACH_ITEM (child, KATZE_ARRAY (item))
{ {
if ((uri = katze_item_get_uri (child)) && *uri) if ((uri = katze_item_get_uri (child)) && *uri)
{ {
n = midori_browser_add_item (browser, child); n = midori_browser_add_item (browser, child);
midori_browser_set_current_page_smartly (browser, n); midori_browser_set_current_page_smartly (browser, n);
} }
i++;
} }
} }
else else
@ -4016,8 +4014,7 @@ _action_bookmarks_import_activate (GtkAction* action,
db = g_object_get_data (G_OBJECT (browser->bookmarks), "db"); db = g_object_get_data (G_OBJECT (browser->bookmarks), "db");
sqlcmd = "SELECT title from bookmarks where uri=''"; sqlcmd = "SELECT title from bookmarks where uri=''";
bookmarkdirs = katze_array_from_sqlite (db, sqlcmd); bookmarkdirs = katze_array_from_sqlite (db, sqlcmd);
i = 0; KATZE_ARRAY_FOREACH_ITEM (item, bookmarkdirs)
while ((item = katze_array_get_nth_item (bookmarkdirs, i++)))
{ {
const gchar* name = katze_item_get_name (item); const gchar* name = katze_item_get_name (item);
gtk_combo_box_append_text (combobox_folder, name); gtk_combo_box_append_text (combobox_folder, name);
@ -6145,16 +6142,13 @@ _midori_browser_update_settings (MidoriBrowser* browser)
if (browser->search_engines) if (browser->search_engines)
{ {
guint i;
item = katze_array_get_nth_item (browser->search_engines, item = katze_array_get_nth_item (browser->search_engines,
last_web_search); last_web_search);
if (item) if (item)
midori_search_action_set_current_item (MIDORI_SEARCH_ACTION ( midori_search_action_set_current_item (MIDORI_SEARCH_ACTION (
_action_by_name (browser, "Search")), item); _action_by_name (browser, "Search")), item);
i = 0; KATZE_ARRAY_FOREACH_ITEM (item, browser->search_engines)
while ((item = katze_array_get_nth_item (browser->search_engines, i++)))
if (!g_strcmp0 (katze_item_get_uri (item), browser->location_entry_search)) if (!g_strcmp0 (katze_item_get_uri (item), browser->location_entry_search))
{ {
midori_search_action_set_default_item (MIDORI_SEARCH_ACTION ( midori_search_action_set_default_item (MIDORI_SEARCH_ACTION (
@ -6330,7 +6324,6 @@ midori_bookmarkbar_populate (MidoriBrowser* browser)
const gchar* sqlcmd; const gchar* sqlcmd;
KatzeArray* array; KatzeArray* array;
KatzeItem* item; KatzeItem* item;
gint i = 0;
midori_bookmarkbar_clear (browser->bookmarkbar); midori_bookmarkbar_clear (browser->bookmarkbar);
@ -6353,7 +6346,7 @@ midori_bookmarkbar_populate (MidoriBrowser* browser)
return; return;
} }
while ((item = katze_array_get_nth_item (KATZE_ARRAY (array), i))) KATZE_ARRAY_FOREACH_ITEM (item, array)
{ {
if (KATZE_ITEM_IS_BOOKMARK (item)) if (KATZE_ITEM_IS_BOOKMARK (item))
midori_bookmarkbar_insert_item (browser->bookmarkbar, item); midori_bookmarkbar_insert_item (browser->bookmarkbar, item);
@ -6369,7 +6362,6 @@ midori_bookmarkbar_populate (MidoriBrowser* browser)
midori_bookmarkbar_insert_item (browser->bookmarkbar, KATZE_ITEM (subfolder)); midori_bookmarkbar_insert_item (browser->bookmarkbar, KATZE_ITEM (subfolder));
g_free (subsqlcmd); g_free (subsqlcmd);
} }
i++;
} }
_action_set_sensitive (browser, "BookmarkAdd", TRUE); _action_set_sensitive (browser, "BookmarkAdd", TRUE);
_action_set_sensitive (browser, "BookmarkFolderAdd", TRUE); _action_set_sensitive (browser, "BookmarkFolderAdd", TRUE);
@ -6476,8 +6468,6 @@ midori_browser_set_property (GObject* object,
break; break;
case PROP_SEARCH_ENGINES: case PROP_SEARCH_ENGINES:
{ {
guint i;
/* FIXME: Disconnect handlers */ /* FIXME: Disconnect handlers */
katze_object_assign (browser->search_engines, g_value_dup_object (value)); katze_object_assign (browser->search_engines, g_value_dup_object (value));
if (katze_object_get_boolean (browser->settings, if (katze_object_get_boolean (browser->settings,
@ -6498,8 +6488,7 @@ midori_browser_set_property (GObject* object,
midori_search_action_set_current_item (MIDORI_SEARCH_ACTION ( midori_search_action_set_current_item (MIDORI_SEARCH_ACTION (
_action_by_name (browser, "Search")), item); _action_by_name (browser, "Search")), item);
i = 0; KATZE_ARRAY_FOREACH_ITEM (item, browser->search_engines)
while ((item = katze_array_get_nth_item (browser->search_engines, i++)))
if (!g_strcmp0 (katze_item_get_uri (item), browser->location_entry_search)) if (!g_strcmp0 (katze_item_get_uri (item), browser->location_entry_search))
{ {
midori_search_action_set_default_item (MIDORI_SEARCH_ACTION ( midori_search_action_set_default_item (MIDORI_SEARCH_ACTION (

View file

@ -486,9 +486,9 @@ midori_location_action_popup_timeout_cb (gpointer data)
if (action->search_engines) if (action->search_engines)
{ {
gint i = 0;
KatzeItem* item; KatzeItem* item;
while ((item = katze_array_get_nth_item (action->search_engines, i))) i = 0;
KATZE_ARRAY_FOREACH_ITEM (item, action->search_engines)
{ {
gchar* uri; gchar* uri;
gchar* title; gchar* title;

View file

@ -436,7 +436,6 @@ midori_search_action_icon_released_cb (GtkWidget* entry,
{ {
KatzeArray* search_engines; KatzeArray* search_engines;
GtkWidget* menu; GtkWidget* menu;
guint i;
GtkWidget* menuitem; GtkWidget* menuitem;
KatzeItem* item; KatzeItem* item;
GdkPixbuf* icon; GdkPixbuf* icon;
@ -447,10 +446,9 @@ midori_search_action_icon_released_cb (GtkWidget* entry,
search_engines = MIDORI_SEARCH_ACTION (action)->search_engines; search_engines = MIDORI_SEARCH_ACTION (action)->search_engines;
menu = gtk_menu_new (); menu = gtk_menu_new ();
i = 0; if (!katze_array_is_empty (search_engines))
if ((item = katze_array_get_nth_item (search_engines, i)))
{ {
do KATZE_ARRAY_FOREACH_ITEM (item, search_engines)
{ {
const gchar* icon_name; const gchar* icon_name;
@ -477,7 +475,6 @@ midori_search_action_icon_released_cb (GtkWidget* entry,
G_CALLBACK (midori_search_action_engine_activate_cb), action); G_CALLBACK (midori_search_action_engine_activate_cb), action);
gtk_widget_show (menuitem); gtk_widget_show (menuitem);
} }
while ((item = katze_array_get_nth_item (search_engines, ++i)));
} }
else else
{ {
@ -1304,7 +1301,7 @@ midori_search_action_get_dialog (MidoriSearchAction* search_action)
gtk_box_pack_start (GTK_BOX (hbox), scrolled, TRUE, TRUE, 5); gtk_box_pack_start (GTK_BOX (hbox), scrolled, TRUE, TRUE, 5);
i = 0; i = 0;
if (search_action->search_engines) if (search_action->search_engines)
while ((item = katze_array_get_nth_item (search_action->search_engines, i))) KATZE_ARRAY_FOREACH_ITEM (item, search_action->search_engines)
gtk_list_store_insert_with_values (GTK_LIST_STORE (liststore), gtk_list_store_insert_with_values (GTK_LIST_STORE (liststore),
NULL, i++, 0, item, -1); NULL, i++, 0, item, -1);
g_object_unref (liststore); g_object_unref (liststore);

View file

@ -2226,7 +2226,7 @@ midori_view_populate_popup (MidoriView* view,
gtk_menu_shell_insert (menu_shell, menuitem, 1); gtk_menu_shell_insert (menu_shell, menuitem, 1);
search_engines = katze_object_get_object (window, "search-engines"); search_engines = katze_object_get_object (window, "search-engines");
while ((item = katze_array_get_nth_item (search_engines, i++))) KATZE_ARRAY_FOREACH_ITEM (item, search_engines)
{ {
GdkPixbuf* pixbuf; GdkPixbuf* pixbuf;
const gchar* icon_name; const gchar* icon_name;
@ -2246,11 +2246,12 @@ midori_view_populate_popup (MidoriView* view,
gtk_image_menu_item_set_always_show_image ( gtk_image_menu_item_set_always_show_image (
GTK_IMAGE_MENU_ITEM (menuitem), TRUE); GTK_IMAGE_MENU_ITEM (menuitem), TRUE);
#endif #endif
gtk_menu_shell_insert (GTK_MENU_SHELL (sub_menu), menuitem, i - 1); gtk_menu_shell_insert (GTK_MENU_SHELL (sub_menu), menuitem, i);
g_object_set_data (G_OBJECT (menuitem), "search", g_object_set_data (G_OBJECT (menuitem), "search",
(gchar*)katze_item_get_uri (item)); (gchar*)katze_item_get_uri (item));
g_signal_connect (menuitem, "activate", g_signal_connect (menuitem, "activate",
G_CALLBACK (midori_web_view_menu_search_web_activate_cb), view); G_CALLBACK (midori_web_view_menu_search_web_activate_cb), view);
i++;
} }
g_object_unref (search_engines); g_object_unref (search_engines);
} }

View file

@ -131,13 +131,12 @@ midori_bookmarks_export_array_db (sqlite3* db,
KatzeArray* root_array; KatzeArray* root_array;
KatzeArray* subarray; KatzeArray* subarray;
KatzeItem* item; KatzeItem* item;
int i = 0;
sqlcmd = g_strdup_printf ("SELECT * FROM bookmarks where folder='%s'", folder); sqlcmd = g_strdup_printf ("SELECT * FROM bookmarks where folder='%s'", folder);
root_array = katze_array_from_sqlite (db, sqlcmd); root_array = katze_array_from_sqlite (db, sqlcmd);
g_free (sqlcmd); g_free (sqlcmd);
while ((item = katze_array_get_nth_item (KATZE_ARRAY (root_array), i++))) KATZE_ARRAY_FOREACH_ITEM (item, root_array)
{ {
if (KATZE_ITEM_IS_FOLDER (item)) if (KATZE_ITEM_IS_FOLDER (item))
{ {
@ -156,17 +155,12 @@ midori_bookmarks_import_array_db (sqlite3* db,
KatzeArray* array, KatzeArray* array,
const gchar* folder) const gchar* folder)
{ {
GList* list = NULL;
GList* bookmarks;
bookmarks = katze_array_get_items ((KatzeArray*)array);
for (list = bookmarks; list != NULL; list = g_list_next (list))
{
KatzeItem* item; KatzeItem* item;
if (KATZE_IS_ARRAY (list->data)) KATZE_ARRAY_FOREACH_ITEM (item, array)
midori_bookmarks_import_array_db (db, list->data, folder); {
item = (KatzeItem*) list->data; if (KATZE_IS_ARRAY (item))
midori_bookmarks_import_array_db (db, KATZE_ARRAY (item), folder);
midori_bookmarks_insert_item_db (db, item, folder); midori_bookmarks_insert_item_db (db, item, folder);
} }
} }
@ -660,11 +654,10 @@ midori_bookmarks_open_in_tab_activate_cb (GtkWidget* menuitem,
{ {
KatzeItem* child; KatzeItem* child;
KatzeArray* array; KatzeArray* array;
guint i = 0;
array = midori_bookmarks_read_from_db (bookmarks, katze_item_get_name (item), NULL); array = midori_bookmarks_read_from_db (bookmarks, katze_item_get_name (item), NULL);
g_return_if_fail (KATZE_IS_ARRAY (array)); g_return_if_fail (KATZE_IS_ARRAY (array));
while ((child = katze_array_get_nth_item (KATZE_ARRAY (array), i))) KATZE_ARRAY_FOREACH_ITEM (child, array)
{ {
if ((uri = katze_item_get_uri (child)) && *uri) if ((uri = katze_item_get_uri (child)) && *uri)
{ {
@ -674,7 +667,6 @@ midori_bookmarks_open_in_tab_activate_cb (GtkWidget* menuitem,
n = midori_browser_add_item (browser, child); n = midori_browser_add_item (browser, child);
midori_browser_set_current_page_smartly (browser, n); midori_browser_set_current_page_smartly (browser, n);
} }
i++;
} }
} }
else if ((uri = katze_item_get_uri (item)) && *uri) else if ((uri = katze_item_get_uri (item)) && *uri)

View file

@ -167,7 +167,6 @@ midori_extensions_set_property (GObject* object,
{ {
KatzeArray* array; KatzeArray* array;
MidoriExtension* extension; MidoriExtension* extension;
guint i;
/* FIXME: Handle NULL and subsequent assignments */ /* FIXME: Handle NULL and subsequent assignments */
extensions->app = g_value_get_object (value); extensions->app = g_value_get_object (value);
@ -175,8 +174,7 @@ midori_extensions_set_property (GObject* object,
g_signal_connect (array, "add-item", g_signal_connect (array, "add-item",
G_CALLBACK (midori_extensions_add_item_cb), extensions); G_CALLBACK (midori_extensions_add_item_cb), extensions);
i = 0; KATZE_ARRAY_FOREACH_ITEM (extension, array)
while ((extension = katze_array_get_nth_item (array, i++)))
midori_extensions_add_item_cb (array, extension, extensions); midori_extensions_add_item_cb (array, extension, extensions);
/* Hide if there are no extensions at all */ /* Hide if there are no extensions at all */
@ -379,10 +377,9 @@ midori_extensions_finalize (GObject* object)
{ {
MidoriExtensions* extensions = MIDORI_EXTENSIONS (object); MidoriExtensions* extensions = MIDORI_EXTENSIONS (object);
KatzeArray* array = katze_object_get_object (extensions->app, "extensions"); KatzeArray* array = katze_object_get_object (extensions->app, "extensions");
guint i = 0;
MidoriExtension* extension; MidoriExtension* extension;
while ((extension = katze_array_get_nth_item (array, i++))) KATZE_ARRAY_FOREACH_ITEM (extension, array)
{ {
g_signal_handlers_disconnect_by_func (extension, g_signal_handlers_disconnect_by_func (extension,
midori_extensions_extension_activate_cb, extensions); midori_extensions_extension_activate_cb, extensions);

View file

@ -668,7 +668,6 @@ midori_history_open_in_tab_activate_cb (GtkWidget* menuitem,
gchar* sqlcmd; gchar* sqlcmd;
KatzeItem* child; KatzeItem* child;
KatzeArray* array; KatzeArray* array;
guint i = 0;
db = g_object_get_data (G_OBJECT (history->array), "db"); db = g_object_get_data (G_OBJECT (history->array), "db");
sqlcmd = g_strdup_printf ("SELECT uri, title, date, day " sqlcmd = g_strdup_printf ("SELECT uri, title, date, day "
@ -677,7 +676,7 @@ midori_history_open_in_tab_activate_cb (GtkWidget* menuitem,
(int)katze_item_get_added (item)); (int)katze_item_get_added (item));
array = katze_array_from_sqlite (db, sqlcmd); array = katze_array_from_sqlite (db, sqlcmd);
g_free (sqlcmd); g_free (sqlcmd);
while ((child = katze_array_get_nth_item (KATZE_ARRAY (array), i++))) KATZE_ARRAY_FOREACH_ITEM (child, KATZE_ARRAY (array))
{ {
if ((uri = katze_item_get_uri (child)) && *uri) if ((uri = katze_item_get_uri (child)) && *uri)
{ {