textbtree: short-circuit visibility check when possible
If we have never seen a GtkTextTag in the GtkTextTagTable with the invisible bit set, then we do not need to go through the process of checking the accumulated tags. Not using invisible tags is overwhelmingly the common case.
This commit is contained in:
parent
2aba6f0ba4
commit
9fc7c3b1b3
@ -61,7 +61,7 @@
|
|||||||
#include "gtktextbufferprivate.h"
|
#include "gtktextbufferprivate.h"
|
||||||
#include "gtktexttag.h"
|
#include "gtktexttag.h"
|
||||||
#include "gtktexttagprivate.h"
|
#include "gtktexttagprivate.h"
|
||||||
#include "gtktexttagtable.h"
|
#include "gtktexttagtableprivate.h"
|
||||||
#include "gtktextlayout.h"
|
#include "gtktextlayout.h"
|
||||||
#include "gtktextiterprivate.h"
|
#include "gtktextiterprivate.h"
|
||||||
#include "gtkdebug.h"
|
#include "gtkdebug.h"
|
||||||
@ -2492,6 +2492,13 @@ _gtk_text_btree_char_is_invisible (const GtkTextIter *iter)
|
|||||||
|
|
||||||
line = _gtk_text_iter_get_text_line (iter);
|
line = _gtk_text_iter_get_text_line (iter);
|
||||||
tree = _gtk_text_iter_get_btree (iter);
|
tree = _gtk_text_iter_get_btree (iter);
|
||||||
|
|
||||||
|
/* Short-circuit if we've never seen a visibility tag within the
|
||||||
|
* tag table (meaning everything must be visible).
|
||||||
|
*/
|
||||||
|
if G_LIKELY (!_gtk_text_tag_table_affects_visibility (tree->table))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
byte_index = gtk_text_iter_get_line_index (iter);
|
byte_index = gtk_text_iter_get_line_index (iter);
|
||||||
|
|
||||||
numTags = gtk_text_tag_table_get_size (tree->table);
|
numTags = gtk_text_tag_table_get_size (tree->table);
|
||||||
|
@ -68,6 +68,8 @@ struct _GtkTextTagTablePrivate
|
|||||||
GSList *buffers;
|
GSList *buffers;
|
||||||
|
|
||||||
gint anon_count;
|
gint anon_count;
|
||||||
|
|
||||||
|
guint seen_invisible : 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
@ -160,6 +162,22 @@ gtk_text_tag_table_init (GtkTextTagTable *table)
|
|||||||
table->priv->hash = g_hash_table_new (g_str_hash, g_str_equal);
|
table->priv->hash = g_hash_table_new (g_str_hash, g_str_equal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
check_visible (GtkTextTagTable *table,
|
||||||
|
GtkTextTag *tag)
|
||||||
|
{
|
||||||
|
if (table->priv->seen_invisible)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (tag->priv->invisible_set)
|
||||||
|
{
|
||||||
|
gboolean invisible;
|
||||||
|
|
||||||
|
g_object_get (tag, "invisible", &invisible, NULL);
|
||||||
|
table->priv->seen_invisible = invisible;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gtk_text_tag_table_new:
|
* gtk_text_tag_table_new:
|
||||||
*
|
*
|
||||||
@ -281,6 +299,8 @@ gtk_text_tag_table_add (GtkTextTagTable *table,
|
|||||||
g_assert (size > 0);
|
g_assert (size > 0);
|
||||||
tag->priv->priority = size - 1;
|
tag->priv->priority = size - 1;
|
||||||
|
|
||||||
|
check_visible (table, tag);
|
||||||
|
|
||||||
g_signal_emit (table, signals[TAG_ADDED], 0, tag);
|
g_signal_emit (table, signals[TAG_ADDED], 0, tag);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@ -470,5 +490,12 @@ _gtk_text_tag_table_tag_changed (GtkTextTagTable *table,
|
|||||||
GtkTextTag *tag,
|
GtkTextTag *tag,
|
||||||
gboolean size_changed)
|
gboolean size_changed)
|
||||||
{
|
{
|
||||||
|
check_visible (table, tag);
|
||||||
g_signal_emit (table, signals[TAG_CHANGED], 0, tag, size_changed);
|
g_signal_emit (table, signals[TAG_CHANGED], 0, tag, size_changed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
_gtk_text_tag_table_affects_visibility (GtkTextTagTable *table)
|
||||||
|
{
|
||||||
|
return table->priv->seen_invisible;
|
||||||
|
}
|
||||||
|
@ -36,6 +36,7 @@ void _gtk_text_tag_table_remove_buffer (GtkTextTagTable *table,
|
|||||||
void _gtk_text_tag_table_tag_changed (GtkTextTagTable *table,
|
void _gtk_text_tag_table_tag_changed (GtkTextTagTable *table,
|
||||||
GtkTextTag *tag,
|
GtkTextTag *tag,
|
||||||
gboolean size_changed);
|
gboolean size_changed);
|
||||||
|
gboolean _gtk_text_tag_table_affects_visibility (GtkTextTagTable *table);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user