Revision: 3687 http://geany.svn.sourceforge.net/geany/?rev=3687&view=rev Author: eht16 Date: 2009-04-05 21:07:40 +0000 (Sun, 05 Apr 2009)
Log Message: ----------- Start using G_LIKELY/G_UNLIKELY macros to gain a little more performance when building the code with gcc.
Modified Paths: -------------- trunk/ChangeLog trunk/src/build.c trunk/src/callbacks.c trunk/src/dialogs.c trunk/src/document.c trunk/src/document.h trunk/src/editor.c trunk/src/encodings.c trunk/src/filetypes.c trunk/src/geanymenubuttonaction.c trunk/src/geanyobject.c trunk/src/geanywraplabel.c trunk/src/highlighting.c trunk/src/keybindings.c trunk/src/keyfile.c trunk/src/log.c trunk/src/main.c trunk/src/msgwindow.c trunk/src/navqueue.c trunk/src/notebook.c trunk/src/plugins.c trunk/src/prefs.c trunk/src/queue.c trunk/src/sciwrappers.c trunk/src/socket.c trunk/src/symbols.c trunk/src/templates.c trunk/src/toolbar.c trunk/src/tools.c trunk/src/tools.h trunk/src/treeviews.c trunk/src/ui_utils.c trunk/src/utils.c trunk/src/utils.h trunk/src/vte.c
Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2009-04-05 19:58:30 UTC (rev 3686) +++ trunk/ChangeLog 2009-04-05 21:07:40 UTC (rev 3687) @@ -9,6 +9,17 @@ (#2728630, patch by Elias Pschernig, thanks). * doc/geany.txt, doc/geany.html: Describe how to build Geany using the Waf build system. + * src/build.c, src/callbacks.c, src/dialogs.c, src/document.c, + src/document.h, src/editor.c, src/encodings.c, src/filetypes.c, + src/geanymenubuttonaction.c, src/geanyobject.c, src/geanywraplabel.c, + src/highlighting.c, src/keybindings.c, src/keyfile.c, src/log.c, + src/main.c, src/msgwindow.c, src/navqueue.c, src/notebook.c, + src/plugins.c, src/prefs.c, src/queue.c, src/sciwrappers.c, + src/socket.c, src/symbols.c, src/templates.c, src/toolbar.c, + src/tools.c, src/tools.h, src/treeviews.c, src/ui_utils.c, + src/utils.c, src/utils.h, src/vte.c: + Start using G_LIKELY/G_UNLIKELY macros to gain a little more + performance when building the code with gcc.
2009-04-03 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
Modified: trunk/src/build.c =================================================================== --- trunk/src/build.c 2009-04-05 19:58:30 UTC (rev 3686) +++ trunk/src/build.c 2009-04-05 21:07:40 UTC (rev 3687) @@ -1570,11 +1570,11 @@ BuildMenuItems *menu_items; static GtkWidget *menubar_build_menu = NULL;
- if (menubar_build_menu == NULL) /* cache the build menu pointer */ + if (G_UNLIKELY(menubar_build_menu == NULL)) /* cache the build menu pointer */ menubar_build_menu = ui_lookup_widget(main_widgets.window, "menu_build1"); if (doc == NULL) doc = document_get_current(); - if (doc == NULL || + if (G_UNLIKELY(doc == NULL) || (FILETYPE_ID(doc->file_type) == GEANY_FILETYPES_NONE && doc->file_name == NULL)) { gtk_widget_set_sensitive(menubar_build_menu, FALSE); @@ -1588,7 +1588,7 @@ gtk_widget_set_sensitive(menubar_build_menu, TRUE);
ft = doc->file_type; - g_return_if_fail(ft != NULL); + g_return_if_fail(G_LIKELY(ft != NULL));
menu_items = build_get_menu_items(ft->id); /* Note: don't remove the submenu first because it can now cause an X hang if @@ -1596,7 +1596,7 @@ gtk_menu_item_set_submenu(GTK_MENU_ITEM(menubar_build_menu), menu_items->menu);
- have_path = (doc->file_name != NULL); + have_path = G_LIKELY(doc->file_name != NULL);
can_make = have_path && build_info.pid <= (GPid) 1;
@@ -1853,7 +1853,7 @@ { static GtkWidget *dialog = NULL; /* keep dialog for combo history */
- if (! dialog) + if (G_UNLIKELY(! dialog)) dialog = dialogs_show_input(_("Make Custom Target"), _("Enter custom options here, all entered text is passed to the make command."), build_info.custom_target, TRUE, &on_make_custom_input_response); @@ -2055,7 +2055,7 @@ widgets.build_action = toolbar_get_action_by_name("Build"); toolmenu = geany_menu_button_action_get_menu(GEANY_MENU_BUTTON_ACTION(widgets.build_action));
- if (toolmenu != NULL) + if (G_UNLIKELY(toolmenu != NULL)) { /* build the code */ item = ui_image_menu_item_new(GEANY_STOCK_BUILD, _("_Build"));
Modified: trunk/src/callbacks.c =================================================================== --- trunk/src/callbacks.c 2009-04-05 19:58:30 UTC (rev 3686) +++ trunk/src/callbacks.c 2009-04-05 21:07:40 UTC (rev 3687) @@ -95,7 +95,7 @@
for (i = 0; i < documents_array->len; i++) { - if (documents[i]->is_valid && documents[i]->changed) + if (documents[i]->is_valid && G_UNLIKELY(documents[i]->changed)) { return FALSE; } @@ -179,9 +179,9 @@ gint cur_page = gtk_notebook_get_current_page(GTK_NOTEBOOK(main_widgets.notebook)); GeanyDocument *doc = document_get_current();
- if (doc != NULL && cur_page >= 0) + if (G_LIKELY(doc != NULL) && G_LIKELY(cur_page >= 0)) { - if (doc->file_name == NULL) + if (G_UNLIKELY(doc->file_name == NULL)) dialogs_show_save_as(); else document_save_file(doc, FALSE); @@ -208,7 +208,7 @@ { doc = document_get_from_page(i); if (! doc->changed) continue; - if (doc->file_name == NULL) + if (G_UNLIKELY(doc->file_name == NULL)) { /* display unnamed document */ gtk_notebook_set_current_page(GTK_NOTEBOOK(main_widgets.notebook), @@ -237,7 +237,7 @@ { GeanyDocument *doc = document_get_current();
- if (doc) + if (G_LIKELY(doc)) document_close(doc); }
@@ -282,7 +282,7 @@ { GeanyDocument *doc = document_get_current();
- if (doc != NULL && document_can_undo(doc)) + if (G_LIKELY(doc != NULL) && document_can_undo(doc)) { sci_cancel(doc->editor->sci); document_undo(doc); @@ -296,7 +296,7 @@ { GeanyDocument *doc = document_get_current();
- if (doc != NULL && document_can_redo(doc)) + if (G_LIKELY(doc != NULL) && document_can_redo(doc)) { sci_cancel(doc->editor->sci); document_redo(doc); @@ -314,7 +314,7 @@ if (GTK_IS_EDITABLE(focusw)) gtk_editable_cut_clipboard(GTK_EDITABLE(focusw)); else - if (IS_SCINTILLA(focusw) && doc != NULL) + if (IS_SCINTILLA(focusw) && G_LIKELY(doc != NULL)) sci_cut(doc->editor->sci); else if (GTK_IS_TEXT_VIEW(focusw)) @@ -336,7 +336,7 @@ if (GTK_IS_EDITABLE(focusw)) gtk_editable_copy_clipboard(GTK_EDITABLE(focusw)); else - if (IS_SCINTILLA(focusw) && doc != NULL) + if (IS_SCINTILLA(focusw) && G_LIKELY(doc != NULL)) sci_copy(doc->editor->sci); else if (GTK_IS_TEXT_VIEW(focusw)) @@ -358,7 +358,7 @@ if (GTK_IS_EDITABLE(focusw)) gtk_editable_paste_clipboard(GTK_EDITABLE(focusw)); else - if (IS_SCINTILLA(focusw) && doc != NULL) + if (IS_SCINTILLA(focusw) && G_LIKELY(doc != NULL)) { sci_paste(doc->editor->sci); } @@ -383,7 +383,7 @@ if (GTK_IS_EDITABLE(focusw)) gtk_editable_delete_selection(GTK_EDITABLE(focusw)); else - if (IS_SCINTILLA(focusw) && doc != NULL && sci_has_selection(doc->editor->sci)) + if (IS_SCINTILLA(focusw) && G_LIKELY(doc != NULL) && sci_has_selection(doc->editor->sci)) sci_clear(doc->editor->sci); else if (GTK_IS_TEXT_VIEW(focusw)) @@ -449,11 +449,12 @@ gint i = GPOINTER_TO_INT(user_data); gchar *charset = NULL;
- if (doc == NULL || doc->file_name == NULL) + if (G_UNLIKELY(doc == NULL) || G_UNLIKELY(doc->file_name == NULL)) return; if (i >= 0) { - if (i >= GEANY_ENCODINGS_MAX || encodings[i].charset == NULL) return; + if (G_UNLIKELY(i >= GEANY_ENCODINGS_MAX) || G_UNLIKELY(encodings[i].charset == NULL)) + return; charset = encodings[i].charset; }
@@ -631,9 +632,9 @@ gpointer user_data) { GeanyDocument *doc = document_get_current(); - static gboolean done = 1; + static gint done = 1;
- if (doc != NULL) + if (G_LIKELY(doc != NULL)) { if (done++ % 3 == 0) sci_set_line_numbers(doc->editor->sci, editor_prefs.show_linenumber_margin, @@ -662,7 +663,7 @@ gpointer user_data) { GeanyDocument *doc = document_get_current(); - if (doc != NULL) + if (G_LIKELY(doc != NULL)) { sci_zoom_off(doc->editor->sci); sci_set_line_numbers(doc->editor->sci, editor_prefs.show_linenumber_margin, 0); @@ -712,7 +713,7 @@ { GeanyDocument *doc;
- if (main_status.opening_session_files || main_status.closing_all) + if (G_UNLIKELY(main_status.opening_session_files) || G_UNLIKELY(main_status.closing_all)) return;
if (page_num == (guint) -1 && page != NULL) @@ -720,7 +721,7 @@ else doc = document_get_from_page(page_num);
- if (doc != NULL) + if (G_LIKELY(doc != NULL)) { treeviews_select_openfiles_item(doc); document_set_text_changed(doc, doc->changed); /* also sets window title and status bar */ @@ -769,7 +770,8 @@ gpointer user_data) { GeanyDocument *doc = document_get_current(); - if (ignore_callback || doc == NULL) return; + if (ignore_callback || G_UNLIKELY(doc == NULL)) + return; sci_convert_eols(doc->editor->sci, SC_EOL_CRLF); sci_set_eol_mode(doc->editor->sci, SC_EOL_CRLF); } @@ -780,7 +782,8 @@ gpointer user_data) { GeanyDocument *doc = document_get_current(); - if (ignore_callback || doc == NULL) return; + if (ignore_callback || G_UNLIKELY(doc == NULL)) + return; sci_convert_eols(doc->editor->sci, SC_EOL_LF); sci_set_eol_mode(doc->editor->sci, SC_EOL_LF); } @@ -791,7 +794,8 @@ gpointer user_data) { GeanyDocument *doc = document_get_current(); - if (ignore_callback || doc == NULL) return; + if (ignore_callback || G_UNLIKELY(doc == NULL)) + return; sci_convert_eols(doc->editor->sci, SC_EOL_CR); sci_set_eol_mode(doc->editor->sci, SC_EOL_CR); } @@ -803,7 +807,7 @@ { GeanyDocument *doc = document_get_current();
- if (doc != NULL) + if (G_LIKELY(doc != NULL)) editor_replace_tabs(doc->editor); }
@@ -854,7 +858,7 @@ gchar *text; gboolean keep_sel = TRUE;
- if (doc == NULL) + if (G_UNLIKELY(doc == NULL)) return;
sci = doc->editor->sci; @@ -1004,7 +1008,7 @@ if (! ignore_callback) { GeanyDocument *doc = document_get_current(); - if (doc != NULL) + if (G_LIKELY(doc != NULL)) editor_set_line_wrapping(doc->editor, ! doc->editor->line_wrapping); } } @@ -1017,7 +1021,7 @@ if (! ignore_callback) { GeanyDocument *doc = document_get_current(); - if (doc == NULL) + if (G_UNLIKELY(doc == NULL)) return; doc->readonly = ! doc->readonly; sci_set_readonly(doc->editor->sci, doc->readonly); @@ -1034,7 +1038,7 @@ if (! ignore_callback) { GeanyDocument *doc = document_get_current(); - if (doc != NULL) + if (G_LIKELY(doc != NULL)) doc->editor->auto_indent = ! doc->editor->auto_indent; } } @@ -1046,7 +1050,7 @@ gchar *search_text; GeanyDocument *doc = document_get_current();
- if (doc == NULL) + if (G_UNLIKELY(doc == NULL)) return;
if (sci_has_selection(doc->editor->sci)) @@ -1090,7 +1094,7 @@ GTK_MENU_ITEM(ui_lookup_widget(main_widgets.editor_menu, "goto_tag_definition1"))); GeanyDocument *doc = document_get_current();
- g_return_if_fail(doc != NULL); + g_return_if_fail(G_LIKELY(doc != NULL));
sci_set_current_position(doc->editor->sci, editor_info.click_pos, FALSE); symbols_goto_tag(editor_info.current_word, definition); @@ -1113,7 +1117,7 @@ GeanyDocument *doc = document_get_current(); gint pos;
- if (doc == NULL) + if (G_UNLIKELY(doc == NULL)) return;
pos = sci_get_current_position(doc->editor->sci); @@ -1142,7 +1146,7 @@ { GeanyDocument *doc = document_get_current();
- g_return_if_fail(doc != NULL); + g_return_if_fail(G_LIKELY(doc != NULL));
if (search_data.text) { @@ -1223,7 +1227,7 @@ { GeanyDocument *doc = document_get_current();
- if (doc != NULL) + if (G_LIKELY(doc != NULL)) { if (! editor_goto_line(doc->editor, (gint) val - 1)) utils_beep(); @@ -1237,7 +1241,7 @@ { GeanyDocument *doc = document_get_current();
- if (doc != NULL) + if (G_LIKELY(doc != NULL)) { gint line = atoi(text); if (! editor_goto_line(doc->editor, line - 1)) @@ -1313,7 +1317,7 @@ const gchar *cur_tag = NULL; gint line = -1, pos = 0;
- if (doc == NULL || doc->file_type == NULL) + if (G_UNLIKELY(doc == NULL) || G_UNLIKELY(doc->file_type == NULL)) { ui_set_statusbar(FALSE, _("Please set the filetype for the current file before using this function.")); @@ -1338,7 +1342,7 @@ { GeanyDocument *doc = document_get_current();
- if (doc == NULL || doc->file_type == NULL) + if (G_UNLIKELY(doc == NULL) || G_UNLIKELY(doc->file_type == NULL)) { ui_set_statusbar(FALSE, _("Please set the filetype for the current file before using this function.")); @@ -1358,7 +1362,7 @@ GeanyDocument *doc = document_get_current(); gchar *text;
- if (doc == NULL) + if (G_UNLIKELY(doc == NULL)) return;
text = templates_get_template_licence(FILETYPE_ID(doc->file_type), GEANY_TEMPLATE_GPL); @@ -1378,7 +1382,7 @@ GeanyDocument *doc = document_get_current(); gchar *text;
- if (doc == NULL) + if (G_UNLIKELY(doc == NULL)) return;
text = templates_get_template_licence(FILETYPE_ID(doc->file_type), GEANY_TEMPLATE_BSD); @@ -1398,7 +1402,7 @@ GeanyDocument *doc = document_get_current(); gchar *text;
- if (doc == NULL) + if (G_UNLIKELY(doc == NULL)) return;
text = templates_get_template_changelog(); @@ -1420,7 +1424,7 @@ gchar *fname; GeanyFiletype *ft;
- g_return_if_fail(doc != NULL); + g_return_if_fail(G_LIKELY(doc != NULL));
ft = doc->file_type; fname = doc->file_name; @@ -1447,7 +1451,8 @@ gchar *format; gchar *time_str;
- if (doc == NULL) return; + if (G_UNLIKELY(doc == NULL)) + return;
if (utils_str_equal(_("dd.mm.yyyy"), (gchar*) user_data)) format = "%d.%m.%Y"; @@ -1479,7 +1484,7 @@ }
time_str = utils_get_date_time(format, NULL); - if (time_str != NULL) + if (G_UNLIKELY(time_str != NULL)) { verify_click_pos(doc); /* make sure that the click_pos is valid */
@@ -1504,7 +1509,8 @@ gint pos = -1; gchar *text;
- if (doc == NULL || user_data == NULL) return; + if (G_UNLIKELY(doc == NULL) || G_UNLIKELY(user_data == NULL)) + return;
verify_click_pos(doc); /* make sure that the click_pos is valid */
@@ -1520,7 +1526,7 @@
sci_insert_text(doc->editor->sci, editor_info.click_pos, text); g_free(text); - if (pos >= 0) + if (G_LIKELY(pos >= 0)) sci_goto_pos(doc->editor->sci, pos, FALSE); }
@@ -1539,7 +1545,7 @@ gpointer user_data) { GeanyDocument *doc = document_get_current(); - if (doc != NULL) + if (G_LIKELY(doc != NULL)) editor_fold_all(doc->editor); }
@@ -1549,7 +1555,7 @@ gpointer user_data) { GeanyDocument *doc = document_get_current(); - if (doc != NULL) + if (G_LIKELY(doc != NULL)) editor_unfold_all(doc->editor); }
@@ -1568,7 +1574,7 @@ { GeanyDocument *doc = document_get_current();
- if (doc != NULL) + if (G_LIKELY(doc != NULL)) editor_indicator_clear(doc->editor, GEANY_INDICATOR_ERROR); }
@@ -1580,11 +1586,11 @@ GeanyDocument *doc = document_get_current(); guint i = GPOINTER_TO_INT(user_data);
- if (ignore_callback || doc == NULL || encodings[i].charset == NULL || + if (ignore_callback || G_UNLIKELY(doc == NULL) || G_UNLIKELY(encodings[i].charset == NULL) || utils_str_equal(encodings[i].charset, doc->encoding)) return;
- if (doc->readonly) + if (G_UNLIKELY(doc->readonly)) { utils_beep(); return; @@ -1600,7 +1606,7 @@ gpointer user_data) { GeanyDocument *doc = document_get_current(); - if (doc != NULL) + if (G_LIKELY(doc != NULL)) printing_print_doc(doc); }
@@ -1611,7 +1617,7 @@ { GeanyDocument *doc = document_get_current();
- if (doc != NULL) + if (G_LIKELY(doc != NULL)) sci_select_all(doc->editor->sci); }
@@ -1652,9 +1658,9 @@ { GeanyDocument *doc = document_get_current();
- if (doc == NULL) + if (G_UNLIKELY(doc == NULL)) return; - if (doc->readonly) + if (G_UNLIKELY(doc->readonly)) { utils_beep(); return; @@ -1674,7 +1680,7 @@ gpointer user_data) { GeanyDocument *doc = document_get_current(); - if (doc != NULL) + if (G_LIKELY(doc != NULL)) editor_do_comment(doc->editor, -1, FALSE, FALSE); }
@@ -1684,7 +1690,7 @@ gpointer user_data) { GeanyDocument *doc = document_get_current(); - if (doc != NULL) + if (G_LIKELY(doc != NULL)) editor_do_uncomment(doc->editor, -1, FALSE); }
@@ -1695,7 +1701,7 @@ gpointer user_data) { GeanyDocument *doc = document_get_current(); - if (doc != NULL) + if (G_LIKELY(doc != NULL)) editor_do_comment_toggle(doc->editor); }
@@ -1725,7 +1731,7 @@ gpointer user_data) { GeanyDocument *doc = document_get_current(); - if (doc == NULL) + if (G_UNLIKELY(doc == NULL)) return;
if (sci_get_lines_selected(doc->editor->sci) > 1) @@ -1744,7 +1750,7 @@ gpointer user_data) { GeanyDocument *doc = document_get_current(); - if (doc == NULL) + if (G_UNLIKELY(doc == NULL)) return;
if (sci_get_lines_selected(doc->editor->sci) > 1) @@ -1862,7 +1868,7 @@ static GtkWidget *item_close = NULL; static GtkWidget *item_properties = NULL;
- if (item_close == NULL) + if (G_UNLIKELY(item_close == NULL)) { item_close = ui_lookup_widget(main_widgets.window, "project_close1"); item_properties = ui_lookup_widget(main_widgets.window, "project_properties1"); @@ -1880,7 +1886,7 @@ GeanyDocument *doc = document_get_current(); gchar *sel = NULL;
- if (doc == NULL) + if (G_UNLIKELY(doc == NULL)) return;
sel = editor_get_default_selection(doc->editor, TRUE, GEANY_WORDCHARS"./-"); @@ -1924,7 +1930,7 @@ { GeanyDocument *doc = document_get_current();
- if (doc == NULL) + if (G_UNLIKELY(doc == NULL)) return;
sci_marker_delete_all(doc->editor->sci, 0); /* delete the yellow tag marker */ @@ -1949,7 +1955,7 @@ GError *error = NULL; GeanyDocument *doc = document_get_current();
- if (doc == NULL) + if (G_UNLIKELY(doc == NULL)) return;
if (sci_has_selection(doc->editor->sci)) @@ -1974,7 +1980,7 @@ }
/* substitute the wildcard %s and run the command if it is non empty */ - if (command != NULL && *command != '\0') + if (NZV(command)) { command = utils_str_replace(command, "%s", word);
@@ -2001,7 +2007,7 @@ ui_lookup_widget(main_widgets.window, "menu_show_toolbar1"));
/* get the initial state (necessary if Geany was closed with hide_all = TRUE) */ - if (hide_all == -1) + if (G_UNLIKELY(hide_all == -1)) { if (! gtk_check_menu_item_get_active(msgw) && ! interface_prefs.show_notebook_tabs && @@ -2074,7 +2080,7 @@ { GeanyDocument *doc = document_get_current();
- if (doc == NULL || ignore_callback) + if (G_UNLIKELY(doc == NULL) || ignore_callback) return;
editor_set_indent_type(doc->editor, type); @@ -2116,7 +2122,7 @@ return;
doc = document_get_current(); - g_return_if_fail(doc != NULL); + g_return_if_fail(G_LIKELY(doc != NULL));
editor_strip_trailing_spaces(doc->editor); } @@ -2159,7 +2165,7 @@ return;
doc = document_get_current(); - g_return_if_fail(doc != NULL); + g_return_if_fail(G_LIKELY(doc != NULL));
doc->editor->line_breaking = !doc->editor->line_breaking; } @@ -2170,7 +2176,7 @@ { GeanyDocument *doc = document_get_current();
- if (doc != NULL) + if (G_LIKELY(doc != NULL)) editor_replace_spaces(doc->editor); }
@@ -2198,13 +2204,13 @@ gpointer user_data) { guint i; - GeanyDocument *cur_doc = document_get_current(); + GeanyDocument *doc, *cur_doc = document_get_current();
for (i = 0; i < documents_array->len; i++) { - GeanyDocument *doc = documents[i]; + doc = documents[i];
- if (doc == cur_doc || ! doc->is_valid) + if (G_UNLIKELY(doc == cur_doc) || ! doc->is_valid) continue;
if (! document_close(doc))
Modified: trunk/src/dialogs.c =================================================================== --- trunk/src/dialogs.c 2009-04-05 19:58:30 UTC (rev 3686) +++ trunk/src/dialogs.c 2009-04-05 21:07:40 UTC (rev 3687) @@ -141,7 +141,7 @@ gchar *filename = gtk_file_chooser_get_filename(filechooser); gboolean is_on = gtk_file_chooser_get_show_hidden(filechooser);
- if (filename) + if (G_LIKELY(filename)) { /* try to get the UTF-8 equivalent for the filename, fallback to filename if error */ gchar *utf8_filename = utils_get_utf8_from_locale(filename); @@ -218,7 +218,7 @@ filetypes_create_file_filter_all_source()); foreach_slist(ft, node, filetypes_by_title) { - if (ft->id == GEANY_FILETYPES_NONE) + if (G_UNLIKELY(ft->id == GEANY_FILETYPES_NONE)) continue; gtk_combo_box_append_text(GTK_COMBO_BOX(filetype_combo), ft->title); gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(ui_widgets.open_filesel), @@ -268,7 +268,7 @@
/* We use the same file selection widget each time, so first of all we create it * if it hasn't already been created. */ - if (ui_widgets.open_filesel == NULL) + if (G_UNLIKELY(ui_widgets.open_filesel == NULL)) create_open_file_dialog();
if (initdir != NULL) @@ -516,7 +516,7 @@ gint resp; gboolean folder_set = FALSE;
- if (ui_widgets.save_filesel == NULL) + if (G_UNLIKELY(ui_widgets.save_filesel == NULL)) create_save_file_dialog();
gtk_file_chooser_unselect_all(GTK_FILE_CHOOSER(ui_widgets.save_filesel)); @@ -704,7 +704,7 @@ document_get_notebook_page(doc)); main_status.quitting = old_quitting_state;
- if (doc->file_name != NULL) + if (G_LIKELY(doc->file_name != NULL)) { short_fn = g_path_get_basename(doc->file_name); } @@ -959,9 +959,9 @@ GtkWidget *dialog, *label, *spin, *vbox; gboolean res = FALSE;
- g_return_val_if_fail(title != NULL, FALSE); - g_return_val_if_fail(label_text != NULL, FALSE); - g_return_val_if_fail(value != NULL, FALSE); + g_return_val_if_fail(G_LIKELY(title != NULL), FALSE); + g_return_val_if_fail(G_LIKELY(label_text != NULL), FALSE); + g_return_val_if_fail(G_LIKELY(value != NULL), FALSE);
dialog = gtk_dialog_new_with_buttons(title, GTK_WINDOW(main_widgets.window), GTK_DIALOG_DESTROY_WITH_PARENT, @@ -1023,7 +1023,7 @@ # define S_IXOTH 0 #endif
- if (doc == NULL || doc->file_name == NULL) + if (G_UNLIKELY(doc == NULL) || G_UNLIKELY(doc->file_name == NULL)) { dialogs_show_msgbox(GTK_MESSAGE_ERROR, _("An error occurred or file information could not be retrieved (e.g. from a new file)."));
Modified: trunk/src/document.c =================================================================== --- trunk/src/document.c 2009-04-05 19:58:30 UTC (rev 3686) +++ trunk/src/document.c 2009-04-05 21:07:40 UTC (rev 3687) @@ -131,14 +131,15 @@ { guint i;
- if (! realname) + if (G_UNLIKELY(! realname)) return NULL; /* file doesn't exist on disk */
for (i = 0; i < documents_array->len; i++) { GeanyDocument *doc = documents[i];
- if (! documents[i]->is_valid || ! doc->real_path) continue; + if (! doc->is_valid || G_UNLIKELY(! doc->real_path)) + continue;
if (filenamecmp(realname, doc->real_path) == 0) { @@ -177,7 +178,7 @@ GeanyDocument *doc; gchar *realname;
- if (! utf8_filename) + if (G_UNLIKELY(! utf8_filename)) return NULL;
/* First search GeanyDocument::file_name, so we can find documents with a @@ -186,7 +187,8 @@ { doc = documents[i];
- if (! documents[i]->is_valid || doc->file_name == NULL) continue; + if (! doc->is_valid || G_UNLIKELY(doc->file_name == NULL)) + continue;
if (filenamecmp(utf8_filename, doc->file_name) == 0) { @@ -206,7 +208,7 @@ { guint i;
- if (sci == NULL) + if (G_UNLIKELY(sci == NULL)) return NULL;
for (i = 0; i < documents_array->len; i++) @@ -221,7 +223,7 @@ /* returns the index of the notebook page for the document. */ gint document_get_notebook_page(GeanyDocument *doc) { - if (doc == NULL) + if (G_UNLIKELY(doc == NULL)) return -1;
return gtk_notebook_page_num(GTK_NOTEBOOK(main_widgets.notebook), @@ -240,7 +242,7 @@ { ScintillaObject *sci;
- if (page_num >= documents_array->len) + if (G_UNLIKELY(page_num >= documents_array->len)) return NULL;
sci = (ScintillaObject*)gtk_notebook_get_nth_page( @@ -259,7 +261,7 @@ { gint cur_page = gtk_notebook_get_current_page(GTK_NOTEBOOK(main_widgets.notebook));
- if (cur_page == -1) + if (G_UNLIKELY(cur_page == -1)) return NULL; else { @@ -288,7 +290,7 @@ gchar *base_name; GtkWidget *parent;
- g_return_if_fail(doc != NULL); + g_return_if_fail(G_LIKELY(doc != NULL));
base_name = g_path_get_basename(DOC_FILENAME(doc)); /* we need to use the event box for the tooltip, labels don't get the necessary events */ @@ -313,12 +315,12 @@ **/ void document_set_text_changed(GeanyDocument *doc, gboolean changed) { - if (doc == NULL) + if (G_UNLIKELY(doc == NULL)) return;
doc->changed = changed;
- if (! main_status.quitting) + if (G_LIKELY(! main_status.quitting)) { ui_update_tab_status(doc); ui_save_buttons_toggle(changed); @@ -395,7 +397,7 @@ /* Set the file status to 'changed' after a single 'created' event. */ static gboolean monitor_finish_pending_create(gpointer doc) { - g_return_val_if_fail(doc != NULL, FALSE); + g_return_val_if_fail(G_LIKELY(doc != NULL), FALSE);
((GeanyDocument *)doc)->priv->file_disk_status = FILE_CHANGED; ui_update_tab_status(doc); @@ -407,7 +409,7 @@ /* Resets the 'ignore' file status after a reload action. */ static gboolean monitor_reset_ignore(gpointer doc) { - g_return_val_if_fail(doc != NULL, FALSE); + g_return_val_if_fail(G_LIKELY(doc != NULL), FALSE);
((GeanyDocument *)doc)->priv->file_disk_status = FILE_OK; ui_update_tab_status(doc); @@ -419,7 +421,7 @@ static void monitor_file_changed_cb(G_GNUC_UNUSED GFileMonitor *monitor, G_GNUC_UNUSED GFile *file, G_GNUC_UNUSED GFile *other_file, GFileMonitorEvent event, GeanyDocument *doc) { - g_return_if_fail(doc != NULL); + g_return_if_fail(G_LIKELY(doc != NULL));
if (file_prefs.disk_check_timeout == 0) return; @@ -492,7 +494,7 @@
void document_stop_file_monitoring(GeanyDocument *doc) { - g_return_if_fail(doc != NULL); + g_return_if_fail(G_LIKELY(doc != NULL));
if (doc->priv->monitor != NULL) { @@ -504,7 +506,7 @@
static void monitor_file_setup(GeanyDocument *doc) { - g_return_if_fail(doc != NULL); + g_return_if_fail(G_LIKELY(doc != NULL)); /* Disable file monitoring completely for remote files (i.e. remote GIO files) as GFileMonitor * doesn't work at all for remote files and legacy polling is too slow. */ if (! doc->priv->is_remote) @@ -602,7 +604,7 @@ **/ gboolean document_close(GeanyDocument *doc) { - g_return_val_if_fail(doc, FALSE); + g_return_val_if_fail(G_LIKELY(doc), FALSE);
return document_remove_page(document_get_notebook_page(doc)); } @@ -620,7 +622,7 @@ { GeanyDocument *doc = document_get_from_page(page_num);
- if (doc == NULL) + if (G_UNLIKELY(doc == NULL)) { g_warning("%s: page_num: %d", G_STRFUNC, page_num); return FALSE; @@ -710,7 +712,7 @@ { GeanyDocument *doc = document_create(utf8_filename);
- g_assert(doc != NULL); + g_assert(G_LIKELY(doc != NULL));
sci_set_undo_collection(doc->editor->sci, FALSE); /* avoid creation of an undo action */ if (text) @@ -812,7 +814,7 @@ { gchar *converted_text = encodings_convert_to_utf8_from_charset( filedata->data, filedata->size, forced_enc, FALSE); - if (converted_text == NULL) + if (G_LIKELY(converted_text == NULL)) { return FALSE; } @@ -834,8 +836,8 @@ static gboolean handle_encoding(FileData *filedata, GeanyEncodingIndex enc_idx) { - g_return_val_if_fail(filedata->enc == NULL, FALSE); - g_return_val_if_fail(filedata->bom == FALSE, FALSE); + g_return_val_if_fail(G_LIKELY(filedata->enc == NULL), FALSE); + g_return_val_if_fail(G_LIKELY(filedata->bom == FALSE), FALSE);
if (filedata->size == 0) { @@ -855,7 +857,7 @@ { gchar *converted_text = encodings_convert_to_utf8_from_charset( filedata->data, filedata->size, filedata->enc, FALSE); - if (converted_text != NULL) + if (G_LIKELY(converted_text != NULL)) { g_free(filedata->data); filedata->data = converted_text; @@ -885,7 +887,7 @@ gchar *converted_text = encodings_convert_to_utf8(filedata->data, filedata->size, &filedata->enc);
- if (converted_text == NULL) + if (G_UNLIKELY(converted_text == NULL)) { return FALSE; } @@ -1158,7 +1160,7 @@ { GeanyDocument *doc = data;
- if (! doc || ! doc->is_valid || doc->tm_file == NULL) + if (G_UNLIKELY(! doc) || G_UNLIKELY(! doc->is_valid) || G_UNLIKELY(doc->tm_file == NULL)) return FALSE;
if (gtk_window_get_focus(GTK_WINDOW(main_widgets.window)) != GTK_WIDGET(doc->editor->sci)) @@ -1195,7 +1197,7 @@ else { /* filename must not be NULL when opening a file */ - if (filename == NULL) + if (G_UNLIKELY(filename == NULL)) { ui_set_statusbar(FALSE, _("Invalid filename")); return NULL; @@ -1240,11 +1242,10 @@ if (! reload) { doc = document_create(utf8_filename); - g_return_val_if_fail(doc != NULL, NULL); /* really should not happen */ + g_return_val_if_fail(G_LIKELY(doc != NULL), NULL); /* really should not happen */
/* file exists on disk, set real_path */ - g_free(doc->real_path); - doc->real_path = tm_get_real_path(locale_filename); + setptr(doc->real_path, tm_get_real_path(locale_filename));
doc->priv->is_remote = utils_is_remote_path(locale_filename); monitor_file_setup(doc); @@ -1312,7 +1313,7 @@ if (! main_status.opening_session_files) ui_add_recent_file(utf8_filename);
- if (! reload && geany_object) + if (! reload) g_signal_emit_by_name(geany_object, "document-open", doc);
if (reload) @@ -1341,7 +1342,8 @@ gchar *filename; gchar **list;
- if (data == NULL) return; + if (G_UNLIKELY(data == NULL)) + return;
if (length < 0) length = strlen(data); @@ -1356,9 +1358,11 @@
for (i = 0; ; i++) { - if (list[i] == NULL) break; + if (list[i] == NULL) + break; filename = g_filename_from_uri(list[i], NULL, NULL); - if (filename == NULL) continue; + if (G_UNLIKELY(filename == NULL)) + continue; document_open_file(filename, FALSE, NULL, NULL); g_free(filename); } @@ -1401,7 +1405,7 @@ gint pos = 0; GeanyDocument *new_doc;
- if (doc == NULL) + if (G_UNLIKELY(doc == NULL)) return FALSE;
/* try to set the cursor to the position before reloading */ @@ -1426,7 +1430,7 @@ #if ! defined(HAVE_GIO) || ! defined(USE_GIO_FILEMON) struct stat st;
- g_return_val_if_fail(doc != NULL, FALSE); + g_return_val_if_fail(G_LIKELY(doc != NULL), FALSE);
/* stat the file to get the timestamp, otherwise on Windows the actual * timestamp can be ahead of time(NULL) */ @@ -1475,7 +1479,8 @@ gchar *filename; struct TextToFind ttf;
- if (doc == NULL || doc->file_type == NULL) return; + if (G_UNLIKELY(doc == NULL) || G_UNLIKELY(doc->file_type == NULL)) + return;
filebase = g_strconcat(GEANY_STRING_UNTITLED, ".", (doc->file_type)->extension, NULL); filename = g_path_get_basename(doc->file_name); @@ -1539,13 +1544,11 @@ { gboolean ret;
- g_return_val_if_fail(doc != NULL, FALSE); + g_return_val_if_fail(G_LIKELY(doc != NULL), FALSE);
if (utf8_fname != NULL) - { - g_free(doc->file_name); - doc->file_name = g_strdup(utf8_fname); - } + setptr(doc->file_name, g_strdup(utf8_fname)); + /* reset real path, it's retrieved again in document_save() */ setptr(doc->real_path, NULL);
@@ -1571,7 +1574,7 @@ monitor_file_setup(doc); doc->priv->file_disk_status = FILE_IGNORE;
- if (ret) + if (G_LIKELY(ret)) ui_add_recent_file(doc->file_name); return ret; } @@ -1584,14 +1587,14 @@ gsize bytes_read; gsize conv_len;
- g_return_val_if_fail(data != NULL || *data == NULL, FALSE); - g_return_val_if_fail(len != NULL, FALSE); + g_return_val_if_fail(G_LIKELY(data != NULL) || G_LIKELY(*data == NULL), FALSE); + g_return_val_if_fail(G_LIKELY(len != NULL), FALSE);
/* try to convert it from UTF-8 to original encoding */ conv_file_contents = g_convert(*data, *len - 1, doc->encoding, "UTF-8", &bytes_read, &conv_len, &conv_error);
- if (conv_error != NULL) + if (G_UNLIKELY(conv_error != NULL)) { gchar *text = g_strdup_printf( _("An error occurred while converting the file from UTF-8 in "%s". The file remains unsaved."), @@ -1648,15 +1651,15 @@ gint bytes_written; gint err = 0;
- g_return_val_if_fail(data != NULL, EINVAL); + g_return_val_if_fail(G_LIKELY(data != NULL), EINVAL);
fp = g_fopen(locale_filename, "wb"); - if (fp == NULL) + if (G_UNLIKELY(fp == NULL)) return errno;
bytes_written = fwrite(data, sizeof(gchar), len, fp);
- if (len != bytes_written) + if (G_UNLIKELY(len != bytes_written)) err = errno;
fclose(fp); @@ -1692,14 +1695,14 @@ gint err; gchar *locale_filename;
- if (doc == NULL) + if (G_UNLIKELY(doc == NULL)) return FALSE;
/* the "changed" flag should exclude the "readonly" flag, but check it anyway for safety */ if (! force && ! ui_prefs.allow_always_save && (! doc->changed || doc->readonly)) return FALSE;
- if (doc->file_name == NULL) + if (G_UNLIKELY(doc->file_name == NULL)) { ui_set_statusbar(TRUE, _("Error saving file.")); utils_beep(); @@ -1758,7 +1761,7 @@ err = write_data_to_disk(doc, locale_filename, data, len); g_free(data);
- if (err != 0) + if (G_UNLIKELY(err != 0)) { ui_set_statusbar(TRUE, _("Error saving file (%s)."), g_strerror(err)); dialogs_show_msgbox_with_secondary(GTK_MESSAGE_ERROR, @@ -1773,7 +1776,7 @@ store_saved_encoding(doc);
/* ignore the following things if we are quitting */ - if (! main_status.quitting) + if (G_LIKELY(! main_status.quitting)) { sci_set_savepoint(doc->editor->sci);
@@ -1807,10 +1810,10 @@ gint start_pos, search_pos; struct TextToFind ttf;
- g_return_val_if_fail(text != NULL, FALSE); - if (doc == NULL) + g_return_val_if_fail(G_LIKELY(text != NULL), FALSE); + if (G_UNLIKELY(doc == NULL)) return FALSE; - if (! *text) + if (G_UNLIKELY(! *text)) return TRUE;
start_pos = (inc) ? sci_get_selection_start(doc->editor->sci) : @@ -1869,8 +1872,10 @@ { gint selection_end, selection_start, search_pos;
- g_return_val_if_fail(doc != NULL && text != NULL, -1); - if (! *text) return -1; + g_return_val_if_fail(G_LIKELY(doc != NULL) && G_LIKELY(text != NULL), -1); + if (G_UNLIKELY(! *text)) + return -1; + /* Sci doesn't support searching backwards with a regex */ if (flags & SCFIND_REGEXP) search_backwards = FALSE; @@ -1939,9 +1944,12 @@ { gint selection_end, selection_start, search_pos;
- g_return_val_if_fail(doc != NULL && find_text != NULL && replace_text != NULL, -1); - if (! *find_text) return -1; + g_return_val_if_fail(G_LIKELY(doc != NULL) && G_LIKELY(find_text != NULL) && + G_LIKELY(replace_text != NULL), -1);
+ if (G_UNLIKELY(! *find_text)) + return -1; + /* Sci doesn't support searching backwards with a regex */ if (flags & SCFIND_REGEXP) search_backwards = FALSE; @@ -2036,9 +2044,13 @@
if (new_range_end != NULL) *new_range_end = -1; - g_return_val_if_fail(doc != NULL && find_text != NULL && replace_text != NULL, 0); - if (! *find_text || doc->readonly) return 0;
+ g_return_val_if_fail(G_LIKELY(doc != NULL) && G_LIKELY(find_text != NULL) && + G_LIKELY(replace_text != NULL), 0); + + if (G_UNLIKELY(! *find_text) || doc->readonly) + return 0; + sci = doc->editor->sci;
sci_start_undo_action(sci); @@ -2110,9 +2122,12 @@ gint max_column = 0, count = 0; gboolean replaced = FALSE;
- g_return_if_fail(doc != NULL && find_text != NULL && replace_text != NULL); - if (! *find_text) return; + g_return_if_fail(G_LIKELY(doc != NULL) && G_LIKELY(find_text != NULL) && + G_LIKELY(replace_text != NULL));
+ if (G_UNLIKELY(! *find_text)) + return; + selection_start = sci_get_selection_start(doc->editor->sci); selection_end = sci_get_selection_end(doc->editor->sci); /* do we have a selection? */ @@ -2208,9 +2223,12 @@ gint flags, gboolean escaped_chars) { gint len, count; - g_return_val_if_fail(doc != NULL && find_text != NULL && replace_text != NULL, FALSE); - if (! *find_text) return FALSE; + g_return_val_if_fail(G_LIKELY(doc != NULL) && G_LIKELY(find_text != NULL) && + G_LIKELY(replace_text != NULL), FALSE);
+ if (G_UNLIKELY(! *find_text)) + return FALSE; + len = sci_get_length(doc->editor->sci); count = document_replace_range( doc, find_text, replace_text, flags, 0, len, TRUE, NULL); @@ -2248,16 +2266,16 @@ gboolean success = FALSE;
/* if the filetype doesn't have a tag parser or it is a new file */ - if (doc == NULL || doc->file_type == NULL || - app->tm_workspace == NULL || - ! filetype_has_tags(doc->file_type) || ! doc->file_name) + if (G_UNLIKELY(doc == NULL) || G_UNLIKELY(doc->file_type == NULL) || + G_UNLIKELY(app->tm_workspace == NULL) || + ! filetype_has_tags(doc->file_type) || G_UNLIKELY(! doc->file_name)) { /* set the default (empty) tag list */ treeviews_update_tag_list(doc, FALSE); return; }
- if (doc->tm_file == NULL) + if (G_UNLIKELY(doc->tm_file == NULL)) { gchar *locale_filename = utils_get_locale_from_utf8(doc->file_name);
@@ -2282,7 +2300,7 @@ else { success = update_tags_from_buffer(doc); - if (! success) + if (G_UNLIKELY(! success)) geany_debug("tag list updating failed"); } treeviews_update_tag_list(doc, success); @@ -2297,7 +2315,7 @@ static GString *last_typenames = NULL; GString *s = NULL;
- if (app->tm_workspace) + if (G_LIKELY(app->tm_workspace)) { GPtrArray *tags_array = app->tm_workspace->work_object.tags_array;
@@ -2319,7 +2337,8 @@ last_typenames = s;
*types = s; - if (s == NULL) return FALSE; + if (s == NULL) + return FALSE; return TRUE; }
@@ -2336,7 +2355,7 @@ const GString *s; ScintillaObject *sci;
- g_return_val_if_fail(doc != NULL, FALSE); + g_return_val_if_fail(G_LIKELY(doc != NULL), FALSE); sci = doc->editor->sci;
switch (FILETYPE_ID(doc->file_type)) @@ -2353,7 +2372,7 @@ }
sci = doc->editor->sci; - if (sci != NULL && editor_lexer_get_type_keyword_idx(sci_get_lexer(sci)) == -1) + if (G_UNLIKELY(sci != NULL) && editor_lexer_get_type_keyword_idx(sci_get_lexer(sci)) == -1) return FALSE;
if (! get_project_typenames(&s, lang)) @@ -2367,7 +2386,7 @@ } return FALSE; } - g_return_val_if_fail(s != NULL, FALSE); + g_return_val_if_fail(G_LIKELY(s != NULL), FALSE);
for (n = 0; n < documents_array->len; n++) { @@ -2395,7 +2414,7 @@ { gboolean ft_changed;
- if (type == NULL || doc == NULL) + if (G_UNLIKELY(type == NULL) || G_UNLIKELY(doc == NULL)) return;
geany_debug("%s : %s (%s)", @@ -2437,8 +2456,9 @@ **/ void document_set_encoding(GeanyDocument *doc, const gchar *new_encoding) { - if (doc == NULL || new_encoding == NULL || - utils_str_equal(new_encoding, doc->encoding)) return; + if (G_UNLIKELY(doc == NULL) || G_UNLIKELY(new_encoding == NULL) || + utils_str_equal(new_encoding, doc->encoding)) + return;
g_free(doc->encoding); doc->encoding = g_strdup(new_encoding); @@ -2461,14 +2481,13 @@ while (g_trash_stack_height(&doc->priv->undo_actions) > 0) { a = g_trash_stack_pop(&doc->priv->undo_actions); - if (a != NULL) + if (G_LIKELY(a != NULL)) { switch (a->type) { case UNDO_ENCODING: g_free(a->data); break; default: break; } - g_free(a); } } @@ -2477,14 +2496,13 @@ while (g_trash_stack_height(&doc->priv->redo_actions) > 0) { a = g_trash_stack_pop(&doc->priv->redo_actions); - if (a != NULL) + if (G_LIKELY(a != NULL)) { switch (a->type) { case UNDO_ENCODING: g_free(a->data); break; default: break; } - g_free(a); } } @@ -2492,9 +2510,6 @@
if (! main_status.quitting && doc->editor != NULL) document_set_text_changed(doc, FALSE); - - /*geany_debug("%s: new undo stack height: %d, new redo stack height: %d", G_STRFUNC, - *g_trash_stack_height(&doc->undo_actions), g_trash_stack_height(&doc->redo_actions)); */ }
@@ -2502,7 +2517,7 @@ { undo_action *action;
- if (doc == NULL) + if (G_UNLIKELY(doc == NULL)) return;
action = g_new0(undo_action, 1); @@ -2513,15 +2528,12 @@
document_set_text_changed(doc, TRUE); ui_update_popup_reundo_items(doc); - - /*geany_debug("%s: new stack height: %d, added type: %d", G_STRFUNC, - *g_trash_stack_height(&doc->undo_actions), action->type); */ }
gboolean document_can_undo(GeanyDocument *doc) { - if (doc == NULL) + if (G_UNLIKELY(doc == NULL)) return FALSE;
if (g_trash_stack_height(&doc->priv->undo_actions) > 0 || sci_can_undo(doc->editor->sci)) @@ -2545,12 +2557,12 @@ { undo_action *action;
- if (doc == NULL) + if (G_UNLIKELY(doc == NULL)) return;
action = g_trash_stack_pop(&doc->priv->undo_actions);
- if (action == NULL) + if (G_UNLIKELY(action == NULL)) { /* fallback, should not be necessary */ geany_debug("%s: fallback used", G_STRFUNC); @@ -2597,13 +2609,12 @@
update_changed_state(doc); ui_update_popup_reundo_items(doc); - /*geany_debug("%s: new stack height: %d", G_STRFUNC, g_trash_stack_height(&doc->undo_actions));*/ }
gboolean document_can_redo(GeanyDocument *doc) { - if (doc == NULL) + if (G_UNLIKELY(doc == NULL)) return FALSE;
if (g_trash_stack_height(&doc->priv->redo_actions) > 0 || sci_can_redo(doc->editor->sci)) @@ -2617,12 +2628,12 @@ { undo_action *action;
- if (doc == NULL) + if (G_UNLIKELY(doc == NULL)) return;
action = g_trash_stack_pop(&doc->priv->redo_actions);
- if (action == NULL) + if (G_UNLIKELY(action == NULL)) { /* fallback, should not be necessary */ geany_debug("%s: fallback used", G_STRFUNC); @@ -2668,7 +2679,6 @@
update_changed_state(doc); ui_update_popup_reundo_items(doc); - /*geany_debug("%s: new stack height: %d", G_STRFUNC, g_trash_stack_height(&doc->redo_actions));*/ }
@@ -2676,7 +2686,7 @@ { undo_action *action;
- if (doc == NULL) + if G_UNLIKELY((doc == NULL)) return;
action = g_new0(undo_action, 1); @@ -2709,7 +2719,7 @@ /*static GdkColor orange = {0, 0xFFFF, 0x7FFF, 0};*/ GdkColor *color = NULL;
- if (doc == NULL) + if (G_UNLIKELY(doc == NULL)) return NULL;
if (doc->changed) @@ -2737,7 +2747,8 @@ */ GeanyDocument *document_index(gint idx) { - return (idx >= 0 && idx < (gint) documents_array->len) ? documents[idx] : NULL; + return (G_LIKELY(idx >= 0) && G_LIKELY(idx < (gint) documents_array->len)) ? + documents[idx] : NULL; }
@@ -2748,6 +2759,8 @@ gchar *text; GeanyDocument *doc;
+ g_return_val_if_fail(G_LIKELY(old_doc != NULL), NULL); + len = sci_get_length(old_doc->editor->sci) + 1; text = (gchar*) g_malloc(len); sci_get_text(old_doc->editor->sci, len, text); @@ -2774,12 +2787,12 @@ gboolean document_account_for_unsaved(void) { guint i, p, page_count, len = documents_array->len; + GeanyDocument *doc;
page_count = gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook)); for (p = 0; p < page_count; p++) { - GeanyDocument *doc = document_get_from_page(p); - + doc = document_get_from_page(p); if (doc->changed) { if (! dialogs_show_unsaved_file(doc)) @@ -2789,9 +2802,10 @@ /* all documents should now be accounted for, so ignore any changes */ for (i = 0; i < len; i++) { - if (documents[i]->is_valid && documents[i]->changed) + doc = documents[i]; + if (doc->is_valid && doc->changed) { - documents[i]->changed = FALSE; + doc->changed = FALSE; } } return TRUE; @@ -2889,7 +2903,7 @@ doc->priv->file_disk_status = FILE_MISSING; return 0; } - else if (doc->priv->mtime > t || st.st_mtime > t) + else if (G_UNLIKELY(doc->priv->mtime > t) || G_UNLIKELY(st.st_mtime > t)) { g_warning("%s: Something is wrong with the time stamps.", G_STRFUNC); } @@ -2912,7 +2926,7 @@ gboolean ret = FALSE; time_t t;
- if (file_prefs.disk_check_timeout == 0 || doc == NULL) + if (file_prefs.disk_check_timeout == 0 || G_UNLIKELY(doc == NULL)) return FALSE;
/* ignore documents that have never been saved to disk and remote files */
Modified: trunk/src/document.h =================================================================== --- trunk/src/document.h 2009-04-05 19:58:30 UTC (rev 3686) +++ trunk/src/document.h 2009-04-05 21:07:40 UTC (rev 3687) @@ -118,7 +118,7 @@ * @note This should not be used to check the result of the main API functions, * these only need a NULL-pointer check - @c document_get_current() != @c NULL. */ #define DOC_VALID(doc_ptr) \ - ((doc_ptr) != NULL && (doc_ptr)->is_valid) + (G_LIKELY((doc_ptr) != NULL) && G_LIKELY((doc_ptr)->is_valid))
/** * DOC_FILENAME returns the filename of the document passed or @@ -126,7 +126,7 @@ * This macro never returns NULL. **/ #define DOC_FILENAME(doc) \ - ((doc->file_name != NULL) ? (doc->file_name) : GEANY_STRING_UNTITLED) + (G_LIKELY(doc->file_name != NULL) ? (doc->file_name) : GEANY_STRING_UNTITLED)
Modified: trunk/src/editor.c =================================================================== --- trunk/src/editor.c 2009-04-05 19:58:30 UTC (rev 3686) +++ trunk/src/editor.c 2009-04-05 21:07:40 UTC (rev 3687) @@ -495,7 +495,7 @@ (*line)++; while (*line <= lineMaxSubord) { - if (force) + if (G_UNLIKELY(force)) { if (visLevels > 0) SSM(sci, SCI_SHOWLINES, *line, *line); @@ -511,7 +511,7 @@ levelLine = SSM(sci, SCI_GETFOLDLEVEL, *line, 0); if (levelLine & SC_FOLDLEVELHEADERFLAG) { - if (force) + if (G_UNLIKELY(force)) { if (visLevels > 1) SSM(sci, SCI_SETFOLDEXPANDED, *line, 1); @@ -597,7 +597,7 @@ { SCNotification *nt = data;
- g_return_val_if_fail(calltip.sci != NULL, FALSE); + g_return_val_if_fail(G_LIKELY(calltip.sci != NULL), FALSE);
SSM(calltip.sci, SCI_CALLTIPCANCEL, 0, 0); /* we use the position where the calltip was previously started as SCI_GETCURRENTPOS @@ -643,7 +643,7 @@ GeanyEditor *editor = data; gboolean retval;
- g_return_if_fail(editor != NULL); + g_return_if_fail(G_LIKELY(editor != NULL));
g_signal_emit_by_name(geany_object, "editor-notify", editor, scnt, &retval); } @@ -796,7 +796,7 @@ static gchar * get_whitespace(const GeanyIndentPrefs *iprefs, gint width) { - g_return_val_if_fail(width >= 0, NULL); + g_return_val_if_fail(G_LIKELY(width >= 0), NULL);
if (width == 0) return g_strdup(""); @@ -846,7 +846,7 @@
iprefs = *get_default_indent_prefs();
- if (!editor) + if (G_UNLIKELY(editor == NULL)) return &iprefs;
iprefs.type = editor->indent_type; @@ -997,7 +997,7 @@ gint size; const GeanyIndentPrefs *iprefs = editor_get_indent_prefs(editor);
- g_return_val_if_fail(line >= 0, 0); + g_return_val_if_fail(G_LIKELY(line >= 0), 0);
size = sci_get_line_indentation(sci, line);
@@ -1019,7 +1019,7 @@ gint size = get_indent_size_after_line(editor, line); const GeanyIndentPrefs *iprefs = editor_get_indent_prefs(editor);
- if (size > 0) + if (G_LIKELY(size > 0)) { gchar *text;
@@ -1122,8 +1122,7 @@
if (iprefs->auto_indent_mode < GEANY_AUTOINDENT_CURRENTCHARS) return; - if (editor == NULL || editor->document->file_type == NULL) - return; + g_return_if_fail(G_LIKELY(editor != NULL) && G_LIKELY(editor->document->file_type != NULL));
sci = editor->sci; doc = editor->document; @@ -1142,7 +1141,8 @@ line_buf[line_len - eol_char_len] = '\0'; while (x < (line_len - eol_char_len)) { - if (isspace(line_buf[x])) cnt++; + if (isspace(line_buf[x])) + cnt++; x++; } g_free(line_buf); @@ -1195,7 +1195,7 @@ gchar *chunk; ScintillaObject *sci;
- if (editor == NULL) + if (G_UNLIKELY(editor == NULL)) return; sci = editor->sci;
@@ -1269,7 +1269,7 @@ { static gchar cword[GEANY_MAX_WORD_LENGTH];
- g_return_val_if_fail(editor != NULL, FALSE); + g_return_val_if_fail(G_LIKELY(editor != NULL), FALSE);
read_current_word(editor, pos, cword, sizeof(cword), wordchars, FALSE);
@@ -1327,7 +1327,8 @@
static gboolean append_calltip(GString *str, const TMTag *tag, filetype_id ft_id) { - if (! tag->atts.entry.arglist) return FALSE; + if (! tag->atts.entry.arglist) + return FALSE;
if (tag->atts.entry.var_type) { @@ -1365,7 +1366,7 @@ GString *str = NULL; guint i;
- g_return_val_if_fail(ft && word && *word, NULL); + g_return_val_if_fail(G_LIKELY(ft) && G_LIKELY(word) && G_LIKELY(*word), NULL);
tags = tm_workspace_find(word, arg_types | tm_tag_class_t, attrs, FALSE, ft->lang); if (tags->len == 0) @@ -1450,7 +1451,7 @@ gchar *str; ScintillaObject *sci;
- if (editor == NULL || editor->document->file_type == NULL) + if (G_UNLIKELY(editor == NULL) || G_UNLIKELY(editor->document->file_type == NULL)) return FALSE; sci = editor->sci;
@@ -1464,7 +1465,8 @@ orig_pos = pos; pos = (lexer == SCLEX_LATEX) ? find_previous_brace(sci, pos) : find_start_bracket(sci, pos); - if (pos == -1) return FALSE; + if (G_UNLIKELY(pos == -1)) + return FALSE; }
/* the style 1 before the brace (which may be highlighted) */ @@ -1474,7 +1476,8 @@
word[0] = '\0'; editor_find_current_word(editor, pos - 1, word, sizeof word, NULL); - if (word[0] == '\0') return FALSE; + if (word[0] == '\0') + return FALSE;
str = find_calltip(word, editor->document->file_type); if (str) @@ -1496,7 +1499,7 @@ { GString *str;
- g_return_val_if_fail(editor != NULL, NULL); + g_return_val_if_fail(G_LIKELY(editor != NULL), NULL);
str = g_string_new(NULL); if (append_calltip(str, tag, FILETYPE_ID(editor->document->file_type))) @@ -1521,21 +1524,26 @@ GString *words; const gchar **entities = symbols_get_html_entities();
- if (*root != '&' || entities == NULL) return FALSE; + if (*root != '&' || G_UNLIKELY(entities == NULL)) + return FALSE;
words = g_string_sized_new(500); for (i = 0; ; i++) { - if (entities[i] == NULL) break; - else if (entities[i][0] == '#') continue; + if (G_UNLIKELY(entities[i] == NULL)) + break; + else if (G_UNLIKELY(entities[i][0] == '#')) + continue;
if (! strncmp(entities[i], root, rootlen)) { - if (j++ > 0) g_string_append_c(words, '\n'); + if (j++ > 0) + g_string_append_c(words, '\n'); g_string_append(words, entities[i]); } } - if (words->len > 0) show_autocomplete(sci, rootlen, words->str); + if (words->len > 0) + show_autocomplete(sci, rootlen, words->str); g_string_free(words, TRUE); return TRUE; } @@ -1550,8 +1558,9 @@ ScintillaObject *sci; GeanyDocument *doc;
- if (editor == NULL || editor->document->file_type == NULL) - return FALSE; + g_return_val_if_fail(G_LIKELY(editor != NULL) && + G_LIKELY(editor->document->file_type != NULL), FALSE); + sci = editor->sci; doc = editor->document;
@@ -1563,7 +1572,7 @@
for (j = 0; j < tags->len; ++j) { - if (j > 0) + if (G_LIKELY(j > 0)) g_string_append_c(words, '\n');
if (j == editor_prefs.autocompletion_max_entries) @@ -1610,13 +1619,15 @@ gchar *wordchars; GeanyFiletype *ft;
- if ((! editor_prefs.auto_complete_symbols && ! force) || - editor == NULL || editor->document->file_type == NULL) + if (! editor_prefs.auto_complete_symbols && ! force) return FALSE;
+ g_return_val_if_fail(G_LIKELY(editor != NULL) && + G_LIKELY(editor->document->file_type != NULL), FALSE); + /* If we are at the beginning of the document, we skip autocompletion as we can't determine the * necessary styling information */ - if (pos < 2) + if (G_UNLIKELY(pos < 2)) return FALSE;
sci = editor->sci; @@ -1670,8 +1681,8 @@ { ScintillaObject *sci;
- if (editor == NULL || editor->document->file_type == NULL) - return; + g_return_if_fail(G_LIKELY(editor != NULL) && G_LIKELY(editor->document->file_type != NULL)); + sci = editor->sci;
if (sci_get_char_at(sci, pos - 2) == '}') @@ -1783,7 +1794,7 @@ { gchar *needle;
- if (key == NULL || value == NULL) + if (G_UNLIKELY(key == NULL) || G_UNLIKELY(value == NULL)) return;
needle = g_strconcat("%", (gchar*) key, "%", NULL); @@ -1854,7 +1865,7 @@ GString *buf; const gchar cur_marker[] = "__GEANY_CURSOR_MARKER__";
- g_return_if_fail(text); + g_return_if_fail(G_LIKELY(text));
buf = g_string_new(text);
@@ -1908,7 +1919,7 @@ * Can, and should, be optimized to give better results */ void snippet_goto_next_cursor(ScintillaObject *sci, gint current_pos) { - if (snippet_queue) + if (G_LIKELY(snippet_queue)) { gpointer offset;
@@ -1963,7 +1974,7 @@
/* replace 'special' completions */ specials = g_hash_table_lookup(editor_prefs.snippets, "Special"); - if (specials != NULL) + if (G_LIKELY(specials != NULL)) { /* ugly hack using global_pattern */ snippets_global_pattern = pattern; @@ -2075,7 +2086,7 @@ const gchar *word; ScintillaObject *sci;
- if (editor == NULL) + if (G_UNLIKELY(editor == NULL)) return FALSE;
sci = editor->sci; @@ -2111,10 +2122,12 @@ { GString *words;
- if (editor == NULL) return; + if (G_UNLIKELY(editor == NULL)) + return;
words = symbols_get_macro_list(); - if (words == NULL) return; + if (G_UNLIKELY(words == NULL)) + return;
SSM(editor->sci, SCI_USERLISTSHOW, 1, (sptr_t) words->str); g_string_free(words, TRUE); @@ -2294,8 +2307,7 @@ gchar *str_begin, *str_end, *co, *cc; gint line_len;
- if (editor == NULL || editor->document->file_type == NULL) - return; + g_return_if_fail(G_LIKELY(editor != NULL) && G_LIKELY(editor->document->file_type != NULL));
eol = editor_get_eol_char(editor); co = editor->document->file_type->comment_open; @@ -2320,8 +2332,7 @@ gchar *linebuf; GeanyDocument *doc;
- if (editor == NULL || editor->document->file_type == NULL) - return; + g_return_if_fail(G_LIKELY(editor != NULL) && G_LIKELY(editor->document->file_type != NULL)); doc = editor->document;
/* remove comment open chars */ @@ -2366,8 +2377,8 @@ gboolean break_loop = FALSE, single_line = FALSE; GeanyFiletype *ft;
- if (editor == NULL || editor->document->file_type == NULL) - return 0; + g_return_val_if_fail(G_LIKELY(editor != NULL) && + G_LIKELY(editor->document->file_type != NULL), 0);
if (line < 0) { /* use selection or current line */ @@ -2398,11 +2409,11 @@
co = ft->comment_open; cc = ft->comment_close; - if (co == NULL) + if (G_UNLIKELY(co == NULL)) return 0;
co_len = strlen(co); - if (co_len == 0) + if (G_UNLIKELY(co_len == 0)) return 0;
SSM(editor->sci, SCI_BEGINUNDOACTION, 0, 0); @@ -2521,8 +2532,7 @@ gsize tm_len = strlen(editor_prefs.comment_toggle_mark); GeanyFiletype *ft;
- if (editor == NULL || editor->document->file_type == NULL) - return; + g_return_if_fail(G_LIKELY(editor != NULL) && G_LIKELY(editor->document->file_type != NULL));
sel_start = sci_get_selection_start(editor->sci); sel_end = sci_get_selection_end(editor->sci); @@ -2546,11 +2556,11 @@
co = ft->comment_open; cc = ft->comment_close; - if (co == NULL) + if (G_UNLIKELY(co == NULL)) return;
co_len = strlen(co); - if (co_len == 0) + if (G_UNLIKELY(co_len == 0)) return;
SSM(editor->sci, SCI_BEGINUNDOACTION, 0, 0); @@ -2690,8 +2700,7 @@ gboolean break_loop = FALSE, single_line = FALSE; GeanyFiletype *ft;
- if (editor == NULL || editor->document->file_type == NULL) - return; + g_return_if_fail(G_LIKELY(editor != NULL) && G_LIKELY(editor->document->file_type != NULL));
if (line < 0) { /* use selection or current line */ @@ -2722,11 +2731,11 @@
co = ft->comment_open; cc = ft->comment_close; - if (co == NULL) + if (G_UNLIKELY(co == NULL)) return;
co_len = strlen(co); - if (co_len == 0) + if (G_UNLIKELY(co_len == 0)) return;
SSM(editor->sci, SCI_BEGINUNDOACTION, 0, 0); @@ -2939,7 +2948,7 @@ whitespace = " "; }
- if (style == SCE_D_COMMENTNESTED) + if (G_UNLIKELY(style == SCE_D_COMMENTNESTED)) continuation = "+"; /* for nested comments in D */
result = g_strconcat(whitespace, continuation, " ", NULL); @@ -3251,11 +3260,10 @@ gboolean have_multiline_comment = FALSE; GeanyDocument *doc;
- if (editor == NULL || editor->document->file_type == NULL || - editor->document->file_type->comment_open == NULL) - { - return; - } + g_return_if_fail(G_LIKELY(editor != NULL) && + G_LIKELY(editor->document->file_type != NULL) && + G_LIKELY(editor->document->file_type->comment_open != NULL)); + doc = editor->document;
if (doc->file_type->comment_close != NULL && strlen(doc->file_type->comment_close) > 0) @@ -3312,7 +3320,7 @@ gint vis1, los, delta; GtkWidget *wid;
- if (editor == NULL) + if (G_UNLIKELY(editor == NULL)) return;
wid = GTK_WIDGET(editor->sci); @@ -3341,6 +3349,9 @@ gchar *text; GeanyIndentPrefs iprefs = *editor_get_indent_prefs(editor);
+ if (G_UNLIKELY(editor == NULL)) + return; + switch (iprefs.type) { case GEANY_INDENT_TYPE_TABS: @@ -3363,7 +3374,7 @@ gint start; gint end;
- g_return_if_fail(editor != NULL); + g_return_if_fail(G_LIKELY(editor != NULL));
pos = SSM(editor->sci, SCI_GETCURRENTPOS, 0, 0); start = SSM(editor->sci, SCI_WORDSTARTPOSITION, pos, TRUE); @@ -3389,7 +3400,7 @@ { gint start, end, line;
- g_return_if_fail(editor != NULL); + g_return_if_fail(G_LIKELY(editor != NULL));
start = sci_get_selection_start(editor->sci); end = sci_get_selection_end(editor->sci); @@ -3463,7 +3474,7 @@ { gint pos_start, pos_end, line_start, line_found;
- g_return_if_fail(editor != NULL); + g_return_if_fail(G_LIKELY(editor != NULL));
line_start = SSM(editor->sci, SCI_LINEFROMPOSITION, SSM(editor->sci, SCI_GETCURRENTPOS, 0, 0), 0); @@ -3522,7 +3533,7 @@ gint first_sel_start, first_sel_end; ScintillaObject *sci;
- g_return_if_fail(editor != NULL); + g_return_if_fail(G_LIKELY(editor != NULL));
sci = editor->sci;
@@ -3566,7 +3577,7 @@ gint i, first_line, last_line, line_start, indentation_end, count = 0; gint sel_start, sel_end, first_line_offset = 0;
- g_return_if_fail(editor != NULL); + g_return_if_fail(G_LIKELY(editor != NULL));
sel_start = sci_get_selection_start(editor->sci); sel_end = sci_get_selection_end(editor->sci); @@ -3640,7 +3651,7 @@ { gchar *s = NULL;
- if (editor == NULL) + if (G_UNLIKELY(editor == NULL)) return NULL;
if (sci_get_lines_selected(editor->sci) == 1) @@ -3669,7 +3680,7 @@ { gint vis1, los;
- if (editor == NULL) + if (G_UNLIKELY(editor == NULL)) return FALSE;
/* If line is wrapped the result may occur on another virtual line than the first and may be @@ -3691,7 +3702,7 @@ { gint line;
- if (editor == NULL) + if (G_UNLIKELY(editor == NULL)) return;
line = sci_get_current_line(editor->sci); @@ -3730,10 +3741,10 @@ { glong last_pos;
- g_return_if_fail(editor != NULL); + g_return_if_fail(G_LIKELY(editor != NULL));
last_pos = sci_get_length(editor->sci); - if (last_pos > 0) + if (G_LIKELY(last_pos > 0)) { sci_indicator_set(editor->sci, indic); sci_indicator_clear(editor->sci, 0, last_pos); @@ -3757,7 +3768,7 @@ guint i = 0, len; gchar *linebuf;
- if (editor == NULL) + if (G_UNLIKELY(editor == NULL)) return;
start = sci_get_position_from_line(editor->sci, line); @@ -3798,7 +3809,7 @@ */ void editor_indicator_set_on_range(GeanyEditor *editor, gint indic, gint start, gint end) { - if (editor == NULL || start >= end) + if (G_UNLIKELY(editor == NULL) || G_UNLIKELY(start >= end)) return;
sci_indicator_set(editor->sci, indic); @@ -3810,7 +3821,7 @@ * the replacement will also start with 0x... */ void editor_insert_color(GeanyEditor *editor, const gchar *colour) { - g_return_if_fail(editor != NULL); + g_return_if_fail(G_LIKELY(editor != NULL));
if (sci_has_selection(editor->sci)) { @@ -3839,7 +3850,7 @@ { gint mode = file_prefs.default_eol_character;
- if (editor != NULL) + if (G_LIKELY(editor != NULL)) mode = sci_get_eol_mode(editor->sci);
switch (mode) @@ -3856,7 +3867,7 @@ { gint mode = file_prefs.default_eol_character;
- if (editor != NULL) + if (G_LIKELY(editor != NULL)) mode = sci_get_eol_mode(editor->sci);
switch (mode) @@ -3872,7 +3883,7 @@ { gint mode = file_prefs.default_eol_character;
- if (editor != NULL) + if (G_LIKELY(editor != NULL)) mode = sci_get_eol_mode(editor->sci);
switch (mode) @@ -3888,7 +3899,7 @@ { gint lines, first, i;
- if (editor == NULL || ! editor_prefs.folding) + if (G_UNLIKELY(editor == NULL) || ! editor_prefs.folding) return;
lines = sci_get_line_count(editor->sci); @@ -3926,7 +3937,7 @@ gchar *tab_str; struct TextToFind ttf;
- if (editor == NULL) + if (G_UNLIKELY(editor == NULL)) return;
sci_start_undo_action(editor->sci); @@ -3965,10 +3976,10 @@ gint tab_len; struct TextToFind ttf;
- if (editor == NULL) + if (G_UNLIKELY(editor == NULL)) return;
- if (tab_len_f < 0.0) + if (G_UNLIKELY(tab_len_f < 0.0)) tab_len_f = sci_get_tab_width(editor->sci);
if (! dialogs_show_input_numeric( @@ -4045,11 +4056,11 @@ gboolean append_newline = (max_lines == 1); gint end_document = sci_get_position_from_line(editor->sci, max_lines);
- if (max_lines > 1) + if (G_LIKELY(max_lines > 1)) { append_newline = end_document > sci_get_position_from_line(editor->sci, max_lines - 1); } - if (append_newline) + if (G_LIKELY(append_newline)) { const gchar *eol = "\n"; switch (sci_get_eol_mode(editor->sci)) @@ -4072,7 +4083,7 @@ gchar *font_name; PangoFontDescription *pfd;
- g_return_if_fail(editor); + g_return_if_fail(G_LIKELY(editor));
pfd = pango_font_description_from_string(font); size = pango_font_description_get_size(pfd) / PANGO_SCALE; @@ -4095,7 +4106,7 @@
void editor_set_line_wrapping(GeanyEditor *editor, gboolean wrap) { - g_return_if_fail(editor != NULL); + g_return_if_fail(G_LIKELY(editor != NULL));
editor->line_wrapping = wrap; sci_set_lines_wrapped(editor->sci, wrap); @@ -4133,8 +4144,8 @@ { gint pos;
- g_return_val_if_fail(editor, FALSE); - if (line < 0 || line >= sci_get_line_count(editor->sci)) + g_return_val_if_fail(G_LIKELY(editor), FALSE); + if (G_UNLIKELY(line < 0) || G_UNLIKELY(line >= sci_get_line_count(editor->sci))) return FALSE;
pos = sci_get_position_from_line(editor->sci, line); @@ -4148,8 +4159,8 @@ { gint page_num;
- g_return_val_if_fail(editor, FALSE); - if (pos < 0) + g_return_val_if_fail(G_LIKELY(editor), FALSE); + if (G_UNLIKELY(pos < 0)) return FALSE;
if (mark) @@ -4179,12 +4190,12 @@
/* Handle scroll events if Alt is pressed and scroll whole pages instead of a * few lines only, maybe this could/should be done in Scintilla directly */ - if (event->state & GDK_MOD1_MASK) + if (G_UNLIKELY(event->state & GDK_MOD1_MASK)) { sci_send_command(editor->sci, (event->direction == GDK_SCROLL_DOWN) ? SCI_PAGEDOWN : SCI_PAGEUP); return TRUE; } - else if (event->state & GDK_SHIFT_MASK) + else if (G_UNLIKELY(event->state & GDK_SHIFT_MASK)) { gint amount = (event->direction == GDK_SCROLL_DOWN) ? 8 : -8;
@@ -4430,7 +4441,7 @@ { ScintillaObject *sci;
- g_return_if_fail(editor != NULL); + g_return_if_fail(G_UNLIKELY(editor != NULL));
sci = editor->sci;
Modified: trunk/src/encodings.c =================================================================== --- trunk/src/encodings.c 2009-04-05 19:58:30 UTC (rev 3686) +++ trunk/src/encodings.c 2009-04-05 21:07:40 UTC (rev 3687) @@ -150,7 +150,8 @@ { gint i;
- if (charset == NULL) return GEANY_ENCODING_UTF_8; + if (G_UNLIKELY(charset == NULL)) + return GEANY_ENCODING_UTF_8;
i = 0; while (i < GEANY_ENCODINGS_MAX) @@ -168,7 +169,8 @@ { gint i;
- if (charset == NULL) return &encodings[GEANY_ENCODING_UTF_8]; + if (G_UNLIKELY(charset == NULL)) + return &encodings[GEANY_ENCODING_UTF_8];
i = 0; while (i < GEANY_ENCODINGS_MAX) @@ -185,7 +187,7 @@
const GeanyEncoding *encodings_get_from_index(gint idx) { - g_return_val_if_fail(idx >= 0 && idx < GEANY_ENCODINGS_MAX, NULL); + g_return_val_if_fail(G_LIKELY(idx >= 0) && G_LIKELY(idx < GEANY_ENCODINGS_MAX), NULL);
return &encodings[idx]; } @@ -204,7 +206,7 @@ **/ const gchar* encodings_get_charset_from_index(gint idx) { - g_return_val_if_fail(idx >= 0 && idx < GEANY_ENCODINGS_MAX, NULL); + g_return_val_if_fail(G_LIKELY(idx >= 0) && G_LIKELY(idx < GEANY_ENCODINGS_MAX), NULL);
return encodings[idx].charset; } @@ -212,9 +214,9 @@
gchar *encodings_to_string(const GeanyEncoding* enc) { - g_return_val_if_fail(enc != NULL, NULL); - g_return_val_if_fail(enc->name != NULL, NULL); - g_return_val_if_fail(enc->charset != NULL, NULL); + g_return_val_if_fail(G_LIKELY(enc != NULL), NULL); + g_return_val_if_fail(G_LIKELY(enc->name != NULL), NULL); + g_return_val_if_fail(G_LIKELY(enc->charset != NULL), NULL);
return g_strdup_printf("%s (%s)", enc->name, enc->charset); } @@ -222,8 +224,8 @@
const gchar *encodings_get_charset(const GeanyEncoding* enc) { - g_return_val_if_fail(enc != NULL, NULL); - g_return_val_if_fail(enc->charset != NULL, NULL); + g_return_val_if_fail(G_LIKELY(enc != NULL), NULL); + g_return_val_if_fail(G_LIKELY(enc->charset != NULL), NULL);
return enc->charset; } @@ -235,7 +237,7 @@ { gint i;
- g_return_if_fail(charset != NULL); + g_return_if_fail(G_LIKELY(charset != NULL));
i = 0; while (i < GEANY_ENCODINGS_MAX) @@ -244,7 +246,7 @@ break; i++; } - if (i == GEANY_ENCODINGS_MAX) + if (G_UNLIKELY(i == GEANY_ENCODINGS_MAX)) i = GEANY_ENCODING_UTF_8; /* fallback to UTF-8 */
/* ignore_callback has to be set by the caller */ @@ -261,7 +263,7 @@ static void regex_compile(regex_t *preg, const gchar *pattern) { gint retval = regcomp(preg, pattern, REG_EXTENDED | REG_ICASE); - if (retval != 0) + if (G_UNLIKELY(retval != 0)) { gchar errmsg[512]; regerror(retval, preg, errmsg, 512); @@ -279,7 +281,7 @@ gchar *encoding = NULL; regmatch_t pmatch[10];
- if (! pregs_loaded || buffer == NULL) + if (G_UNLIKELY(! pregs_loaded) || G_UNLIKELY(buffer == NULL)) return NULL;
if (size > 512) @@ -302,10 +304,11 @@ void encodings_finalize(void) { #ifdef HAVE_REGCOMP - if (pregs_loaded) + if (G_LIKELY(pregs_loaded)) { - guint i; - for (i = 0; i < G_N_ELEMENTS(pregs); i++) + guint i, len; + len = G_N_ELEMENTS(pregs); + for (i = 0; i < len; i++) { regfree(&pregs[i]); } @@ -328,7 +331,7 @@ init_encodings();
#ifdef HAVE_REGCOMP - if (! pregs_loaded) + if (G_UNLIKELY(! pregs_loaded)) { regex_compile(&pregs[0], PATTERN_HTMLMETA); regex_compile(&pregs[1], PATTERN_CODING); @@ -445,8 +448,8 @@ gchar* converted_contents = NULL; gsize bytes_written;
- g_return_val_if_fail(buffer != NULL, NULL); - g_return_val_if_fail(charset != NULL, NULL); + g_return_val_if_fail(G_LIKELY(buffer != NULL), NULL); + g_return_val_if_fail(G_LIKELY(charset != NULL), NULL);
converted_contents = g_convert(buffer, size, "UTF-8", charset, NULL, &bytes_written, &conv_error); @@ -468,7 +471,8 @@ geany_debug("Couldn't convert from %s to UTF-8.", charset);
utf8_content = NULL; - if (converted_contents != NULL) g_free(converted_contents); + if (converted_contents != NULL) + g_free(converted_contents); } else { @@ -499,7 +503,7 @@ gchar *utf8_content; gboolean check_regex = FALSE; gboolean check_locale = FALSE; - gint i; + gint i, len;
if ((gint)size == -1) { @@ -508,7 +512,8 @@
#ifdef HAVE_REGCOMP /* first try to read the encoding from the file content */ - for (i = 0; i < (gint) G_N_ELEMENTS(pregs) && ! check_regex; i++) + len = (gint) G_N_ELEMENTS(pregs); + for (i = 0; i < len && ! check_regex; i++) { if ((regex_charset = regex_match(&pregs[i], buffer, size)) != NULL) check_regex = TRUE; @@ -520,7 +525,7 @@
for (i = 0; i < GEANY_ENCODINGS_MAX; i++) { - if (i == encodings[GEANY_ENCODING_NONE].idx || i == -1) + if (G_UNLIKELY(i == encodings[GEANY_ENCODING_NONE].idx) || G_UNLIKELY(i == -1)) continue;
if (check_regex) @@ -539,17 +544,17 @@ charset = encodings[i].charset;
- if (charset == NULL) + if (G_UNLIKELY(charset == NULL)) continue;
geany_debug("Trying to convert %" G_GSIZE_FORMAT " bytes of data from %s into UTF-8.", size, charset); utf8_content = encodings_convert_to_utf8_from_charset(buffer, size, charset, FALSE);
- if (utf8_content != NULL) + if (G_LIKELY(utf8_content != NULL)) { if (used_encoding != NULL) { - if (*used_encoding != NULL) + if (G_UNLIKELY(*used_encoding != NULL)) { geany_debug("%s:%d", __FILE__, __LINE__); g_free(*used_encoding); @@ -625,7 +630,8 @@
gboolean encodings_is_unicode_charset(const gchar *string) { - if (string != NULL && (strncmp(string, "UTF", 3) == 0 || strncmp(string, "UCS", 3) == 0)) + if (G_LIKELY(string != NULL) && + (strncmp(string, "UTF", 3) == 0 || strncmp(string, "UCS", 3) == 0)) { return TRUE; }
Modified: trunk/src/filetypes.c =================================================================== --- trunk/src/filetypes.c 2009-04-05 19:58:30 UTC (rev 3686) +++ trunk/src/filetypes.c 2009-04-05 21:07:40 UTC (rev 3687) @@ -598,9 +598,9 @@ { const GeanyFiletype *ft1 = pft1, *ft2 = pft2;
- if (ft1->id == GEANY_FILETYPES_NONE) + if (G_UNLIKELY(ft1->id == GEANY_FILETYPES_NONE)) return -1; - if (ft2->id == GEANY_FILETYPES_NONE) + if (G_UNLIKELY(ft2->id == GEANY_FILETYPES_NONE)) return 1;
return utils_str_casecmp(ft1->title, ft2->title); @@ -611,8 +611,8 @@ * and set the filetype::id field. */ static void filetype_add(GeanyFiletype *ft) { - g_return_if_fail(ft); - g_return_if_fail(ft->name); + g_return_if_fail(G_LIKELY(ft)); + g_return_if_fail(G_LIKELY(ft->name));
ft->id = filetypes_array->len; /* len will be the index for filetype_array */ g_ptr_array_add(filetypes_array, ft); @@ -627,8 +627,8 @@ { filetype_id ft_id;
- g_return_if_fail(filetypes_array == NULL); - g_return_if_fail(filetypes_hash == NULL); + g_return_if_fail(G_LIKELY(filetypes_array == NULL)); + g_return_if_fail(G_LIKELY(filetypes_hash == NULL));
filetypes_array = g_ptr_array_sized_new(GEANY_MAX_BUILT_IN_FILETYPES); filetypes_hash = g_hash_table_new(g_str_hash, g_str_equal); @@ -736,7 +736,7 @@ gint j; gboolean ret = FALSE;
- if (ft->id == GEANY_FILETYPES_NONE) + if (G_UNLIKELY(ft->id == GEANY_FILETYPES_NONE)) return FALSE;
for (j = 0; ft->pattern[j] != NULL; j++) @@ -902,7 +902,7 @@ if (ft != NULL) return ft;
- if (utf8_filename == NULL) + if (G_UNLIKELY(utf8_filename == NULL)) return filetypes[GEANY_FILETYPES_NONE];
return filetypes_detect_from_extension(utf8_filename); @@ -915,7 +915,7 @@ GeanyFiletype *ft; gchar *line;
- if (doc == NULL) + if (G_UNLIKELY(doc == NULL)) return filetypes[GEANY_FILETYPES_NONE];
line = sci_get_line(doc->editor->sci, 0); @@ -943,7 +943,7 @@
f = g_fopen(locale_name, "r"); g_free(locale_name); - if (f != NULL) + if (G_LIKELY(f != NULL)) { if (fgets(line, sizeof(line), f) != NULL) { @@ -962,7 +962,7 @@ /* ignore_callback has to be set by the caller */ g_return_if_fail(ignore_callback);
- if (ft == NULL) + if (G_UNLIKELY(ft == NULL)) ft = filetypes[GEANY_FILETYPES_NONE];
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(ft->priv->menu_item), TRUE); @@ -974,7 +974,7 @@ gpointer user_data) { GeanyDocument *doc = document_get_current(); - if (ignore_callback || doc == NULL) + if (G_UNLIKELY(ignore_callback) || G_UNLIKELY(doc == NULL)) return;
document_set_filetype(doc, (GeanyFiletype*)user_data); @@ -999,7 +999,7 @@ /* Remove a filetype pointer from the list of available filetypes. */ static void filetype_remove(GeanyFiletype *ft) { - g_return_if_fail(ft); + g_return_if_fail(G_LIKELY(ft));
g_ptr_array_remove(filetypes_array, ft);
@@ -1027,7 +1027,7 @@ { GeanyFiletype *ft = data;
- g_return_if_fail(ft != NULL); + g_return_if_fail(G_LIKELY(ft != NULL));
g_free(ft->name); g_free(ft->title); @@ -1049,10 +1049,10 @@
/* frees the array and all related pointers */ -void filetypes_free_types() +void filetypes_free_types(void) { - g_return_if_fail(filetypes_array != NULL); - g_return_if_fail(filetypes_hash != NULL); + g_return_if_fail(G_LIKELY(filetypes_array != NULL)); + g_return_if_fail(G_LIKELY(filetypes_hash != NULL));
g_ptr_array_foreach(filetypes_array, filetype_free, NULL); g_ptr_array_free(filetypes_array, TRUE); @@ -1070,7 +1070,7 @@ /* default extension */ result = g_key_file_get_string(configh, "settings", "extension", NULL); if (result == NULL) result = g_key_file_get_string(config, "settings", "extension", NULL); - if (result != NULL) + if (G_LIKELY(result != NULL)) { setptr(filetypes[ft_id]->extension, result); } @@ -1078,7 +1078,7 @@ /* read comment notes */ result = g_key_file_get_string(configh, "settings", "comment_open", NULL); if (result == NULL) result = g_key_file_get_string(config, "settings", "comment_open", NULL); - if (result != NULL) + if (G_LIKELY(result != NULL)) { g_free(filetypes[ft_id]->comment_open); filetypes[ft_id]->comment_open = result; @@ -1086,7 +1086,7 @@
result = g_key_file_get_string(configh, "settings", "comment_close", NULL); if (result == NULL) result = g_key_file_get_string(config, "settings", "comment_close", NULL); - if (result != NULL) + if (G_LIKELY(result != NULL)) { g_free(filetypes[ft_id]->comment_close); filetypes[ft_id]->comment_close = result; @@ -1106,7 +1106,7 @@ /* read context action */ result = g_key_file_get_string(configh, "settings", "context_action_cmd", NULL); if (result == NULL) result = g_key_file_get_string(config, "settings", "context_action_cmd", NULL); - if (result != NULL) + if (G_LIKELY(result != NULL)) { filetypes[ft_id]->context_action_cmd = result; } @@ -1114,7 +1114,7 @@ /* read build settings */ result = g_key_file_get_string(configh, "build_settings", "compiler", NULL); if (result == NULL) result = g_key_file_get_string(config, "build_settings", "compiler", NULL); - if (result != NULL) + if (G_LIKELY(result != NULL)) { filetypes[ft_id]->programs->compiler = result; filetypes[ft_id]->actions->can_compile = TRUE; @@ -1130,7 +1130,7 @@
result = g_key_file_get_string(configh, "build_settings", "run_cmd", NULL); if (result == NULL) result = g_key_file_get_string(config, "build_settings", "run_cmd", NULL); - if (result != NULL) + if (G_LIKELY(result != NULL)) { filetypes[ft_id]->programs->run_cmd = result; filetypes[ft_id]->actions->can_exec = TRUE; @@ -1159,7 +1159,7 @@ { GError *error = NULL; gboolean done = g_key_file_load_from_file(key_file, file, flags, &error); - if (! done && error != NULL) + if (G_UNLIKELY(! done) && G_UNLIKELY(error != NULL)) { geany_debug("Failed to open %s (%s)", file, error->message); g_error_free(error); @@ -1176,16 +1176,16 @@ GKeyFile *config, *config_home; GeanyFiletypePrivate *pft;
- g_return_if_fail(ft_id >= 0 && ft_id < (gint) filetypes_array->len); + g_return_if_fail(G_LIKELY(ft_id >= 0) && G_LIKELY(ft_id < (gint) filetypes_array->len));
pft = filetypes[ft_id]->priv;
/* when reloading, proceed only if the settings were already loaded */ - if (reload && ! pft->keyfile_loaded) + if (reload && G_UNLIKELY(! pft->keyfile_loaded)) return;
/* when not reloading, load the settings only once */ - if (! reload && pft->keyfile_loaded) + if (! reload && G_LIKELY(pft->keyfile_loaded)) return; pft->keyfile_loaded = TRUE;
@@ -1233,7 +1233,7 @@ }
-void filetypes_save_commands() +void filetypes_save_commands(void) { gchar *conf_prefix = g_strconcat(app->configdir, G_DIR_SEPARATOR_S GEANY_FILEDEFS_SUBDIR G_DIR_SEPARATOR_S "filetypes.", NULL); @@ -1245,7 +1245,8 @@ GKeyFile *config_home; gchar *fname, *ext, *data;
- if (! bp->modified) continue; + if (G_LIKELY(! bp->modified)) + continue;
ext = filetypes_get_conf_extension(i); fname = g_strconcat(conf_prefix, ext, NULL); @@ -1254,13 +1255,13 @@ config_home = g_key_file_new(); g_key_file_load_from_file(config_home, fname, G_KEY_FILE_KEEP_COMMENTS, NULL);
- if (bp->compiler && *bp->compiler) + if (NZV(bp->compiler)) g_key_file_set_string(config_home, "build_settings", "compiler", bp->compiler); - if (bp->linker && *bp->linker) + if (NZV(bp->linker)) g_key_file_set_string(config_home, "build_settings", "linker", bp->linker); - if (bp->run_cmd && *bp->run_cmd) + if (NZV(bp->run_cmd)) g_key_file_set_string(config_home, "build_settings", "run_cmd", bp->run_cmd); - if (bp->run_cmd2 && *bp->run_cmd2) + if (NZV(bp->run_cmd2)) g_key_file_set_string(config_home, "build_settings", "run_cmd2", bp->run_cmd2);
data = g_key_file_to_data(config_home, NULL, NULL); @@ -1274,7 +1275,7 @@
/* create one file filter which has each file pattern of each filetype */ -GtkFileFilter *filetypes_create_file_filter_all_source() +GtkFileFilter *filetypes_create_file_filter_all_source(void) { GtkFileFilter *new_filter; guint i, j; @@ -1284,7 +1285,7 @@
for (i = 0; i < filetypes_array->len; i++) { - if (i == GEANY_FILETYPES_NONE) + if (G_UNLIKELY(i == GEANY_FILETYPES_NONE)) continue;
for (j = 0; filetypes[i]->pattern[j]; j++) @@ -1302,7 +1303,7 @@ gint i; const gchar *title;
- g_return_val_if_fail(ft != NULL, NULL); + g_return_val_if_fail(G_LIKELY(ft != NULL), NULL);
new_filter = gtk_file_filter_new(); title = ft->id == GEANY_FILETYPES_NONE ? _("All files") : ft->title; @@ -1320,7 +1321,7 @@ /* Indicates whether there is a tag parser for the filetype or not. */ gboolean filetype_has_tags(GeanyFiletype *ft) { - g_return_val_if_fail(ft != NULL, FALSE); + g_return_val_if_fail(G_LIKELY(ft != NULL), FALSE);
return ft->lang >= 0; } @@ -1339,7 +1340,7 @@ g_return_val_if_fail(NZV(name), NULL);
ft = g_hash_table_lookup(filetypes_hash, name); - if (ft == NULL) + if (G_UNLIKELY(ft == NULL)) geany_debug("Could not find filetype '%s'.", name); return ft; } @@ -1359,7 +1360,7 @@
ft->priv->error_regex_compiled = (retval == 0); /* prevent recompilation */
- if (retval != 0) + if (G_UNLIKELY(retval != 0)) { gchar buf[256]; regerror(retval, regex, buf, sizeof buf); @@ -1388,9 +1389,9 @@ if (!NZV(ft->error_regex_string)) return FALSE;
- if (!ft->priv->error_regex_compiled) + if (G_UNLIKELY(!ft->priv->error_regex_compiled)) compile_regex(ft, regex); - if (!ft->priv->error_regex_compiled) /* regex error */ + if (G_UNLIKELY(!ft->priv->error_regex_compiled)) /* regex error */ return FALSE;
if (regexec(regex, message, G_N_ELEMENTS(pmatch), pmatch, 0) != 0) @@ -1453,7 +1454,7 @@ g_key_file_has_key(userconfig, "Extensions", filetypes[i]->name, NULL); list = g_key_file_get_string_list( (userset) ? userconfig : sysconfig, "Extensions", filetypes[i]->name, &len, NULL); - if (list && len > 0) + if (G_LIKELY(list) && G_LIKELY(len > 0)) { g_strfreev(filetypes[i]->pattern); filetypes[i]->pattern = list; @@ -1477,7 +1478,8 @@ */ GeanyFiletype *filetypes_index(gint idx) { - return (idx >= 0 && idx < (gint) filetypes_array->len) ? filetypes[idx] : NULL; + return (G_LIKELY(idx >= 0) && G_LIKELY(idx < (gint) filetypes_array->len)) ? + filetypes[idx] : NULL; }
@@ -1489,7 +1491,7 @@
foreach_slist(ft, node, filetypes_by_title) { - if (ft->id != GEANY_FILETYPES_NONE) + if (G_LIKELY(ft->id != GEANY_FILETYPES_NONE)) callback(ft, user_data); } }
Modified: trunk/src/geanymenubuttonaction.c =================================================================== --- trunk/src/geanymenubuttonaction.c 2009-04-05 19:58:30 UTC (rev 3686) +++ trunk/src/geanymenubuttonaction.c 2009-04-05 21:07:40 UTC (rev 3687) @@ -68,7 +68,7 @@ { GeanyMenubuttonActionPrivate *priv = GEANY_MENU_BUTTON_ACTION_GET_PRIVATE(data);
- if (! priv->menu_added) + if (G_UNLIKELY(! priv->menu_added)) { gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(priv->button), priv->menu); priv->menu_added = TRUE; @@ -161,7 +161,7 @@ { GeanyMenubuttonActionPrivate *priv;
- g_return_val_if_fail(action != NULL, NULL); + g_return_val_if_fail(G_LIKELY(action != NULL), NULL);
priv = GEANY_MENU_BUTTON_ACTION_GET_PRIVATE(action);
Modified: trunk/src/geanyobject.c =================================================================== --- trunk/src/geanyobject.c 2009-04-05 19:58:30 UTC (rev 3686) +++ trunk/src/geanyobject.c 2009-04-05 21:07:40 UTC (rev 3687) @@ -66,7 +66,7 @@ register GCClosure* cc = (GCClosure*) closure; register gpointer data1, data2;
- g_return_if_fail(n_param_vals == 4); + g_return_if_fail(G_LIKELY(n_param_vals == 4));
if (G_CCLOSURE_SWAP_DATA(closure)) { @@ -112,8 +112,8 @@ register gpointer data1, data2; gboolean v_return;
- g_return_if_fail(return_value != NULL); - g_return_if_fail(n_param_values == 3); + g_return_if_fail(G_LIKELY(return_value != NULL)); + g_return_if_fail(G_LIKELY(n_param_values == 3));
if (G_CCLOSURE_SWAP_DATA(closure)) { @@ -260,12 +260,12 @@
static void geany_object_init(GeanyObject *self) { - + /* nothing to do */ }
-GObject* geany_object_new(void) +GObject *geany_object_new(void) { - return (GObject*)g_object_new(GEANY_OBJECT_TYPE, NULL); + return g_object_new(GEANY_OBJECT_TYPE, NULL); }
Modified: trunk/src/geanywraplabel.c =================================================================== --- trunk/src/geanywraplabel.c 2009-04-05 19:58:30 UTC (rev 3686) +++ trunk/src/geanywraplabel.c 2009-04-05 21:07:40 UTC (rev 3687) @@ -28,6 +28,7 @@
#include <gtk/gtk.h> +#include "utils.h" #include "geanywraplabel.h"
@@ -83,7 +84,7 @@ { GeanyWrapLabelPrivate *priv;
- if (width == 0) + if (G_UNLIKELY(width == 0)) return;
/* @@ -136,7 +137,7 @@ { GtkWidget *l = g_object_new(GEANY_WRAP_LABEL_TYPE, NULL);
- if (text != NULL && text[0] != '\0') + if (NZV(text)) gtk_label_set_text(GTK_LABEL(l), text);
pango_layout_set_wrap(gtk_label_get_layout(GTK_LABEL(l)), PANGO_WRAP_WORD_CHAR);
Modified: trunk/src/highlighting.c =================================================================== --- trunk/src/highlighting.c 2009-04-05 19:58:30 UTC (rev 3686) +++ trunk/src/highlighting.c 2009-04-05 21:07:40 UTC (rev 3687) @@ -121,16 +121,17 @@ { gchar *result;
- if (config == NULL || configh == NULL || section == NULL) + if (G_UNLIKELY(config == NULL) || G_UNLIKELY(configh == NULL) || G_UNLIKELY(section == NULL)) { style_sets[index].keywords[pos] = g_strdup(default_value); return; }
result = g_key_file_get_string(configh, section, key, NULL); - if (result == NULL) result = g_key_file_get_string(config, section, key, NULL); + if (result == NULL) + result = g_key_file_get_string(config, section, key, NULL);
- if (result == NULL) + if (G_UNLIKELY(result == NULL)) { style_sets[index].keywords[pos] = g_strdup(default_value); } @@ -145,7 +146,7 @@ { gchar *result;
- if (config == NULL || configh == NULL) + if (G_UNLIKELY(config == NULL) || G_UNLIKELY(configh == NULL)) { *wordchars = g_strdup(GEANY_WORDCHARS); return; @@ -154,7 +155,7 @@ result = g_key_file_get_string(configh, "settings", "wordchars", NULL); if (result == NULL) result = g_key_file_get_string(config, "settings", "wordchars", NULL);
- if (result == NULL) + if (G_UNLIKELY(result == NULL)) { *wordchars = g_strdup(GEANY_WORDCHARS); } @@ -178,26 +179,32 @@ gchar **list; gsize len;
- g_return_if_fail(config && configh && key_name && default_style && style); + g_return_if_fail(G_LIKELY(config)); + g_return_if_fail(G_LIKELY(configh)); + g_return_if_fail(G_LIKELY(key_name)); + g_return_if_fail(G_LIKELY(default_style)); + g_return_if_fail(G_LIKELY(style));
list = g_key_file_get_string_list(configh, "styling", key_name, &len, NULL); if (list == NULL) list = g_key_file_get_string_list(config, "styling", key_name, &len, NULL);
- if (list != NULL && list[0] != NULL) + if (G_LIKELY(list) != NULL && G_UNLIKELY(list[0] != NULL)) style->foreground = (gint) utils_strtod(list[0], NULL, FALSE); else style->foreground = rotate_rgb(default_style->foreground);
- if (list != NULL && list[1] != NULL) + if (G_LIKELY(list != NULL) && G_LIKELY(list[1] != NULL)) style->background = (gint) utils_strtod(list[1], NULL, FALSE); else style->background = rotate_rgb(default_style->background);
- if (list != NULL && list[2] != NULL) style->bold = utils_atob(list[2]); + if (G_LIKELY(list) != NULL && G_LIKELY(list[2] != NULL)) + style->bold = utils_atob(list[2]); else style->bold = default_style->bold;
- if (list != NULL && list[3] != NULL) style->italic = utils_atob(list[3]); + if (G_LIKELY(list) != NULL && list[3] != NULL) + style->italic = utils_atob(list[3]); else style->italic = default_style->italic;
g_strfreev(list); @@ -212,26 +219,34 @@ gchar **list; gsize len;
- if (config == NULL || configh == NULL || section == NULL) return; + g_return_if_fail(G_LIKELY(config)); + g_return_if_fail(G_LIKELY(configh)); + g_return_if_fail(G_LIKELY(section)); + g_return_if_fail(G_LIKELY(key));
list = g_key_file_get_string_list(configh, section, key, &len, NULL); - if (list == NULL) list = g_key_file_get_string_list(config, section, key, &len, NULL); + if (list == NULL) + list = g_key_file_get_string_list(config, section, key, &len, NULL);
- if (list != NULL && list[0] != NULL) + if (G_LIKELY(list != NULL) && G_LIKELY(list[0] != NULL)) style->foreground = (gint) utils_strtod(list[0], NULL, FALSE); else if (foreground) style->foreground = (gint) utils_strtod(foreground, NULL, FALSE);
- if (list != NULL && list[1] != NULL) + if (G_LIKELY(list != NULL) && G_LIKELY(list[1] != NULL)) style->background = (gint) utils_strtod(list[1], NULL, FALSE); else if (background) style->background = (gint) utils_strtod(background, NULL, FALSE);
- if (list != NULL && list[2] != NULL) style->bold = utils_atob(list[2]); - else style->bold = utils_atob(bold); + if (G_LIKELY(list != NULL) && G_LIKELY(list[2] != NULL)) + style->bold = utils_atob(list[2]); + else + style->bold = utils_atob(bold);
- if (list != NULL && list[3] != NULL) style->italic = utils_atob(list[3]); - else style->italic = FALSE; + if (G_LIKELY(list != NULL) && list[3] != NULL) + style->italic = utils_atob(list[3]); + else + style->italic = FALSE;
g_strfreev(list); } @@ -245,19 +260,29 @@ gchar *end1, *end2; gsize len;
- if (config == NULL || configh == NULL || section == NULL) return; + g_return_if_fail(G_LIKELY(config)); + g_return_if_fail(G_LIKELY(configh)); + g_return_if_fail(G_LIKELY(section)); + g_return_if_fail(G_LIKELY(key));
list = g_key_file_get_string_list(configh, section, key, &len, NULL); - if (list == NULL) list = g_key_file_get_string_list(config, section, key, &len, NULL); + if (list == NULL) + list = g_key_file_get_string_list(config, section, key, &len, NULL);
- if (list != NULL && list[0] != NULL) style->foreground = strtol(list[0], &end1, 10); - else style->foreground = fdefault_val; - if (list != NULL && list[1] != NULL) style->background = strtol(list[1], &end2, 10); - else style->background = sdefault_val; + if (G_LIKELY(list != NULL) && G_LIKELY(list[0] != NULL) ) + style->foreground = strtol(list[0], &end1, 10); + else + style->foreground = fdefault_val; + if (G_LIKELY(list != NULL) && G_LIKELY(list[1] != NULL) ) + style->background = strtol(list[1], &end2, 10); + else + style->background = sdefault_val;
/* if there was an error, strtol() returns 0 and end is list[x], so then we use default_val */ - if (list == NULL || list[0] == end1) style->foreground = fdefault_val; - if (list == NULL || list[1] == end2) style->background = sdefault_val; + if (G_UNLIKELY(list == NULL) || G_UNLIKELY(list[0] == end1)) + style->foreground = fdefault_val; + if (G_UNLIKELY(list == NULL) || G_UNLIKELY(list[1] == end2)) + style->background = sdefault_val;
g_strfreev(list); } @@ -280,18 +305,18 @@
static GeanyLexerStyle *get_style(guint ft_id, guint styling_index) { - g_assert(ft_id < GEANY_MAX_BUILT_IN_FILETYPES); + g_assert(G_LIKELY(ft_id < GEANY_MAX_BUILT_IN_FILETYPES));
- if (ft_id == GEANY_FILETYPES_NONE) + if (G_UNLIKELY(ft_id == GEANY_FILETYPES_NONE)) { - g_assert(styling_index < GCS_MAX); + g_assert(G_LIKELY(styling_index < GCS_MAX)); return &common_style_set.styling[styling_index]; } else { StyleSet *set = &style_sets[ft_id];
- g_assert(styling_index < set->count); + g_assert(G_LIKELY(styling_index < set->count)); return &set->styling[styling_index]; } } @@ -329,11 +354,11 @@ { GString *s = NULL;
- if (app->tm_workspace) + if (G_LIKELY(app->tm_workspace)) { GPtrArray *tags_array = app->tm_workspace->global_tags;
- if (tags_array) + if (G_LIKELY(tags_array)) { s = symbols_find_tags_as_string(tags_array, TM_GLOBAL_TYPE_MASK, lang); } @@ -347,7 +372,7 @@ { gchar *result;
- if (config == NULL || configh == NULL) + if (G_UNLIKELY(config == NULL) || G_UNLIKELY(configh == NULL)) { result = NULL; } @@ -367,7 +392,7 @@ { static gboolean common_style_set_valid = FALSE;
- if (common_style_set_valid) + if (G_LIKELY(common_style_set_valid)) return; common_style_set_valid = TRUE; /* ensure filetypes.common is only loaded once */
@@ -605,7 +630,7 @@ GString *s;
s = get_global_typenames(lang); - if (s == NULL) + if (G_UNLIKELY(s == NULL)) s = g_string_sized_new(200); else g_string_append_c(s, ' '); /* append a space as delimiter to the existing list of words */ @@ -621,7 +646,7 @@ static void apply_filetype_properties(ScintillaObject *sci, gint lexer, filetype_id ft_id) { - g_assert(ft_id != GEANY_FILETYPES_NONE); + g_assert(G_LIKELY(ft_id != GEANY_FILETYPES_NONE));
SSM(sci, SCI_SETLEXER, lexer, 0);
@@ -3498,7 +3523,7 @@ * @see Scintilla messages @c SCI_STYLEGETFORE, etc, for use with ScintillaFuncs::send_message(). */ const GeanyLexerStyle *highlighting_get_style(gint ft_id, gint style_id) { - if (ft_id < 0 || ft_id > GEANY_MAX_BUILT_IN_FILETYPES) + if (G_UNLIKELY(ft_id < 0) || G_UNLIKELY(ft_id > GEANY_MAX_BUILT_IN_FILETYPES)) return NULL;
/* ensure filetype loaded */
Modified: trunk/src/keybindings.c =================================================================== --- trunk/src/keybindings.c 2009-04-05 19:58:30 UTC (rev 3686) +++ trunk/src/keybindings.c 2009-04-05 21:07:40 UTC (rev 3687) @@ -73,8 +73,8 @@ static gboolean on_key_press_event(GtkWidget *widget, GdkEventKey *event, gpointer user_data); static gboolean on_key_release_event(GtkWidget *widget, GdkEventKey *event, gpointer user_data);
-static gboolean check_current_word(void); -static gboolean read_current_word(void); +static gboolean check_current_word(GeanyDocument *doc); +static gboolean read_current_word(GeanyDocument *doc);
static void cb_func_file_action(guint key_id); static void cb_func_project_action(guint key_id); @@ -126,7 +126,7 @@ { GeanyKeyBinding *kb;
- g_assert(key_id < group->count); + g_assert(G_LIKELY(key_id < group->count));
kb = &group->keys[key_id];
@@ -526,7 +526,7 @@
static void on_document_close(GObject *obj, GeanyDocument *doc) { - if (! main_status.quitting) + if (G_LIKELY(! main_status.quitting)) { g_queue_remove_all(mru_docs, doc); g_idle_add(on_idle_close, NULL); @@ -558,7 +558,7 @@
static void apply_kb_accel(GeanyKeyGroup *group, GeanyKeyBinding *kb, gpointer user_data) { - if (kb->key != 0 && kb->menu_item) + if (G_LIKELY(kb->key != 0) && kb->menu_item) { gtk_widget_add_accelerator(kb->menu_item, "activate", kb_accel_group, kb->key, kb->mods, GTK_ACCEL_VISIBLE); @@ -571,14 +571,15 @@ static void keybindings_foreach(KBItemCallback cb, gpointer user_data) { gsize g, i; + GeanyKeyGroup *group; + GeanyKeyBinding *kb;
for (g = 0; g < keybinding_groups->len; g++) { - GeanyKeyGroup *group = g_ptr_array_index(keybinding_groups, g); - + group = g_ptr_array_index(keybinding_groups, g); for (i = 0; i < group->count; i++) { - GeanyKeyBinding *kb = &group->keys[i]; + kb = &group->keys[i];
cb(group, kb, user_data); } @@ -594,13 +595,13 @@ GdkModifierType mods;
val = g_key_file_get_string(config, group->name, kb->name, NULL); - if (val != NULL) + if (G_LIKELY(val != NULL)) { gtk_accelerator_parse(val, &key, &mods); kb->key = key; kb->mods = mods; + g_free(val); } - g_free(val); }
@@ -636,7 +637,7 @@ { GeanyKeyBinding *kb = &group->keys[kb_id];
- if (kb->key != 0) + if (G_LIKELY(kb->key != 0)) gtk_widget_add_accelerator(menuitem, "activate", accel_group, kb->key, kb->mods, GTK_ACCEL_VISIBLE); } @@ -750,7 +751,7 @@ { group = g_ptr_array_index(keybinding_groups, g);
- if (g > 0) + if (G_LIKELY(g > 0)) { gtk_list_store_append(store, &iter); gtk_list_store_set(store, &iter, -1); @@ -823,6 +824,7 @@
gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 6); gtk_box_pack_start(GTK_BOX(vbox), swin, TRUE, TRUE, 0); + return dialog; }
@@ -854,7 +856,7 @@
void keybindings_show_shortcuts(void) { - if (key_dialog) + if (G_UNLIKELY(key_dialog)) gtk_widget_destroy(key_dialog); /* in case the key_dialog is still visible */
key_dialog = create_dialog(); @@ -900,18 +902,17 @@
/* We have a special case for GEANY_KEYS_EDIT_COMPLETESNIPPET, because we need to * return FALSE if no completion occurs, so the tab or space is handled normally. */ -static gboolean check_snippet_completion(guint keyval, guint state) +static gboolean check_snippet_completion(GeanyDocument *doc, guint keyval, guint state) { GeanyKeyBinding *kb = keybindings_lookup_item(GEANY_KEY_GROUP_EDITOR, GEANY_KEYS_EDITOR_COMPLETESNIPPET);
if (kb->key == keyval && kb->mods == state) { - GeanyDocument *doc = document_get_current(); GtkWidget *focusw = gtk_window_get_focus(GTK_WINDOW(main_widgets.window));
/* keybinding only valid when scintilla widget has focus */ - if (doc != NULL && focusw == GTK_WIDGET(doc->editor->sci)) + if (G_LIKELY(doc != NULL) && focusw == GTK_WIDGET(doc->editor->sci)) { ScintillaObject *sci = doc->editor->sci; gint pos = sci_get_current_position(sci); @@ -952,18 +953,17 @@ * would be shown. As a very special case, we differentiate between the Menu key and Shift-F10 * if pressed in the editor widget: the Menu key opens the popup menu, Shift-F10 opens the * notebook tab list. */ -static gboolean check_menu_key(guint keyval, guint state, guint32 event_time) +static gboolean check_menu_key(GeanyDocument *doc, guint keyval, guint state, guint32 event_time) { if ((keyval == GDK_Menu && state == 0) || (keyval == GDK_F10 && state == GDK_SHIFT_MASK)) { - GeanyDocument *doc = document_get_current(); GtkWidget *focusw = gtk_window_get_focus(GTK_WINDOW(main_widgets.window)); static GtkWidget *scribble = NULL;
- if (scribble == NULL) + if (G_UNLIKELY(scribble == NULL)) scribble = ui_lookup_widget(main_widgets.window, "textview_scribble");
- if (doc != NULL) + if (G_LIKELY(doc != NULL)) { if (focusw == doc->priv->tag_tree) { @@ -1062,27 +1062,20 @@ #endif
-static void check_disk_status(void) -{ - GeanyDocument *doc = document_get_current(); - - if (doc != NULL) - { - document_check_disk_status(doc, FALSE); - } -} - - /* central keypress event handler, almost all keypress events go to this function */ static gboolean on_key_press_event(GtkWidget *widget, GdkEventKey *ev, gpointer user_data) { guint state, keyval; gsize g, i; + GeanyDocument *doc; + GeanyKeyGroup *group; + GeanyKeyBinding *kb;
- if (ev->keyval == 0) + if (G_UNLIKELY(ev->keyval == 0)) return FALSE;
- check_disk_status(); + doc = document_get_current(); + document_check_disk_status(doc, FALSE);
keyval = ev->keyval; state = ev->state & GEANY_KEYS_MODIFIER_MASK; @@ -1099,23 +1092,22 @@ if (vte_info.have_vte && check_vte(state, keyval)) return FALSE; #endif - if (check_snippet_completion(keyval, state)) + if (check_snippet_completion(doc, keyval, state)) return TRUE; - if (check_menu_key(keyval, state, ev->time)) + if (check_menu_key(doc, keyval, state, ev->time)) return TRUE;
ignore_keybinding = FALSE; for (g = 0; g < keybinding_groups->len; g++) { - GeanyKeyGroup *group = g_ptr_array_index(keybinding_groups, g); + group = g_ptr_array_index(keybinding_groups, g);
for (i = 0; i < group->count; i++) { - GeanyKeyBinding *kb = &group->keys[i]; - + kb = &group->keys[i]; if (keyval == kb->key && state == kb->mods) { - if (kb->callback == NULL) + if (G_UNLIKELY(kb->callback == NULL)) return FALSE; /* ignore the keybinding */
/* call the corresponding callback function for this shortcut */ @@ -1158,12 +1150,12 @@ { GeanyKeyGroup *group;
- g_return_val_if_fail(group_id < keybinding_groups->len, NULL); + g_return_val_if_fail(G_LIKELY(group_id < keybinding_groups->len), NULL);
group = g_ptr_array_index(keybinding_groups, group_id);
- g_return_val_if_fail(group, NULL); - g_return_val_if_fail(key_id < group->count, NULL); + g_return_val_if_fail(G_LIKELY(group), NULL); + g_return_val_if_fail(G_LIKELY(key_id < group->count), NULL);
return &group->keys[key_id]; } @@ -1177,10 +1169,10 @@ { GeanyKeyBinding *kb;
- g_return_if_fail(group_id < GEANY_KEY_GROUP_COUNT); /* can't use this for plugin groups */ + g_return_if_fail(G_LIKELY(group_id < GEANY_KEY_GROUP_COUNT)); /* can't use this for plugin groups */
kb = keybindings_lookup_item(group_id, key_id); - if (kb) + if (G_LIKELY(kb)) kb->callback(key_id); }
@@ -1251,6 +1243,8 @@
static void cb_func_search_action(guint key_id) { + GeanyDocument *doc; + switch (key_id) { case GEANY_KEYS_SEARCH_FIND: @@ -1272,11 +1266,13 @@ case GEANY_KEYS_SEARCH_PREVIOUSMESSAGE: on_previous_message1_activate(NULL, NULL); break; case GEANY_KEYS_SEARCH_FINDUSAGE: - read_current_word(); + doc = document_get_current(); + read_current_word(doc); on_find_usage1_activate(NULL, NULL); break; case GEANY_KEYS_SEARCH_FINDDOCUMENTUSAGE: - read_current_word(); + doc = document_get_current(); + read_current_word(doc); on_find_document_usage1_activate(NULL, NULL); break; } @@ -1334,11 +1330,12 @@ BuildMenuItems *menu_items;
GeanyDocument *doc = document_get_current(); - if (doc == NULL) + if (G_UNLIKELY(doc == NULL)) return;
ft = doc->file_type; - if (! ft) return; + if (G_UNLIKELY(! ft)) + return; menu_items = build_get_menu_items(ft->id);
switch (key_id) @@ -1384,12 +1381,11 @@ }
-static gboolean read_current_word(void) +static gboolean read_current_word(GeanyDocument *doc) { gint pos; - GeanyDocument *doc = document_get_current();
- if (doc == NULL) + if (G_UNLIKELY(doc == NULL)) return FALSE;
pos = sci_get_current_position(doc->editor->sci); @@ -1401,9 +1397,9 @@ }
-static gboolean check_current_word(void) +static gboolean check_current_word(GeanyDocument *doc) { - if (!read_current_word()) + if (!read_current_word(doc)) { utils_beep(); return FALSE; @@ -1432,7 +1428,7 @@ case GEANY_KEYS_FOCUS_EDITOR: { GeanyDocument *doc = document_get_current(); - if (doc != NULL) + if (G_LIKELY(doc != NULL)) gtk_widget_grab_focus(GTK_WIDGET(doc->editor->sci)); break; } @@ -1557,7 +1553,7 @@ if (switch_dialog_cancelled) return FALSE;
- if (!switch_dialog) + if (G_UNLIKELY(! switch_dialog)) switch_dialog = create_switch_dialog();
geany_wrap_label_set_text(GTK_LABEL(switch_dialog_label), @@ -1572,7 +1568,7 @@ /* TODO: MRU switching order */ GeanyDocument *last_doc = g_queue_peek_head(mru_docs);
- if (!DOC_VALID(last_doc)) + if (! DOC_VALID(last_doc)) return;
gtk_notebook_set_current_page(GTK_NOTEBOOK(main_widgets.notebook), @@ -1580,7 +1576,7 @@
/* if there's a modifier key, we can switch back in MRU order each time unless * the key is released */ - if (!switch_dialog_cancelled) + if (! switch_dialog_cancelled) { on_switch_timeout(NULL); /* update filename label */ } @@ -1604,7 +1600,7 @@ gint cur_page = gtk_notebook_get_current_page(nb); GeanyDocument *doc = document_get_current();
- if (doc == NULL) + if (G_UNLIKELY(doc == NULL)) return;
sci = GTK_WIDGET(doc->editor->sci); @@ -1638,7 +1634,7 @@ { gint pos, new_pos;
- if (doc == NULL) + if (G_UNLIKELY(doc == NULL)) return;
pos = sci_get_current_position(doc->editor->sci); @@ -1658,7 +1654,7 @@ { GeanyDocument *doc = document_get_current();
- if (doc == NULL) + if (G_UNLIKELY(doc == NULL)) return;
switch (key_id) @@ -1688,7 +1684,7 @@ gint cur_line; GeanyDocument *doc = document_get_current();
- if (doc == NULL) + if (G_UNLIKELY(doc == NULL)) return;
cur_line = sci_get_current_line(doc->editor->sci); @@ -1737,11 +1733,11 @@ return; } case GEANY_KEYS_GOTO_TAGDEFINITION: - if (check_current_word()) + if (check_current_word(doc)) symbols_goto_tag(editor_info.current_word, TRUE); return; case GEANY_KEYS_GOTO_TAGDECLARATION: - if (check_current_word()) + if (check_current_word(doc)) symbols_goto_tag(editor_info.current_word, FALSE); return; } @@ -1797,7 +1793,7 @@ GtkWidget *focusw = gtk_window_get_focus(GTK_WINDOW(main_widgets.window));
/* edit keybindings only valid when scintilla widget has focus */ - if (doc == NULL || focusw != GTK_WIDGET(doc->editor->sci)) + if (G_UNLIKELY(doc == NULL) || focusw != GTK_WIDGET(doc->editor->sci)) return;
switch (key_id) @@ -1840,7 +1836,7 @@ editor_show_macro_list(doc->editor); break; case GEANY_KEYS_EDITOR_CONTEXTACTION: - if (check_current_word()) + if (check_current_word(doc)) on_context_action1_activate(GTK_MENU_ITEM(ui_lookup_widget(main_widgets.editor_menu, "context_action1")), NULL); break; @@ -1873,7 +1869,7 @@ GtkWidget *focusw = gtk_window_get_focus(GTK_WINDOW(main_widgets.window));
/* keybindings only valid when scintilla widget has focus */ - if (doc == NULL || focusw != GTK_WIDGET(doc->editor->sci)) + if (G_UNLIKELY(doc == NULL) || focusw != GTK_WIDGET(doc->editor->sci)) return;
switch (key_id) @@ -1927,12 +1923,12 @@ /* common function for select keybindings, only valid when scintilla has focus. */ static void cb_func_select_action(guint key_id) { - GeanyDocument *doc = document_get_current(); + GeanyDocument *doc; GtkWidget *focusw = gtk_window_get_focus(GTK_WINDOW(main_widgets.window)); static GtkWidget *scribble_widget = NULL;
/* special case for Select All in the scribble widget */ - if (scribble_widget == NULL) /* lookup the scribble widget only once */ + if (G_UNLIKELY(scribble_widget == NULL)) /* lookup the scribble widget only once */ scribble_widget = ui_lookup_widget(main_widgets.window, "textview_scribble"); if (key_id == GEANY_KEYS_SELECT_ALL && focusw == scribble_widget) { @@ -1940,8 +1936,9 @@ return; }
+ doc = document_get_current(); /* keybindings only valid when scintilla widget has focus */ - if (doc == NULL || focusw != GTK_WIDGET(doc->editor->sci)) + if (G_UNLIKELY(doc == NULL) || focusw != GTK_WIDGET(doc->editor->sci)) return;
switch (key_id) @@ -1965,7 +1962,7 @@ static void cb_func_document_action(guint key_id) { GeanyDocument *doc = document_get_current(); - if (doc == NULL) + if (G_UNLIKELY(doc == NULL)) return;
switch (key_id) @@ -2011,7 +2008,8 @@ GtkWidget *focusw = gtk_window_get_focus(GTK_WINDOW(main_widgets.window));
/* keybindings only valid when scintilla widget has focus */ - if (doc == NULL || focusw != GTK_WIDGET(doc->editor->sci)) return; + if (G_UNLIKELY(doc == NULL) || focusw != GTK_WIDGET(doc->editor->sci)) + return;
switch (key_id) {
Modified: trunk/src/keyfile.c =================================================================== --- trunk/src/keyfile.c 2009-04-05 19:58:30 UTC (rev 3686) +++ trunk/src/keyfile.c 2009-04-05 21:07:40 UTC (rev 3687) @@ -233,7 +233,7 @@ gchar *locale_filename; GeanyFiletype *ft = doc->file_type;
- if (ft == NULL) /* can happen when saving a new file when quitting */ + if (G_UNLIKELY(ft == NULL)) /* can happen when saving a new file when quitting */ ft = filetypes[GEANY_FILETYPES_NONE];
locale_filename = utils_get_locale_from_utf8(doc->file_name); @@ -275,7 +275,7 @@ for (i = 0; i < max; i++) {
@@ Diff output truncated at 100000 characters. @@
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.