Commit 9ee4eb95 authored by Christian Hergert's avatar Christian Hergert

buffer: cache presence of draw-spaces-set tag

To avoid iterating the tag table during space drawing, we can cache if
we've seen a tag with the draw-spaces-set field set. This can reduce a
bit of work in the common case, which is space drawing solely based upon
the matrix settings.
parent 92fe708c
......@@ -22,8 +22,10 @@
#define GTK_SOURCE_BUFFER_PRIVATE_H
#include <gtk/gtk.h>
#include "gtksourcetypes.h"
#include "gtksourcetypes-private.h"
#include "gtksourcebuffer.h"
G_BEGIN_DECLS
......@@ -83,6 +85,9 @@ gboolean _gtk_source_buffer_is_undo_redo_enabled (GtkSourceBuffer *buff
GTK_SOURCE_INTERNAL
gboolean _gtk_source_buffer_has_source_marks (GtkSourceBuffer *buffer);
GTK_SOURCE_INTERNAL
gboolean _gtk_source_buffer_has_spaces_tag (GtkSourceBuffer *buffer);
G_END_DECLS
#endif /* GTK_SOURCE_BUFFER_PRIVATE_H */
......@@ -216,6 +216,7 @@ struct _GtkSourceBufferPrivate
GtkTextTag *invalid_char_tag;
guint has_draw_spaces_tag : 1;
guint highlight_syntax : 1;
guint highlight_brackets : 1;
guint implicit_trailing_newline : 1;
......@@ -269,10 +270,53 @@ static void gtk_source_buffer_real_highlight_updated
GtkTextIter *start,
GtkTextIter *end);
static void
gtk_source_buffer_check_tag_for_spaces (GtkSourceBuffer *buffer,
GtkSourceTag *tag)
{
if (!buffer->priv->has_draw_spaces_tag)
{
gboolean draw_spaces_set;
g_object_get (tag,
"draw-spaces-set", &draw_spaces_set,
NULL);
if (draw_spaces_set)
{
buffer->priv->has_draw_spaces_tag = TRUE;
}
}
}
static void
gtk_source_buffer_tag_changed_cb (GtkTextTagTable *table,
GtkTextTag *tag,
gboolean size_changed,
GtkSourceBuffer *buffer)
{
if (GTK_SOURCE_IS_TAG (tag))
{
gtk_source_buffer_check_tag_for_spaces (buffer, GTK_SOURCE_TAG (tag));
}
}
static void
gtk_source_buffer_tag_added_cb (GtkTextTagTable *table,
GtkTextTag *tag,
GtkSourceBuffer *buffer)
{
if (GTK_SOURCE_IS_TAG (tag))
{
gtk_source_buffer_check_tag_for_spaces (buffer, GTK_SOURCE_TAG (tag));
}
}
static void
gtk_source_buffer_constructed (GObject *object)
{
GtkSourceBuffer *buffer = GTK_SOURCE_BUFFER (object);
GtkTextTagTable *table;
if (buffer->priv->undo_manager == NULL)
{
......@@ -281,6 +325,16 @@ gtk_source_buffer_constructed (GObject *object)
}
G_OBJECT_CLASS (gtk_source_buffer_parent_class)->constructed (object);
table = gtk_text_buffer_get_tag_table (GTK_TEXT_BUFFER (buffer));
g_signal_connect_object (table,
"tag-changed",
G_CALLBACK (gtk_source_buffer_tag_changed_cb),
buffer, 0);
g_signal_connect_object (table,
"tag-added",
G_CALLBACK (gtk_source_buffer_tag_added_cb),
buffer, 0);
}
static void
......@@ -3349,3 +3403,11 @@ gtk_source_buffer_create_source_tag (GtkSourceBuffer *buffer,
return tag;
}
gboolean
_gtk_source_buffer_has_spaces_tag (GtkSourceBuffer *buffer)
{
g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), FALSE);
return buffer->priv->has_draw_spaces_tag;
}
......@@ -30,6 +30,7 @@
#include "gtksourcespacedrawer.h"
#include "gtksourcespacedrawer-private.h"
#include "gtksourcebuffer.h"
#include "gtksourcebuffer-private.h"
#include "gtksourceiter.h"
#include "gtksourcestylescheme.h"
#include "gtksourcetag.h"
......@@ -957,44 +958,6 @@ draw_whitespace_at_iter (GtkTextView *text_view,
}
}
static void
draw_spaces_tag_foreach (GtkTextTag *tag,
gboolean *found)
{
if (*found)
{
return;
}
if (GTK_SOURCE_IS_TAG (tag))
{
gboolean draw_spaces_set;
g_object_get (tag,
"draw-spaces-set", &draw_spaces_set,
NULL);
if (draw_spaces_set)
{
*found = TRUE;
}
}
}
static gboolean
buffer_has_draw_spaces_tag (GtkTextBuffer *buffer)
{
GtkTextTagTable *table;
gboolean found = FALSE;
table = gtk_text_buffer_get_tag_table (buffer);
gtk_text_tag_table_foreach (table,
(GtkTextTagTableForeach) draw_spaces_tag_foreach,
&found);
return found;
}
static void
space_needs_drawing_according_to_tag (const GtkTextIter *iter,
gboolean *has_tag,
......@@ -1224,7 +1187,7 @@ _gtk_source_space_drawer_draw (GtkSourceSpaceDrawer *drawer,
buffer = gtk_text_view_get_buffer (text_view);
if ((!drawer->priv->enable_matrix || is_zero_matrix (drawer)) &&
!buffer_has_draw_spaces_tag (buffer))
!_gtk_source_buffer_has_spaces_tag (GTK_SOURCE_BUFFER (buffer)))
{
return;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment