From 58166e645971a4812fef23702f45cacc8e64e419 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Sat, 24 Oct 2009 17:55:54 -0400 Subject: Prefer G_N_ELEMENTS over sizeof calculations. --- addressbook/gui/widgets/e-minicard-view.c | 3 +-- addressbook/importers/evolution-ldif-importer.c | 3 +-- calendar/gui/dialogs/recurrence-page.c | 6 +++--- calendar/gui/e-day-view-time-item.c | 3 +-- calendar/gui/e-day-view.c | 13 ++++++------- e-util/e-error.c | 6 +++--- em-format/em-format-quote.c | 2 +- em-format/em-format.c | 4 ++-- filter/filter-datespec.c | 3 +-- mail/e-searching-tokenizer.c | 2 +- mail/em-account-editor.c | 14 ++++++-------- mail/em-folder-properties.c | 4 ++-- mail/em-format-html-display.c | 4 ++-- mail/em-vfolder-rule.c | 4 ++-- mail/message-list.c | 8 ++++---- mail/message-tag-followup.c | 4 +--- modules/mail/e-mail-shell-migrate.c | 2 +- modules/mail/em-mailer-prefs.c | 2 +- modules/mail/em-network-prefs.c | 2 +- plugins/prefer-plain/prefer-plain.c | 4 ++-- smime/lib/e-cert.c | 2 +- widgets/misc/test-calendar.c | 4 +--- widgets/table/e-table-click-to-add.c | 2 -- widgets/table/e-table-field-chooser-item.c | 4 +--- widgets/table/e-table-header-item.c | 5 ++--- 25 files changed, 47 insertions(+), 63 deletions(-) diff --git a/addressbook/gui/widgets/e-minicard-view.c b/addressbook/gui/widgets/e-minicard-view.c index 5f16ac9a56..cca537d65e 100644 --- a/addressbook/gui/widgets/e-minicard-view.c +++ b/addressbook/gui/widgets/e-minicard-view.c @@ -74,7 +74,6 @@ static GtkTargetEntry drag_types[] = { { (gchar *) SOURCE_VCARD_LIST_TYPE, 0, DND_TARGET_TYPE_SOURCE_VCARD_LIST }, { (gchar *) VCARD_LIST_TYPE, 0, DND_TARGET_TYPE_VCARD_LIST } }; -static gint num_drag_types = sizeof(drag_types) / sizeof(drag_types[0]); static void e_minicard_view_drag_data_get(GtkWidget *widget, @@ -138,7 +137,7 @@ e_minicard_view_drag_begin (EAddressbookReflowAdapter *adapter, GdkEvent *event, g_print ("dragging %d card(s)\n", g_list_length (view->drag_list)); - target_list = gtk_target_list_new (drag_types, num_drag_types); + target_list = gtk_target_list_new (drag_types, G_N_ELEMENTS (drag_types)); context = gtk_drag_begin (GTK_WIDGET (GNOME_CANVAS_ITEM (view)->canvas), target_list, actions, 1/*XXX*/, event); diff --git a/addressbook/importers/evolution-ldif-importer.c b/addressbook/importers/evolution-ldif-importer.c index efc4a2bf71..1e6461a631 100644 --- a/addressbook/importers/evolution-ldif-importer.c +++ b/addressbook/importers/evolution-ldif-importer.c @@ -127,7 +127,6 @@ ldif_fields[] = { { "nsAIMid", E_CONTACT_IM_AIM, FLAG_LIST }, { "mozilla_AimScreenName", E_CONTACT_IM_AIM, FLAG_LIST } }; -static gint num_ldif_fields = sizeof(ldif_fields) / sizeof (ldif_fields[0]); static GString * getValue( gchar **src ) @@ -267,7 +266,7 @@ parseLine (LDIFImporter *gci, EContact *contact, ldif_value = getValue(&value ); field_handled = FALSE; - for (i = 0; i < num_ldif_fields; i ++) { + for (i = 0; i < G_N_ELEMENTS (ldif_fields); i ++) { if (!g_ascii_strcasecmp (ptr, ldif_fields[i].ldif_attribute)) { if (ldif_fields[i].flags & FLAG_WORK_ADDRESS) { populate_contact_address (work_address, ptr, ldif_value->str); diff --git a/calendar/gui/dialogs/recurrence-page.c b/calendar/gui/dialogs/recurrence-page.c index a94fe9e37f..8b341f5bc8 100644 --- a/calendar/gui/dialogs/recurrence-page.c +++ b/calendar/gui/dialogs/recurrence-page.c @@ -1050,7 +1050,7 @@ make_recur_month_num_combo (gint month_index) store = gtk_tree_store_new (2, G_TYPE_STRING, G_TYPE_INT); /* Relation */ - for (i = 0; i < sizeof (options) / sizeof (options[0]); i++) { + for (i = 0; i < G_N_ELEMENTS (options); i++) { gtk_tree_store_append (store, &iter, NULL); gtk_tree_store_set (store, &iter, 0, _(options [i]), 1, month_num_options_map [i], -1); } @@ -1120,7 +1120,7 @@ make_recur_month_combobox (void) combo = gtk_combo_box_new_text (); - for (i = 0; i < sizeof (options) / sizeof (options[0]); i++) { + for (i = 0; i < G_N_ELEMENTS (options); i++) { gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _(options[i])); } @@ -1635,7 +1635,7 @@ recurrence_page_fill_widgets (CompEditorPage *page, ECalComponent *comp) /* Any funky shit? */ -#define N_HAS_BY(field) (count_by_xxx (field, sizeof (field) / sizeof (field[0]))) +#define N_HAS_BY(field) (count_by_xxx (field, G_N_ELEMENTS (field))) n_by_second = N_HAS_BY (r->by_second); n_by_minute = N_HAS_BY (r->by_minute); diff --git a/calendar/gui/e-day-view-time-item.c b/calendar/gui/e-day-view-time-item.c index 5068ed47e0..ff0f6406a4 100644 --- a/calendar/gui/e-day-view-time-item.c +++ b/calendar/gui/e-day-view-time-item.c @@ -733,7 +733,6 @@ e_day_view_time_item_show_popup_menu (EDayViewTimeItem *time_item, { static gint divisions[] = { 60, 30, 15, 10, 5 }; EDayView *day_view; - gint num_divisions = sizeof (divisions) / sizeof (divisions[0]); GtkWidget *menu, *item, *submenu; gchar buffer[256]; GSList *group = NULL, *recent_zones, *s; @@ -752,7 +751,7 @@ e_day_view_time_item_show_popup_menu (EDayViewTimeItem *time_item, menu, "selection-done", G_CALLBACK (gtk_widget_destroy), NULL); - for (i = 0; i < num_divisions; i++) { + for (i = 0; i < G_N_ELEMENTS (divisions); i++) { g_snprintf (buffer, sizeof (buffer), /* TO TRANSLATORS: %02i is the number of minutes; this is a context menu entry * to change the length of the time division in the calendar day view, e.g. diff --git a/calendar/gui/e-day-view.c b/calendar/gui/e-day-view.c index af6fdc66e7..46a37ddc46 100644 --- a/calendar/gui/e-day-view.c +++ b/calendar/gui/e-day-view.c @@ -112,7 +112,6 @@ static GtkTargetEntry target_table[] = { { (gchar *) "text/x-calendar", 0, TARGET_VCALENDAR }, { (gchar *) "text/calendar", 0, TARGET_VCALENDAR } }; -static guint n_targets = sizeof(target_table) / sizeof(target_table[0]); static void e_day_view_destroy (GtkObject *object); static void e_day_view_realize (GtkWidget *widget); @@ -1336,11 +1335,11 @@ e_day_view_init (EDayView *day_view) /* Set up the drop sites. */ gtk_drag_dest_set (day_view->top_canvas, GTK_DEST_DEFAULT_ALL, - target_table, n_targets, + target_table, G_N_ELEMENTS (target_table), GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_ASK); gtk_drag_dest_set (day_view->main_canvas, GTK_DEST_DEFAULT_ALL, - target_table, n_targets, + target_table, G_N_ELEMENTS (target_table), GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_ASK); /* connect to ECalendarView's signals */ @@ -3927,8 +3926,8 @@ e_day_view_on_top_canvas_motion (GtkWidget *widget, day_view->resize_bars_event_num = -1; } - target_list = gtk_target_list_new (target_table, - n_targets); + target_list = gtk_target_list_new ( + target_table, G_N_ELEMENTS (target_table)); gtk_drag_begin (widget, target_list, GDK_ACTION_COPY | GDK_ACTION_MOVE, 1, (GdkEvent*)mevent); @@ -4030,8 +4029,8 @@ e_day_view_on_main_canvas_motion (GtkWidget *widget, day_view->resize_bars_event_num = -1; } - target_list = gtk_target_list_new (target_table, - n_targets); + target_list = gtk_target_list_new ( + target_table, G_N_ELEMENTS (target_table)); gtk_drag_begin (widget, target_list, GDK_ACTION_COPY | GDK_ACTION_MOVE, 1, (GdkEvent*)mevent); diff --git a/e-util/e-error.c b/e-util/e-error.c index e31b7732d8..049e090fdc 100644 --- a/e-util/e-error.c +++ b/e-util/e-error.c @@ -102,7 +102,7 @@ map_response(const gchar *name) { gint i; - for (i=0;idomain = "builtin"; table->errors = g_hash_table_new(g_str_hash, g_str_equal); - for (i=0;ierrors, (gpointer) default_errors[i].id, &default_errors[i]); g_hash_table_insert(error_table, (gpointer) table->domain, table); diff --git a/em-format/em-format-quote.c b/em-format/em-format-quote.c index c329769976..05fefa02e6 100644 --- a/em-format/em-format-quote.c +++ b/em-format/em-format-quote.c @@ -588,6 +588,6 @@ emfq_builtin_init(EMFormatQuoteClass *efhc) { gint i; - for (i=0;itype_handlers, type_builtin_table[i].mime_type, &type_builtin_table[i]); } diff --git a/filter/filter-datespec.c b/filter/filter-datespec.c index 5d1e573f9b..a0e981d111 100644 --- a/filter/filter-datespec.c +++ b/filter/filter-datespec.c @@ -91,7 +91,6 @@ static const timespan timespans[] = { #undef ngettext #define DAY_INDEX 3 -#define N_TIMESPANS (sizeof (timespans) / sizeof (timespans[0])) struct _FilterDatespecPrivate { GtkWidget *label_button; @@ -264,7 +263,7 @@ get_best_span (time_t val) { gint i; - for (i=N_TIMESPANS-1;i>=0;i--) { + for (i=G_N_ELEMENTS (timespans)-1;i>=0;i--) { if (val % timespans[i].seconds == 0) return i; } diff --git a/mail/e-searching-tokenizer.c b/mail/e-searching-tokenizer.c index aac8a0a34f..4a3b6a9bac 100644 --- a/mail/e-searching-tokenizer.c +++ b/mail/e-searching-tokenizer.c @@ -122,7 +122,7 @@ ignore_tag (const gchar *tag) } *out = 0; - for (i=0;iprovider, info->flag); show = (enable && !hide)?gtk_widget_show:gtk_widget_hide; - for (j=0; j < sizeof (info->widgets)/sizeof (info->widgets[0]); j++) { + for (j=0; j < G_N_ELEMENTS (info->widgets); j++) { if (info->widgets[j] && (w = G_STRUCT_MEMBER(GtkWidget *, service, info->widgets[j]))) { show (w); if (j == 0) { @@ -1777,7 +1775,7 @@ emae_refresh_providers (EMAccountEditor *emae, EMAccountEditorService *service) tmp = camel_url_get_param (url, "use_ssl"); if (tmp == NULL) tmp = "never"; - for (i=0;iuse_ssl, i); break; @@ -2018,7 +2016,7 @@ emae_setup_service (EMAccountEditor *emae, EMAccountEditorService *service, Glad if (tmp == NULL) tmp = "never"; - for (i=0;iuse_ssl, i); break; @@ -2152,7 +2150,7 @@ emae_queue_widgets (EMAccountEditor *emae, GladeXML *xml, const gchar *first, .. } va_end (ap); - g_return_if_fail (i < sizeof (emae->priv->widgets)/sizeof (emae->priv->widgets[0])); + g_return_if_fail (i < G_N_ELEMENTS (emae->priv->widgets)); emae->priv->widgets[i] = NULL; emae->priv->widgets_index = 0; @@ -2181,7 +2179,7 @@ emae_identity_page (EConfig *ec, EConfigItem *item, GtkWidget *parent, GtkWidget g_free (gladefile); /* Management & Identity fields, in the assistant the management frame is relocated to the last page later on */ - for (i=0;iidentity_entries[i] = emae_account_entry (emae, emae_identity_entries[i].name, emae_identity_entries[i].item, xml); gui->management_frame = glade_xml_get_widget (xml, "management_frame"); diff --git a/mail/em-folder-properties.c b/mail/em-folder-properties.c index a7236e66dd..7b7957149c 100644 --- a/mail/em-folder-properties.c +++ b/mail/em-folder-properties.c @@ -357,7 +357,7 @@ emfp_dialog_got_folder_quota (CamelFolder *folder, || !strcmp(prop_data->name, "Sent"))) { emfp_items[EMFP_FOLDER_SECTION].label = _(prop_data->name); if (!emfp_items_translated) { - for (i=0;iconfig = ec; l = NULL; - for (i=0;ixml_encode(fr); g_return_val_if_fail (node != NULL, NULL); - g_return_val_if_fail (vr->with < sizeof(with_names)/sizeof(with_names[0]), NULL); + g_return_val_if_fail (vr->with < G_N_ELEMENTS (with_names), NULL); set = xmlNewNode(NULL, (const guchar *)"sources"); xmlAddChild(node, set); @@ -279,7 +279,7 @@ set_with(EMVFolderRule *vr, const gchar *name) { gint i; - for (i=0;iwith = i; return; diff --git a/mail/message-list.c b/mail/message-list.c index c45dbf3437..90c0812aff 100644 --- a/mail/message-list.c +++ b/mail/message-list.c @@ -2213,7 +2213,7 @@ ml_tree_drag_motion(ETree *tree, GdkDragContext *context, gint x, gint y, guint gint i; d(printf("atom drop '%s'\n", gdk_atom_name(targets->data))); - for (i=0;idata == (gpointer)ml_drag_info[i].atom) actions |= ml_drag_info[i].actions; } @@ -2488,7 +2488,7 @@ message_list_class_init (MessageListClass *class) GtkObjectClass *gtk_object_class; gint i; - for (i=0;itree, GDK_BUTTON1_MASK, - ml_drag_types, sizeof(ml_drag_types)/sizeof(ml_drag_types[0]), + ml_drag_types, G_N_ELEMENTS (ml_drag_types), GDK_ACTION_MOVE|GDK_ACTION_COPY); g_signal_connect(message_list->tree, "tree_drag_data_get", G_CALLBACK(ml_tree_drag_data_get), message_list); e_tree_drag_dest_set(message_list->tree, GTK_DEST_DEFAULT_ALL, - ml_drop_types, sizeof(ml_drop_types)/sizeof(ml_drop_types[0]), + ml_drop_types, G_N_ELEMENTS (ml_drop_types), GDK_ACTION_MOVE|GDK_ACTION_COPY); g_signal_connect(message_list->tree, "tree_drag_data_received", diff --git a/mail/message-tag-followup.c b/mail/message-tag-followup.c index 5141387b01..b9ae183f6b 100644 --- a/mail/message-tag-followup.c +++ b/mail/message-tag-followup.c @@ -64,8 +64,6 @@ static const gchar *available_flags[] = { N_("Review"), }; -static gint num_available_flags = sizeof (available_flags) / sizeof (available_flags[0]); - static MessageTagEditorClass *parent_class = NULL; GType @@ -307,7 +305,7 @@ construct (MessageTagEditor *editor) followup->combo_entry = GTK_COMBO_BOX (glade_xml_get_widget (gui, "combo")); gtk_list_store_clear (GTK_LIST_STORE (gtk_combo_box_get_model (followup->combo_entry))); - for (i = 0; i < num_available_flags; i++) + for (i = 0; i < G_N_ELEMENTS (available_flags); i++) gtk_combo_box_append_text (followup->combo_entry, (gchar *) _(available_flags[i])); gtk_combo_box_set_active (followup->combo_entry, DEFAULT_FLAG); diff --git a/modules/mail/e-mail-shell-migrate.c b/modules/mail/e-mail-shell-migrate.c index 967f80053f..43cd1a5185 100644 --- a/modules/mail/e-mail-shell-migrate.c +++ b/modules/mail/e-mail-shell-migrate.c @@ -1670,7 +1670,7 @@ em_migrate_folder(EMMigrateSession *session, const gchar *dirname, const gchar * } /* copy over the metadata files */ - for (i = 0; i < sizeof(meta_ext)/sizeof(meta_ext[0]); i++) { + for (i = 0; i < G_N_ELEMENTS (meta_ext); i++) { g_string_truncate (src, slen); g_string_truncate (dest, dlen); diff --git a/modules/mail/em-mailer-prefs.c b/modules/mail/em-mailer-prefs.c index 630f77563f..03f8973ab4 100644 --- a/modules/mail/em-mailer-prefs.c +++ b/modules/mail/em-mailer-prefs.c @@ -845,7 +845,7 @@ em_mailer_prefs_construct (EMMailerPrefs *prefs, */ ec = em_config_new(E_CONFIG_BOOK, "org.gnome.evolution.mail.prefs"); l = NULL; - for (i=0;ikeyUsage & usageinfo[i].bit) { if (str->len != 0) g_string_append(str, ", "); diff --git a/widgets/misc/test-calendar.c b/widgets/misc/test-calendar.c index 458d60f90a..83b8f11cd7 100644 --- a/widgets/misc/test-calendar.c +++ b/widgets/misc/test-calendar.c @@ -41,8 +41,6 @@ static GtkTargetEntry target_table[] = { { (gchar *) "E-SHORTCUT", 0, TARGET_SHORTCUT } }; -static guint n_targets = sizeof(target_table) / sizeof(target_table[0]); - static void on_date_range_changed (ECalendarItem *calitem); static void on_selection_changed (ECalendarItem *calitem); @@ -85,7 +83,7 @@ main (gint argc, gchar **argv) gtk_drag_dest_set (cal, GTK_DEST_DEFAULT_ALL, - target_table, n_targets, + target_table, G_N_ELEMENTS (target_table), GDK_ACTION_COPY | GDK_ACTION_MOVE); vbox = gtk_vbox_new (FALSE, 0); diff --git a/widgets/table/e-table-click-to-add.c b/widgets/table/e-table-click-to-add.c index 57769d1540..7cceadcec8 100644 --- a/widgets/table/e-table-click-to-add.c +++ b/widgets/table/e-table-click-to-add.c @@ -53,8 +53,6 @@ static guint etcta_signals [LAST_SIGNAL] = { 0 }; #define etcta_get_type e_table_click_to_add_get_type G_DEFINE_TYPE (ETableClickToAdd, etcta, GNOME_TYPE_CANVAS_GROUP) -#define ELEMENTS(x) (sizeof (x) / sizeof (x[0])) - enum { PROP_0, PROP_HEADER, diff --git a/widgets/table/e-table-field-chooser-item.c b/widgets/table/e-table-field-chooser-item.c index 7f0f39a9f9..5cd2f9edc2 100644 --- a/widgets/table/e-table-field-chooser-item.c +++ b/widgets/table/e-table-field-chooser-item.c @@ -57,8 +57,6 @@ static guint etfci_signals [LAST_SIGNAL] = { 0, }; #define etfci_get_type e_table_field_chooser_item_get_type G_DEFINE_TYPE (ETableFieldChooserItem, etfci, GNOME_TYPE_CANVAS_ITEM) -#define ELEMENTS(x) (sizeof (x) / sizeof (x[0])) - static void etfci_drop_table_header (ETableFieldChooserItem *etfci); static void etfci_drop_full_header (ETableFieldChooserItem *etfci); @@ -547,7 +545,7 @@ etfci_start_drag (ETableFieldChooserItem *etfci, GdkEvent *event, double x, doub etfci_drag_types[0].target = g_strdup_printf("%s-%s", etfci_drag_types[0].target, etfci->dnd_code); d(g_print ("etfci - %s\n", etfci_drag_types[0].target)); - list = gtk_target_list_new (etfci_drag_types, ELEMENTS (etfci_drag_types)); + list = gtk_target_list_new (etfci_drag_types, G_N_ELEMENTS (etfci_drag_types)); context = gtk_drag_begin (widget, list, GDK_ACTION_MOVE, 1, event); g_free(etfci_drag_types[0].target); diff --git a/widgets/table/e-table-header-item.c b/widgets/table/e-table-header-item.c index 4bfa15f6ce..684c92037a 100644 --- a/widgets/table/e-table-header-item.c +++ b/widgets/table/e-table-header-item.c @@ -75,7 +75,6 @@ static guint ethi_signals [LAST_SIGNAL] = { 0, }; #define ethi_get_type e_table_header_item_get_type G_DEFINE_TYPE (ETableHeaderItem, ethi, GNOME_TYPE_CANVAS_ITEM) -#define ELEMENTS(x) (sizeof (x) / sizeof (x[0])) #define d(x) static void ethi_drop_table_header (ETableHeaderItem *ethi); @@ -881,7 +880,7 @@ ethi_realize (GnomeCanvasItem *item) */ ethi_drop_types[0].target = g_strdup_printf("%s-%s", ethi_drop_types[0].target, ethi->dnd_code); gtk_drag_dest_set (GTK_WIDGET (item->canvas), 0, - ethi_drop_types, ELEMENTS (ethi_drop_types), + ethi_drop_types, G_N_ELEMENTS (ethi_drop_types), GDK_ACTION_MOVE); g_free(ethi_drop_types[0].target); @@ -1169,7 +1168,7 @@ ethi_start_drag (ETableHeaderItem *ethi, GdkEvent *event) ethi_drag_types[0].target = g_strdup_printf( "%s-%s", ethi_drag_types[0].target, ethi->dnd_code); list = gtk_target_list_new ( - ethi_drag_types, ELEMENTS (ethi_drag_types)); + ethi_drag_types, G_N_ELEMENTS (ethi_drag_types)); context = gtk_drag_begin (widget, list, GDK_ACTION_MOVE, 1, event); g_free(ethi_drag_types[0].target); -- cgit