From c0191c722570daf03fe7e89ce70ca7b7423f11a4 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 23 Aug 2020 15:09:45 -0400 Subject: [PATCH] text: Defer most recomputation until we're mapped It doesn't make sense to update scroll positions or im cursor locations while we're unmapped, and doing so causes us to do expensive text measuring. --- gtk/gtktext.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/gtk/gtktext.c b/gtk/gtktext.c index 7d7d3e37ab..c4300e9481 100644 --- a/gtk/gtktext.c +++ b/gtk/gtktext.c @@ -309,6 +309,7 @@ static void gtk_text_dispose (GObject *object); */ static void gtk_text_realize (GtkWidget *widget); static void gtk_text_unrealize (GtkWidget *widget); +static void gtk_text_map (GtkWidget *widget); static void gtk_text_unmap (GtkWidget *widget); static void gtk_text_measure (GtkWidget *widget, GtkOrientation orientation, @@ -710,6 +711,7 @@ gtk_text_class_init (GtkTextClass *class) gobject_class->set_property = gtk_text_set_property; gobject_class->get_property = gtk_text_get_property; + widget_class->map = gtk_text_map; widget_class->unmap = gtk_text_unmap; widget_class->realize = gtk_text_realize; widget_class->unrealize = gtk_text_unrealize; @@ -2131,6 +2133,16 @@ gtk_text_get_display_text (GtkText *self, } } +static void +gtk_text_map (GtkWidget *widget) +{ + GtkText *self = GTK_TEXT (widget); + + GTK_WIDGET_CLASS (gtk_text_parent_class)->map (widget); + + gtk_text_recompute (self); +} + static void gtk_text_unmap (GtkWidget *widget) { @@ -3284,8 +3296,6 @@ static void gtk_text_root (GtkWidget *widget) { GTK_WIDGET_CLASS (gtk_text_parent_class)->root (widget); - - gtk_text_recompute (GTK_TEXT (widget)); } /* GtkEditable method implementations @@ -4329,15 +4339,15 @@ static void gtk_text_recompute (GtkText *self) { gtk_text_reset_layout (self); - gtk_text_check_cursor_blink (self); - - gtk_text_adjust_scroll (self); - - update_im_cursor_location (self); - - gtk_text_update_handles (self); - gtk_widget_queue_draw (GTK_WIDGET (self)); + + if (!gtk_widget_get_mapped (GTK_WIDGET (self))) + return; + + gtk_text_check_cursor_blink (self); + gtk_text_adjust_scroll (self); + update_im_cursor_location (self); + gtk_text_update_handles (self); } static PangoLayout *