Branch: refs/heads/master Author: Jiří Techet techet@gmail.com Committer: Jiří Techet techet@gmail.com Date: Thu, 30 Oct 2014 21:08:17 UTC Commit: be131b00f9822309089c61a053125378bdefa005 https://github.com/geany/geany/commit/be131b00f9822309089c61a053125378bdefa0...
Log Message: ----------- Extend dedup() and merge() to unref the duplicate tag when needed
Modified Paths: -------------- src/editor.c src/symbols.c tagmanager/src/tm_tag.c tagmanager/src/tm_tag.h tagmanager/src/tm_workspace.c
Modified: src/editor.c 2 lines changed, 1 insertions(+), 1 deletions(-) =================================================================== @@ -1873,7 +1873,7 @@ static gchar *find_calltip(const gchar *word, GeanyFiletype *ft) TMTagAttrType sort_attr[] = {tm_tag_attr_name_t, tm_tag_attr_scope_t, tm_tag_attr_arglist_t, 0};
- tm_tags_sort((GPtrArray *) tags, sort_attr, TRUE); + tm_tags_sort((GPtrArray *) tags, sort_attr, TRUE, FALSE); }
/* if the current word has changed since last time, start with the first tag match */
Modified: src/symbols.c 2 lines changed, 1 insertions(+), 1 deletions(-) =================================================================== @@ -365,7 +365,7 @@ GString *symbols_get_macro_list(gint lang) return NULL; }
- tm_tags_sort(ftags, NULL, FALSE); + tm_tags_sort(ftags, NULL, FALSE, FALSE); for (j = 0; j < ftags->len; j++) { if (j > 0)
Modified: tagmanager/src/tm_tag.c 21 lines changed, 15 insertions(+), 6 deletions(-) =================================================================== @@ -761,7 +761,7 @@ gboolean tm_tags_prune(GPtrArray *tags_array) on the same criteria. @return TRUE on success, FALSE on failure */ -gboolean tm_tags_dedup(GPtrArray *tags_array, TMTagAttrType *sort_attributes) +gboolean tm_tags_dedup(GPtrArray *tags_array, TMTagAttrType *sort_attributes, gboolean unref_duplicates) { TMSortOptions sort_options; guint i; @@ -774,6 +774,8 @@ gboolean tm_tags_dedup(GPtrArray *tags_array, TMTagAttrType *sort_attributes) { if (0 == tm_tag_compare(&(tags_array->pdata[i - 1]), &(tags_array->pdata[i]), &sort_options)) { + if (unref_duplicates) + tm_tag_unref(tags_array->pdata[i-1]); tags_array->pdata[i-1] = NULL; } } @@ -789,7 +791,8 @@ gboolean tm_tags_dedup(GPtrArray *tags_array, TMTagAttrType *sort_attributes) @param dedup Whether to deduplicate the sorted array @return TRUE on success, FALSE on failure */ -gboolean tm_tags_sort(GPtrArray *tags_array, TMTagAttrType *sort_attributes, gboolean dedup) +gboolean tm_tags_sort(GPtrArray *tags_array, TMTagAttrType *sort_attributes, + gboolean dedup, gboolean unref_duplicates) { TMSortOptions sort_options; @@ -799,7 +802,7 @@ gboolean tm_tags_sort(GPtrArray *tags_array, TMTagAttrType *sort_attributes, gbo sort_options.partial = FALSE; g_ptr_array_sort_with_data(tags_array, tm_tag_compare, &sort_options); if (dedup) - tm_tags_dedup(tags_array, sort_attributes); + tm_tags_dedup(tags_array, sort_attributes, unref_duplicates); return TRUE; }
@@ -821,7 +824,8 @@ void tm_tags_remove_file_tags(TMSourceFile *source_file, GPtrArray *tags_array) * The merge complexity depends mostly on the size of the small array * and is almost independent of the size of the big array. * In addition, get rid of the duplicates (if both big_array and small_array are duplicate-free). */ -static GPtrArray *merge(GPtrArray *big_array, GPtrArray *small_array, TMSortOptions *sort_options) { +static GPtrArray *merge(GPtrArray *big_array, GPtrArray *small_array, + TMSortOptions *sort_options, gboolean unref_duplicates) { guint i1 = 0; /* index to big_array */ guint i2 = 0; /* index to small_array */ guint initial_step; @@ -898,7 +902,11 @@ static GPtrArray *merge(GPtrArray *big_array, GPtrArray *small_array, TMSortOpti /* value from small_array gets merged - reset the step size */ step = initial_step; if (cmpval == 0) + { i1++; /* remove the duplicate, keep just the newly merged value */ + if (unref_duplicates) + tm_tag_unref(val1); + } } } } @@ -918,14 +926,15 @@ static GPtrArray *merge(GPtrArray *big_array, GPtrArray *small_array, TMSortOpti return res_array; }
-GPtrArray *tm_tags_merge(GPtrArray *big_array, GPtrArray *small_array, TMTagAttrType *sort_attributes) +GPtrArray *tm_tags_merge(GPtrArray *big_array, GPtrArray *small_array, + TMTagAttrType *sort_attributes, gboolean unref_duplicates) { GPtrArray *res_array; TMSortOptions sort_options; sort_options.sort_attrs = sort_attributes; sort_options.partial = FALSE; - res_array = merge(big_array, small_array, &sort_options); + res_array = merge(big_array, small_array, &sort_options, unref_duplicates); return res_array; }
Modified: tagmanager/src/tm_tag.h 8 lines changed, 5 insertions(+), 3 deletions(-) =================================================================== @@ -163,15 +163,17 @@ gboolean tm_tag_write(TMTag *tag, FILE *file, guint attrs);
void tm_tags_remove_file_tags(TMSourceFile *source_file, GPtrArray *tags_array);
-GPtrArray *tm_tags_merge(GPtrArray *big_array, GPtrArray *small_array, TMTagAttrType *sort_attributes); +GPtrArray *tm_tags_merge(GPtrArray *big_array, GPtrArray *small_array, + TMTagAttrType *sort_attributes, gboolean unref_duplicates);
-gboolean tm_tags_sort(GPtrArray *tags_array, TMTagAttrType *sort_attributes, gboolean dedup); +gboolean tm_tags_sort(GPtrArray *tags_array, TMTagAttrType *sort_attributes, + gboolean dedup, gboolean unref_duplicates);
GPtrArray *tm_tags_extract(GPtrArray *tags_array, guint tag_types);
gboolean tm_tags_prune(GPtrArray *tags_array);
-gboolean tm_tags_dedup(GPtrArray *tags_array, TMTagAttrType *sort_attributes); +gboolean tm_tags_dedup(GPtrArray *tags_array, TMTagAttrType *sort_attributes, gboolean unref_duplicates);
TMTag **tm_tags_find(const GPtrArray *tags_array, const char *name, gboolean partial, gboolean tags_array_sorted, int * tagCount);
Modified: tagmanager/src/tm_workspace.c 18 lines changed, 9 insertions(+), 9 deletions(-) =================================================================== @@ -177,11 +177,11 @@ gboolean tm_workspace_load_global_tags(const char *tags_file, gint mode) g_ptr_array_add(file_tags, tag); fclose(fp); - tm_tags_sort(file_tags, global_tags_sort_attrs, TRUE); + tm_tags_sort(file_tags, global_tags_sort_attrs, TRUE, TRUE);
/* reorder the whole array, because tm_tags_find expects a sorted array */ new_tags = tm_tags_merge(theWorkspace->global_tags, - file_tags, global_tags_sort_attrs); + file_tags, global_tags_sort_attrs, TRUE); g_ptr_array_free(theWorkspace->global_tags, TRUE); g_ptr_array_free(file_tags, TRUE); theWorkspace->global_tags = new_tags; @@ -443,7 +443,7 @@ gboolean tm_workspace_create_global_tags(const char *pre_process, const char **i tm_source_file_free(source_file); return FALSE; } - if (FALSE == tm_tags_sort(tags_array, global_tags_sort_attrs, TRUE)) + if (FALSE == tm_tags_sort(tags_array, global_tags_sort_attrs, TRUE, FALSE)) { tm_source_file_free(source_file); return FALSE; @@ -505,7 +505,7 @@ void tm_workspace_update(void) #ifdef TM_DEBUG g_message("Total: %d tags", theWorkspace->tags_array->len); #endif - tm_tags_sort(theWorkspace->tags_array, sort_attrs, TRUE); + tm_tags_sort(theWorkspace->tags_array, sort_attrs, TRUE, FALSE); }
static void tm_workspace_merge_file_tags(TMSourceFile *source_file) @@ -514,7 +514,7 @@ static void tm_workspace_merge_file_tags(TMSourceFile *source_file) tm_tag_attr_scope_t, tm_tag_attr_type_t, tm_tag_attr_arglist_t, 0};
GPtrArray *new_tags = tm_tags_merge(theWorkspace->tags_array, - source_file->tags_array, sort_attrs); + source_file->tags_array, sort_attrs, FALSE); /* tags owned by TMSourceFile - free just the pointer array */ g_ptr_array_free(theWorkspace->tags_array, TRUE); theWorkspace->tags_array = new_tags; @@ -542,7 +542,7 @@ void tm_workspace_update_source_file(TMSourceFile *source_file, gboolean update_ tm_tags_remove_file_tags(source_file, theWorkspace->tags_array); } tm_source_file_parse(source_file); - tm_tags_sort(source_file->tags_array, NULL, FALSE); + tm_tags_sort(source_file->tags_array, NULL, FALSE, TRUE); if (update_workspace) { #ifdef TM_DEBUG @@ -589,7 +589,7 @@ void tm_workspace_update_source_file_buffer(TMSourceFile *source_file, guchar* t tm_tags_remove_file_tags(source_file, theWorkspace->tags_array); } tm_source_file_buffer_parse (source_file, text_buf, buf_size); - tm_tags_sort(source_file->tags_array, NULL, FALSE); + tm_tags_sort(source_file->tags_array, NULL, FALSE, TRUE); if (update_workspace) { #ifdef TM_DEBUG @@ -693,7 +693,7 @@ const GPtrArray *tm_workspace_find(const char *name, int type, TMTagAttrType *at }
if (attrs) - tm_tags_sort(tags, attrs, TRUE); + tm_tags_sort(tags, attrs, TRUE, FALSE); return tags; }
@@ -777,7 +777,7 @@ tm_workspace_find_scoped (const char *name, const char *scope, gint type, name, scope, type, partial, lang, FALSE); } if (attrs) - tm_tags_sort (tags, attrs, TRUE); + tm_tags_sort (tags, attrs, TRUE, FALSE); return tags; }
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).