From e88f9bb28500bdf2bfe5106b565ab56a0b601239 Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Tue, 10 Mar 2015 04:26:58 +0100 Subject: avoid frequent info line redraws in Curses and GTK+ UIs * it is now redrawn once after each key press, even if the info line has not changed. * This is because Interface::update_info() is called very often in interactive mode, so it makes more sense to redraw it after user interaction (where even unnecessary delays are not noticed so easily), than thousands of times in a macro. * This is especially important since InterfaceCurses::update_info() now also sets the Window title on PDCurses - this is a very costly operation. * The same optimization was applied to InterfaceGtk where it is probably greatly responsible for the sluggishness of the UI. The GTK+ changes are currently UNTESTED. --- src/interface-gtk.cpp | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) (limited to 'src/interface-gtk.cpp') diff --git a/src/interface-gtk.cpp b/src/interface-gtk.cpp index 900208c..3e1703e 100644 --- a/src/interface-gtk.cpp +++ b/src/interface-gtk.cpp @@ -90,6 +90,8 @@ InterfaceGtk::main_impl(int &argc, char **&argv) vbox = gtk_vbox_new(FALSE, 0); + info_current = g_strdup(PACKAGE_NAME); + cmdline_widget = gtk_entry_new(); gtk_entry_set_has_frame(GTK_ENTRY(cmdline_widget), FALSE); gtk_editable_set_editable(GTK_EDITABLE(cmdline_widget), FALSE); @@ -168,28 +170,21 @@ InterfaceGtk::show_view_impl(ViewGtk *view) void InterfaceGtk::info_update_impl(const QRegister *reg) { - gchar *str; gchar *name = String::canonicalize_ctl(reg->name); - str = g_strconcat(PACKAGE_NAME " - ", - name, NIL); + g_free(info_current); + info_current = g_strconcat(PACKAGE_NAME " - ", + name, NIL); g_free(name); - - gtk_window_set_title(GTK_WINDOW(window), str); - g_free(str); } void InterfaceGtk::info_update_impl(const Buffer *buffer) { - gchar *str; - - str = g_strconcat(PACKAGE_NAME " - ", - buffer->filename ? : UNNAMED_FILE, - buffer->dirty ? "*" : "", NIL); - - gtk_window_set_title(GTK_WINDOW(window), str); - g_free(str); + g_free(info_current); + info_current = g_strconcat(PACKAGE_NAME " - ", + buffer->filename ? : UNNAMED_FILE, + buffer->dirty ? "*" : "", NIL); } void @@ -290,6 +285,7 @@ InterfaceGtk::widget_set_font(GtkWidget *widget, const gchar *font_name) InterfaceGtk::~InterfaceGtk() { + g_free(info_current); if (popup_widget) gtk_widget_destroy(popup_widget); if (window) @@ -376,6 +372,15 @@ handle_key_press(bool is_shift, bool is_ctl, guint keyval) cmdline.keypress(key); } } + + /* + * The info area is updated very often and setting the + * window title each time it is updated is VERY costly. + * So we set it here once after every keypress even if the + * info line did not change. + */ + gtk_window_set_title(GTK_WINDOW(interface.window), + interface.info_current); } static gboolean -- cgit v1.2.3