Merge branch 'tm/faster-current-tag'

This makes tm_get_current_tag() roughly 4.5 times faster.
This commit is contained in:
Colomban Wendling 2014-08-01 17:26:54 +02:00
commit 4cfe71a487

View File

@ -745,27 +745,23 @@ tm_workspace_find_scoped (const char *name, const char *scope, gint type,
const TMTag *
tm_get_current_tag (GPtrArray * file_tags, const gulong line, const guint tag_types)
{
GPtrArray *const local = tm_tags_extract (file_tags, tag_types);
TMTag *matching_tag = NULL;
if (local && local->len)
if (file_tags && file_tags->len)
{
guint i;
gulong matching_line = 0;
glong delta;
for (i = 0; (i < local->len); ++i)
for (i = 0; (i < file_tags->len); ++i)
{
TMTag *tag = TM_TAG (local->pdata[i]);
delta = line - tag->atts.entry.line;
if (delta >= 0 && (gulong)delta < line - matching_line)
TMTag *tag = TM_TAG (file_tags->pdata[i]);
if (tag && tag->type & tag_types &&
tag->atts.entry.line <= line && tag->atts.entry.line > matching_line)
{
matching_tag = tag;
matching_line = tag->atts.entry.line;
}
}
}
if (local)
g_ptr_array_free (local, TRUE);
return matching_tag;
}