[gtksourceview] gutterrendererlines: avoid extra function calls in ::query_data()
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview] gutterrendererlines: avoid extra function calls in ::query_data()
- Date: Thu, 21 Apr 2016 22:07:51 +0000 (UTC)
commit c4008d3eab19bccd8b8e1a1e1bd8ac853ec250d8
Author: Christian Hergert <christian hergert me>
Date: Wed Apr 20 18:55:59 2016 -0700
gutterrendererlines: avoid extra function calls in ::query_data()
We can remove the calls to check if the cursor is visible for every visible
line by keeping track of when the property changes. This removes a
gtk_text_view_get_cursor_visible() and gtk_text_gutter_render_get_view()
for every line in the rendering process.
https://bugzilla.gnome.org/show_bug.cgi?id=765356
gtksourceview/gtksourcegutterrendererlines.c | 23 ++++++++++++++++++++++-
1 files changed, 22 insertions(+), 1 deletions(-)
---
diff --git a/gtksourceview/gtksourcegutterrendererlines.c b/gtksourceview/gtksourcegutterrendererlines.c
index 5a07102..a8f1fb2 100644
--- a/gtksourceview/gtksourcegutterrendererlines.c
+++ b/gtksourceview/gtksourcegutterrendererlines.c
@@ -30,6 +30,7 @@ struct _GtkSourceGutterRendererLinesPrivate
{
gint num_line_digits;
gint prev_line_num;
+ guint cursor_visible : 1;
};
G_DEFINE_TYPE_WITH_PRIVATE (GtkSourceGutterRendererLines, gtk_source_gutter_renderer_lines,
GTK_SOURCE_TYPE_GUTTER_RENDERER_TEXT)
@@ -159,6 +160,14 @@ on_view_style_updated (GtkTextView *view,
}
static void
+on_view_notify_cursor_visible (GtkTextView *view,
+ GParamSpec *pspec,
+ GtkSourceGutterRendererLines *renderer)
+{
+ renderer->priv->cursor_visible = gtk_text_view_get_cursor_visible (view);
+}
+
+static void
gutter_renderer_change_view (GtkSourceGutterRenderer *renderer,
GtkTextView *old_view)
{
@@ -169,6 +178,9 @@ gutter_renderer_change_view (GtkSourceGutterRenderer *renderer,
g_signal_handlers_disconnect_by_func (old_view,
on_view_style_updated,
renderer);
+ g_signal_handlers_disconnect_by_func (old_view,
+ on_view_notify_cursor_visible,
+ renderer);
}
new_view = gtk_source_gutter_renderer_get_view (renderer);
@@ -180,6 +192,14 @@ gutter_renderer_change_view (GtkSourceGutterRenderer *renderer,
G_CALLBACK (on_view_style_updated),
renderer,
0);
+
+ g_signal_connect_object (new_view,
+ "notify::cursor-visible",
+ G_CALLBACK (on_view_notify_cursor_visible),
+ renderer,
+ 0);
+
+ GTK_SOURCE_GUTTER_RENDERER_LINES (renderer)->priv->cursor_visible =
gtk_text_view_get_cursor_visible (new_view);
}
if (GTK_SOURCE_GUTTER_RENDERER_CLASS (gtk_source_gutter_renderer_lines_parent_class)->change_view !=
NULL)
@@ -195,6 +215,7 @@ gutter_renderer_query_data (GtkSourceGutterRenderer *renderer,
GtkTextIter *end,
GtkSourceGutterRendererState state)
{
+ GtkSourceGutterRendererLines *lines = GTK_SOURCE_GUTTER_RENDERER_LINES (renderer);
gchar text[24];
gint line;
gint len;
@@ -203,7 +224,7 @@ gutter_renderer_query_data (GtkSourceGutterRenderer *renderer,
line = gtk_text_iter_get_line (start) + 1;
current_line = (state & GTK_SOURCE_GUTTER_RENDERER_STATE_CURSOR) &&
- gtk_text_view_get_cursor_visible (gtk_source_gutter_renderer_get_view (renderer));
+ lines->priv->cursor_visible;
if (current_line)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]