[geany/geany] 4e9802: Swap the merge arguments if len(small_array) > len(big_array)

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:      4e98021689fbc744b75a773f5095d4f7472f4430
             https://github.com/geany/geany/commit/4e98021689fbc744b75a773f5095d4f7472f4430

Log Message:
-----------
Swap the merge arguments if len(small_array) > len(big_array)


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

Modified: tagmanager/src/tm_tag.c
30 lines changed, 21 insertions(+), 9 deletions(-)
===================================================================
@@ -891,20 +891,32 @@ GPtrArray *tm_tags_remove_file_tags(TMSourceFile *source_file, GPtrArray *tags_a
  * 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_big_small(GPtrArray *big_array, GPtrArray *small_array) {
+static GPtrArray *merge(GPtrArray *big_array, GPtrArray *small_array) {
 	gint i1 = 0;  /* index to big_array */
 	gint i2 = 0;  /* index to small_array */
-	/* on average, we are merging a value from small_array every 
-	 * len(big_array) / len(small_array) values - good approximation for fast jump
-	 * step size */
-	gint initial_step = big_array->len / small_array->len;
-	initial_step = initial_step > 4 ? initial_step : 1;
-	gint step = initial_step;
+	gint initial_step;
+	initial_step;
+	gint step;
 	GPtrArray *res_array = g_ptr_array_sized_new(big_array->len + small_array->len);
 #ifdef TM_DEBUG
 	gint cmpnum = 0;
 #endif
 
+	/* swap the arrays if len(small) > len(big) */
+	if (small_array->len > big_array->len)
+	{
+		GPtrArray *tmp = small_array;
+		small_array = big_array;
+		big_array = tmp;
+	}
+	
+	/* on average, we are merging a value from small_array every 
+	 * len(big_array) / len(small_array) values - good approximation for fast jump
+	 * step size */
+	initial_step = big_array->len / small_array->len;
+	initial_step = initial_step > 4 ? initial_step : 1;
+	step = initial_step;
+	
 	while (i1 < big_array->len && i2 < small_array->len)
 	{
 		gint cmpval;
@@ -975,13 +987,13 @@ static GPtrArray *merge_big_small(GPtrArray *big_array, GPtrArray *small_array)
 	return res_array;
 }
 
-GPtrArray *tm_tags_merge_big_small(GPtrArray *big_array, GPtrArray *small_array, TMTagAttrType *sort_attributes)
+GPtrArray *tm_tags_merge(GPtrArray *big_array, GPtrArray *small_array, TMTagAttrType *sort_attributes)
 {
 	GPtrArray *res_array;
 	
 	s_sort_attrs = sort_attributes;
 	s_partial = FALSE;
-	res_array = merge_big_small(big_array, small_array);
+	res_array = merge(big_array, small_array);
 	s_sort_attrs = NULL;
 	return res_array;
 }


Modified: tagmanager/src/tm_tag.h
2 lines changed, 1 insertions(+), 1 deletions(-)
===================================================================
@@ -191,7 +191,7 @@ int tm_tag_compare(const void *ptr1, const void *ptr2);
 
 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);
+GPtrArray *tm_tags_merge(GPtrArray *big_array, GPtrArray *small_array, TMTagAttrType *sort_attributes);
 
 gboolean tm_tags_sort(GPtrArray *tags_array, TMTagAttrType *sort_attributes, gboolean dedup);
 


Modified: tagmanager/src/tm_workspace.c
4 lines changed, 2 insertions(+), 2 deletions(-)
===================================================================
@@ -208,7 +208,7 @@ gboolean tm_workspace_load_global_tags(const char *tags_file, gint mode)
 	tm_tags_sort(file_tags, global_tags_sort_attrs, TRUE);
 
 	/* reorder the whole array, because tm_tags_find expects a sorted array */
-	new_tags = tm_tags_merge_big_small(theWorkspace->global_tags, 
+	new_tags = tm_tags_merge(theWorkspace->global_tags, 
 		file_tags, global_tags_sort_attrs);
 	g_ptr_array_free(theWorkspace->global_tags, TRUE);
 	g_ptr_array_free(file_tags, TRUE);
@@ -555,7 +555,7 @@ void tm_workspace_merge_file_tags(TMSourceFile *source_file)
 		
 	if (source_file->tags_array != NULL)
 	{
-		GPtrArray *new_tags = tm_tags_merge_big_small(theWorkspace->tags_array, 
+		GPtrArray *new_tags = tm_tags_merge(theWorkspace->tags_array, 
 			source_file->tags_array, sort_attrs);
 		/* tags owned by TMSourceFile - free just the pointer array */
 		g_ptr_array_free(theWorkspace->tags_array, 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