There is no need in storing tags applied to the line, removed hl_info->tags; fixed next-line-context once again

master
Yevgen Muntyan 2006-06-21 04:50:36 -05:00
parent 858d584e2c
commit c4d811a3b8
7 changed files with 66 additions and 118 deletions

View File

@ -42,8 +42,7 @@ static CtxNode *ctx_node_new (MooHighlighter *hl,
CtxNode *parent,
MooContext *context,
gboolean create_tag);
static void ctx_node_free (CtxNode *node,
GtkTextTagTable *table);
static void ctx_node_free (CtxNode *node);
static CtxNode *get_next_node (MooHighlighter *hl,
CtxNode *node,
MooRule *rule);
@ -79,31 +78,21 @@ _moo_syntax_tag_init (MooSyntaxTag *tag)
static void
remove_tag (G_GNUC_UNUSED gpointer rule,
GtkTextTag *tag,
ctx_node_free (CtxNode *node)
{
g_hash_table_destroy (node->match_tags);
g_hash_table_destroy (node->children);
g_free (node);
}
static void
delete_tag (GtkTextTag *tag,
GtkTextTagTable *table)
{
gtk_text_tag_table_remove (table, tag);
}
static void
ctx_node_free (CtxNode *node,
GtkTextTagTable *table)
{
if (table)
g_hash_table_foreach (node->match_tags, (GHFunc) remove_tag, table);
g_hash_table_destroy (node->match_tags);
g_hash_table_destroy (node->children);
g_slist_free (node->child_tags);
if (node->context_tag && table)
gtk_text_tag_table_remove (table, node->context_tag);
g_free (node);
}
void
_moo_highlighter_destroy (MooHighlighter *hl,
gboolean delete_tags)
@ -115,7 +104,12 @@ _moo_highlighter_destroy (MooHighlighter *hl,
if (delete_tags)
table = gtk_text_buffer_get_tag_table (hl->buffer);
g_slist_foreach (hl->nodes, (GFunc) ctx_node_free, table);
g_slist_foreach (hl->nodes, (GFunc) ctx_node_free, NULL);
g_slist_free (hl->nodes);
if (delete_tags)
g_slist_foreach (hl->tags, (GFunc) delete_tag, table);
g_slist_free (hl->tags);
if (hl->lang)
moo_lang_unref (hl->lang);
@ -161,7 +155,7 @@ iter_get_syntax_tag (const GtkTextIter *iter)
static void
apply_tag (MooHighlighter *hl,
Line *line,
G_GNUC_UNUSED Line *line,
CtxNode *ctx_node,
CtxNode *match_node,
MooRule *rule,
@ -187,7 +181,6 @@ apply_tag (MooHighlighter *hl,
rule ? rule->description : "NULL",
_moo_line_buffer_get_line_index (hl->line_buf, line));
#endif
line->hl_info->tags = g_slist_prepend (line->hl_info->tags, g_object_ref (tag));
_moo_text_buffer_apply_syntax_tag (MOO_TEXT_BUFFER (hl->buffer), tag, start, end);
}
}
@ -243,6 +236,8 @@ create_tag (MooHighlighter *hl,
return NULL;
tag = moo_syntax_tag_new (ctx_node, match_node, rule);
hl->tags = g_slist_prepend (hl->tags, tag);
// g_print ("%d tags\n", g_slist_length (hl->tags));
table = gtk_text_buffer_get_tag_table (hl->buffer);
@ -260,7 +255,6 @@ create_tag (MooHighlighter *hl,
#endif
_moo_lang_set_tag_style (tag, ctx_node->ctx, rule, NULL);
ctx_node->child_tags = g_slist_prepend (ctx_node->child_tags, tag);
return tag;
}
@ -317,6 +311,7 @@ ctx_node_new (MooHighlighter *hl,
node->context_tag = create_tag (hl, node, NULL, NULL);
hl->nodes = g_slist_prepend (hl->nodes, node);
// g_print ("node of depth %d, total %d nodes\n", node->depth, g_slist_length (hl->nodes));
return node;
}
@ -364,25 +359,35 @@ get_line_end_node (MooHighlighter *hl,
{
guint i;
CtxNode *next = NULL;
MooContext *ctx = node->ctx;
if (node->line_end)
return node->line_end;
switch (ctx->line_end.type)
while (!next)
{
case MOO_CONTEXT_STAY:
next = node;
break;
MooContext *ctx = node->ctx;
case MOO_CONTEXT_POP:
for (i = 0, next = node; next->parent != NULL && i < ctx->line_end.num;
++i, next = next->parent);
break;
switch (ctx->line_end.type)
{
case MOO_CONTEXT_STAY:
next = node;
break;
case MOO_CONTEXT_SWITCH:
next = ctx_node_new (hl, node, ctx->line_end.ctx, TRUE);
break;
case MOO_CONTEXT_POP:
for (i = 0, next = node; next->parent != NULL && i < ctx->line_end.num;
++i, next = next->parent);
g_assert (node != next);
node = next;
next = NULL;
break;
case MOO_CONTEXT_SWITCH:
next = ctx_node_new (hl, node, ctx->line_end.ctx, TRUE);
g_assert (node != next);
node = next;
next = NULL;
break;
}
}
g_assert (next != NULL);
@ -617,10 +622,10 @@ hl_compute_range (MooHighlighter *hl,
static gboolean
moo_highlighter_compute_timed (MooHighlighter *hl,
int first_line,
int last_line,
int time)
moo_highlighter_compute_timed (MooHighlighter *hl,
int first_line,
int last_line,
int time)
{
Interval to_highlight;
@ -714,7 +719,7 @@ _moo_highlighter_apply_tags (MooHighlighter *hl,
HLInfo *info = line->hl_info;
guint i;
GtkTextIter t_start, t_end;
GSList *tags;
GSList *t;
if (!hl->line_buf->invalid.empty && line_no >= hl->line_buf->invalid.first)
break;
@ -727,27 +732,17 @@ _moo_highlighter_apply_tags (MooHighlighter *hl,
last_changed = line_no;
line->hl_info->tags_applied = TRUE;
tags = line->hl_info->tags;
line->hl_info->tags = NULL;
gtk_text_buffer_get_iter_at_line (hl->buffer, &t_start, line_no);
if (gtk_text_iter_ends_line (&t_start))
{
g_slist_foreach (tags, (GFunc) g_object_unref, NULL);
g_slist_free (tags);
continue;
}
t_end = t_start;
gtk_text_iter_forward_to_line_end (&t_end);
while (tags)
{
gtk_text_buffer_remove_tag (hl->buffer, tags->data, &t_start, &t_end);
g_object_unref (tags->data);
tags = g_slist_delete_link (tags, tags);
}
for (t = hl->tags; t != NULL; t = t->next)
gtk_text_buffer_remove_tag (hl->buffer, t->data, &t_start, &t_end);
t_end = t_start;

View File

@ -44,10 +44,6 @@ struct _CtxNode
CtxNode *line_end;
GtkTextTag *context_tag;
GHashTable *match_tags; /* rule -> GtkTextTag* */
/* Match tags that may be contained in this context.
They are not necessarily in match_tags list due to
include-into-next rule property */
GSList *child_tags;
};
struct _MooHighlighter {
@ -56,6 +52,7 @@ struct _MooHighlighter {
MooLang *lang;
CtxNode *root;
GSList *nodes;
GSList *tags;
guint idle;
};

View File

@ -39,7 +39,7 @@ Line*
_moo_line_buffer_insert (LineBuffer *line_buf,
int index)
{
Line *line = _moo_text_btree_insert (line_buf->tree, index, NULL);
Line *line = _moo_text_btree_insert (line_buf->tree, index);
invalidate_line (line_buf, line, index);
return line;
}
@ -59,22 +59,17 @@ _moo_line_buffer_clamp_invalid (LineBuffer *line_buf)
void
_moo_line_buffer_split_line (LineBuffer *line_buf,
int line,
int num_new_lines,
GtkTextTag *tag)
int num_new_lines)
{
Line *l;
GSList *tags;
_moo_text_btree_insert_range (line_buf->tree, line + 1, num_new_lines, tag);
_moo_text_btree_insert_range (line_buf->tree, line + 1, num_new_lines);
l = _moo_line_buffer_get_line (line_buf, line);
invalidate_line (line_buf, l, line);
tags = g_slist_copy (l->hl_info->tags);
g_slist_foreach (tags, (GFunc) g_object_ref, NULL);
l = _moo_line_buffer_get_line (line_buf, line + num_new_lines);
invalidate_line (line_buf, l, line + num_new_lines);
l->hl_info->tags = g_slist_concat (l->hl_info->tags, tags);
}
@ -87,20 +82,17 @@ _moo_line_buffer_delete (LineBuffer *line_buf,
GSList **deleted_marks)
{
Line *line;
GSList *old_tags = NULL;
MooLineMark **old_marks = NULL;
guint i, n_old_marks = 0;
if (move_to >= 0)
{
line = _moo_line_buffer_get_line (line_buf, first + num - 1);
old_tags = line->hl_info->tags;
line->hl_info->tags = NULL;
old_marks = line->marks;
n_old_marks = line->n_marks;
line->marks = NULL;
if (n_old_marks)
_moo_text_btree_update_n_marks (line_buf->tree, line, -((int) n_old_marks));
@ -113,8 +105,6 @@ _moo_line_buffer_delete (LineBuffer *line_buf,
{
line = _moo_line_buffer_get_line (line_buf, move_to);
line->hl_info->tags = g_slist_concat (line->hl_info->tags, old_tags);
if (n_old_marks)
{
MooLineMark **tmp = g_new (MooLineMark*, n_old_marks + line->n_marks);
@ -492,8 +482,6 @@ _moo_line_buffer_cleanup (LineBuffer *line_buf)
{
Line *line = _moo_line_buffer_get_line (line_buf, i);
_moo_line_erase_segments (line);
g_slist_free (line->hl_info->tags);
line->hl_info->tags = NULL;
line->hl_info->tags_applied = FALSE;
}
}

View File

@ -59,7 +59,6 @@ struct _HLInfo {
Segment *segments;
guint n_segments;
guint n_segments_alloc__;
GSList *tags; /* tags applied (maybe) in this line */
guint tags_applied : 1; /* correct highlighting tags were applied */
};
@ -97,8 +96,7 @@ GSList *_moo_line_buffer_get_marks_in_range (LineBuffer *line_buf,
void _moo_line_buffer_split_line (LineBuffer *line_buf,
int line,
int num_new_lines,
GtkTextTag *tag);
int num_new_lines);
void _moo_line_buffer_delete (LineBuffer *line_buf,
int first,
int num,
@ -126,20 +124,6 @@ void _moo_line_add_segment (Line *line,
(ar__)->first = 0; \
(ar__)->last = size__ - 1; \
#define LINE_SET_TAGS_APPLIED(line__) \
G_STMT_START { \
(line__)->hl_info->_tags_applied = TRUE; \
(line__)->hl_info->_dirty = TRUE; \
} G_STMT_END
#define LINE_UNSET_TAGS_APPLIED(line__) \
G_STMT_START { \
(line__)->hl_info->_tags_applied = FALSE; \
} G_STMT_END
#define LINE_DIRTY(line__) ((line__)->hl_info->_dirty)
#define LINE_TAGS_APPLIED(line__) ((line__)->hl_info->_tags_applied)
#define BUF_CLEAN(line_buf__) (AREA_IS_EMPTY__ (&(line_buf__)->invalid))
#define BUF_SET_CLEAN(line_buf__) (AREA_SET_EMPTY__ (&(line_buf__)->invalid))

View File

@ -20,8 +20,7 @@ static BTNode *bt_node_new (BTNode *parent,
guint n_children,
guint count,
guint n_marks);
static BTData *bt_data_new (BTNode *parent,
gpointer tag);
static BTData *bt_data_new (BTNode *parent);
static void bt_node_free_rec (BTNode *node,
GSList **removed_marks);
static void bt_data_free (BTData *data,
@ -63,7 +62,7 @@ _moo_text_btree_new (void)
tree->depth = 0;
tree->root = bt_node_new (NULL, 1, 1, 0);
tree->root->is_bottom = TRUE;
tree->root->data[0] = bt_data_new (tree->root, NULL);
tree->root->data[0] = bt_data_new (tree->root);
CHECK_INTEGRITY (tree, TRUE);
@ -175,8 +174,6 @@ hl_info_free (HLInfo *info)
{
#ifdef __MOO__
g_free (info->segments);
g_slist_foreach (info->tags, (GFunc) g_object_unref, NULL);
g_slist_free (info->tags);
hl_info_free__ (info);
#endif
}
@ -184,17 +181,11 @@ hl_info_free (HLInfo *info)
static BTData*
bt_data_new (BTNode *parent,
gpointer tag)
bt_data_new (BTNode *parent)
{
BTData *data = data_new__ ();
data->parent = parent;
data->hl_info = hl_info_new ();
if (tag)
data->hl_info->tags = g_slist_prepend (NULL, g_object_ref (tag));
return data;
}
@ -280,8 +271,7 @@ node_remove__ (BTNode *node, gpointer data)
BTData*
_moo_text_btree_insert (BTree *tree,
guint index_,
gpointer tag)
guint index_)
{
BTNode *node, *tmp;
BTData *data;
@ -307,7 +297,7 @@ _moo_text_btree_insert (BTree *tree,
g_assert (node->n_children < BTREE_NODE_MAX_CAPACITY);
g_assert (index_ <= node->n_children);
data = bt_data_new (node, tag);
data = bt_data_new (node);
node_insert__ (node, data, index_);
for (tmp = node; tmp != NULL; tmp = tmp->parent)
@ -530,8 +520,7 @@ _moo_text_btree_delete (BTree *tree,
void
_moo_text_btree_insert_range (BTree *tree,
int first,
int num,
gpointer tag)
int num)
{
int i;
@ -540,7 +529,7 @@ _moo_text_btree_insert_range (BTree *tree,
g_assert (num > 0);
for (i = 0; i < num; ++i)
_moo_text_btree_insert (tree, first, tag);
_moo_text_btree_insert (tree, first);
}

View File

@ -76,16 +76,14 @@ BTData *_moo_text_btree_get_data (BTree *tree,
guint index_);
BTData *_moo_text_btree_insert (BTree *tree,
guint index_,
gpointer tag);
guint index_);
void _moo_text_btree_delete (BTree *tree,
guint index_,
GSList **removed_marks);
void _moo_text_btree_insert_range (BTree *tree,
int first,
int num,
gpointer tag);
int num);
void _moo_text_btree_delete_range (BTree *tree,
int first,
int num,

View File

@ -531,8 +531,6 @@ moo_text_buffer_insert_text (GtkTextBuffer *text_buffer,
moo_text_buffer_unhighlight_brackets (buffer);
tag = _moo_text_iter_get_syntax_tag (pos);
GTK_TEXT_BUFFER_CLASS(moo_text_buffer_parent_class)->insert_text (text_buffer, pos, text, length);
last_line = gtk_text_iter_get_line (pos);
@ -541,8 +539,7 @@ moo_text_buffer_insert_text (GtkTextBuffer *text_buffer,
_moo_line_buffer_invalidate (buffer->priv->line_buf, first_line);
else
_moo_line_buffer_split_line (buffer->priv->line_buf,
first_line, last_line - first_line,
tag);
first_line, last_line - first_line);
/* XXX btree can do it better ? i guess it can't */
if (starts_line && ins_line)