Branch: refs/heads/master Author: Jiří Techet techet@gmail.com Committer: Jiří Techet techet@gmail.com Date: Wed, 22 Oct 2014 14:14:59 UTC Commit: 6ef41c65a9504f54bab17253359edaafb9d771fa https://github.com/geany/geany/commit/6ef41c65a9504f54bab17253359edaafb9d771...
Log Message: ----------- Various cleanups in the merge algorithm
Remove the continue statement and use if/else instead. Initialize the val1 variable only with the value used for the chosen path (normal/fast).
Modified Paths: -------------- tagmanager/src/tm_tag.c
Modified: tagmanager/src/tm_tag.c 44 lines changed, 23 insertions(+), 21 deletions(-) =================================================================== @@ -848,8 +848,7 @@ static GPtrArray *merge(GPtrArray *big_array, GPtrArray *small_array) { while (i1 < big_array->len && i2 < small_array->len) { - gint cmpval; - gpointer val1 = big_array->pdata[i1]; + gpointer val1; gpointer val2 = small_array->pdata[i2];
if (step > 4) /* fast path start */ @@ -871,36 +870,39 @@ static GPtrArray *merge(GPtrArray *big_array, GPtrArray *small_array) { g_ptr_array_add(res_array, val1); i1++; } - continue; } else { /* lower the step and try again */ step /= 2; - continue; } } /* fast path end */ - -#ifdef TM_DEBUG - cmpnum++; -#endif - cmpval = tm_tag_compare(&val1, &val2); - if (cmpval < 0) - { - g_ptr_array_add(res_array, val1); - i1++; - } else { - g_ptr_array_add(res_array, val2); - i2++; - /* 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 */ + gint cmpval; + +#ifdef TM_DEBUG + cmpnum++; +#endif + val1 = big_array->pdata[i1]; + cmpval = tm_tag_compare(&val1, &val2); + if (cmpval < 0) + { + g_ptr_array_add(res_array, val1); + i1++; + } + else + { + g_ptr_array_add(res_array, val2); + i2++; + /* 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 */ + } } } - + /* end of one of the arrays reached - copy the rest from the other array */ while (i1 < big_array->len) g_ptr_array_add(res_array, big_array->pdata[i1++]);
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).