Merge pull request #514 from techee/linear_tag_remove
Add linear tag remove path for cases where not many files are open
This commit is contained in:
commit
6f60de3656
@ -828,6 +828,31 @@ gboolean tm_tags_sort(GPtrArray *tags_array, TMTagAttrType *sort_attributes,
|
|||||||
void tm_tags_remove_file_tags(TMSourceFile *source_file, GPtrArray *tags_array)
|
void tm_tags_remove_file_tags(TMSourceFile *source_file, GPtrArray *tags_array)
|
||||||
{
|
{
|
||||||
guint i;
|
guint i;
|
||||||
|
|
||||||
|
/* Now we choose between an algorithm with complexity O(tags_array->len) and
|
||||||
|
* O(source_file->tags_array->len * log(tags_array->len)). The latter algorithm
|
||||||
|
* is better when tags_array contains many times more tags than
|
||||||
|
* source_file->tags_array so instead of trying to find the removed tags
|
||||||
|
* linearly, binary search is used. The constant 20 is more or less random
|
||||||
|
* but seems to work well. It's exact value isn't so critical because it's
|
||||||
|
* the extremes where the difference is the biggest: when
|
||||||
|
* source_file->tags_array->len == tags_array->len (single file open) and
|
||||||
|
* source_file->tags_array->len << tags_array->len (the number of tags
|
||||||
|
* from the file is a small fraction of all tags).
|
||||||
|
*/
|
||||||
|
if (source_file->tags_array->len != 0 &&
|
||||||
|
tags_array->len / source_file->tags_array->len < 20)
|
||||||
|
{
|
||||||
|
for (i = 0; i < tags_array->len; i++)
|
||||||
|
{
|
||||||
|
TMTag *tag = tags_array->pdata[i];
|
||||||
|
|
||||||
|
if (tag->file == source_file)
|
||||||
|
tags_array->pdata[i] = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
GPtrArray *to_delete = g_ptr_array_sized_new(source_file->tags_array->len);
|
GPtrArray *to_delete = g_ptr_array_sized_new(source_file->tags_array->len);
|
||||||
|
|
||||||
for (i = 0; i < source_file->tags_array->len; i++)
|
for (i = 0; i < source_file->tags_array->len; i++)
|
||||||
@ -859,6 +884,7 @@ void tm_tags_remove_file_tags(TMSourceFile *source_file, GPtrArray *tags_array)
|
|||||||
*tag = NULL;
|
*tag = NULL;
|
||||||
}
|
}
|
||||||
g_ptr_array_free(to_delete, TRUE);
|
g_ptr_array_free(to_delete, TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
tm_tags_prune(tags_array);
|
tm_tags_prune(tags_array);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user