[geany/geany] fe98ea: Use the new merge implementation also for global tags

Jiří Techet git-noreply at xxxxx
Sat Nov 8 18:57:51 UTC 2014


Branch:      refs/heads/master
Author:      Jiří Techet <techet at gmail.com>
Committer:   Jiří Techet <techet at gmail.com>
Date:        Sat, 18 Oct 2014 19:40:10 UTC
Commit:      fe98ea61564d4195f9d7619f48b4983f5417eece
             https://github.com/geany/geany/commit/fe98ea61564d4195f9d7619f48b4983f5417eece

Log Message:
-----------
Use the new merge implementation also for global tags


Modified Paths:
--------------
    tagmanager/src/tm_tag.c
    tagmanager/src/tm_tag.h
    tagmanager/src/tm_workspace.c

Modified: tagmanager/src/tm_tag.c
46 lines changed, 0 insertions(+), 46 deletions(-)
===================================================================
@@ -852,52 +852,6 @@ gboolean tm_tags_custom_dedup(GPtrArray *tags_array, TMTagCompareFunc compare_fu
 	return TRUE;
 }
 
-/* Sorts newly-added tags and merges them in order with existing tags.
- * This is much faster than resorting the whole array.
- * Note: Having the caller append to the existing array should be faster
- * than creating a new array which would likely get resized more than once.
- * tags_array: array with new (perhaps unsorted) tags appended.
- * orig_len: number of existing tags. */
-gboolean tm_tags_merge(GPtrArray *tags_array, gsize orig_len,
-	TMTagAttrType *sort_attributes, gboolean dedup)
-{
-	gpointer *copy, *a, *b;
-	gsize copy_len, i;
-
-	if ((!tags_array) || (!tags_array->len) || orig_len >= tags_array->len)
-		return TRUE;
-	if (!orig_len)
-		return tm_tags_sort(tags_array, sort_attributes, dedup);
-	copy_len = tags_array->len - orig_len;
-	copy = g_memdup(tags_array->pdata + orig_len, copy_len * sizeof(gpointer));
-	s_sort_attrs = sort_attributes;
-	s_partial = FALSE;
-	/* enforce copy sorted with same attributes for merge */
-	qsort(copy, copy_len, sizeof(gpointer), tm_tag_compare);
-	a = tags_array->pdata + orig_len - 1;
-	b = copy + copy_len - 1;
-	for (i = tags_array->len - 1;; i--)
-	{
-		gint cmp = tm_tag_compare(a, b);
-
-		tags_array->pdata[i] = (cmp >= 0) ? *a-- : *b--;
-		if (a < tags_array->pdata)
-		{
-			/* include remainder of copy as well as current value of b */
-			memcpy(tags_array->pdata, copy, ((b + 1) - copy) * sizeof(gpointer));
-			break;
-		}
-		if (b < copy)
-			break; /* remaining elements of 'a' are in place already */
-		g_assert(i != 0);
-	}
-	s_sort_attrs = NULL;
-	g_free(copy);
-	if (dedup)
-		tm_tags_dedup(tags_array, sort_attributes);
-	return TRUE;
-}
-
 /*
  Sort an array of tags on the specified attribuites using the inbuilt comparison
  function.


Modified: tagmanager/src/tm_tag.h
3 lines changed, 0 insertions(+), 3 deletions(-)
===================================================================
@@ -189,9 +189,6 @@ gboolean tm_tag_write(TMTag *tag, FILE *file, guint attrs);
 
 int tm_tag_compare(const void *ptr1, const void *ptr2);
 
-gboolean tm_tags_merge(GPtrArray *tags_array, gsize orig_len,
-	TMTagAttrType *sort_attributes, gboolean dedup);
-
 GPtrArray *tm_tags_remove_file_tags(TMSourceFile *source_file, GPtrArray *tags_array);
 
 GPtrArray *tm_tags_merge_big_small(GPtrArray *big_array, GPtrArray *small_array, TMTagAttrType *sort_attributes);


Modified: tagmanager/src/tm_workspace.c
14 lines changed, 12 insertions(+), 2 deletions(-)
===================================================================
@@ -154,6 +154,7 @@ gboolean tm_workspace_load_global_tags(const char *tags_file, gint mode)
 	gsize orig_len;
 	guchar buf[BUFSIZ];
 	FILE *fp;
+	GPtrArray *file_tags, *new_tags;
 	TMTag *tag;
 	TMFileFormat format = TM_FILE_FORMAT_TAGMANAGER;
 
@@ -198,12 +199,21 @@ gboolean tm_workspace_load_global_tags(const char *tags_file, gint mode)
 		}
 		rewind(fp); /* reset the file pointer, to start reading again from the beginning */
 	}
+	
+	file_tags = g_ptr_array_new();
 	while (NULL != (tag = tm_tag_new_from_file(NULL, fp, mode, format)))
-		g_ptr_array_add(theWorkspace->global_tags, tag);
+		g_ptr_array_add(file_tags, tag);
 	fclose(fp);
+	
+	tm_tags_sort(file_tags, global_tags_sort_attrs, TRUE);
 
 	/* reorder the whole array, because tm_tags_find expects a sorted array */
-	tm_tags_merge(theWorkspace->global_tags, orig_len, global_tags_sort_attrs, TRUE);
+	new_tags = tm_tags_merge_big_small(theWorkspace->global_tags, 
+		file_tags, global_tags_sort_attrs);
+	g_ptr_array_free(theWorkspace->global_tags, TRUE);
+	g_ptr_array_free(file_tags, TRUE);
+	theWorkspace->global_tags = new_tags;
+
 	return TRUE;
 }
 



--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).


More information about the Commits mailing list