summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Curley <charlescurley@charlescurley.com>2017-12-06 14:17:52 -0700
committerCharles Curley <charlescurley@charlescurley.com>2017-12-06 14:17:52 -0700
commit8fef4cc768780efb54fe2afeb2bc63879b0ef90f (patch)
tree30461f14e20396fb52bb49d89231ebe7d9290fdb
parent68cc6c392a6e83b9850aad6689d447f699cd5525 (diff)
downloadnavit-8fef4cc768780efb54fe2afeb2bc63879b0ef90f.tar.gz
Once more with feeling. Get rid of the function distance_set_last ()
entirely and use compile-time maths to do the work. fix:navit:navigation.c modified: navit/navigation.c
-rw-r--r--navit/navigation.c23
1 files changed, 5 insertions, 18 deletions
diff --git a/navit/navigation.c b/navit/navigation.c
index 0252730a4..be894c7ed 100644
--- a/navit/navigation.c
+++ b/navit/navigation.c
@@ -194,8 +194,9 @@ struct navigation {
/** @brief Set of simplified distance values that are easy to be pronounced.
* Used for the 'vocabulary_distances' configuration.
*/
-int distances[]={1,2,3,4,5,10,25,50,75,100,150,200,250,300,400,500,750,-1};
-
+const int distances[]={1,2,3,4,5,10,25,50,75,100,150,200,250,300,400,500,750};
+#define SIZE_OF_ARRAY_DISTANCES (sizeof (distances)/sizeof (int))
+#define LAST_DISTANCE (SIZE_OF_ARRAY_DISTANCES - 1)
/* Allowed values for navigation_maneuver.merge_or_exit
* The numeric values are chosen in such a way that they can be interpreted as flags:
@@ -965,20 +966,6 @@ round_distance(int dist)
return dist*10000;
}
-/** @brief Returns the last element of the simplified numbers containing a distance value.
- * @return value with the highest distance.
- */
-static int
-distance_set_last(void)
-{
- static int i=0;
-
- while (distances[i] > 0)
- i++;
-
- return distances[ i>0 ? i-1 : 0 ];
-}
-
/** @brief Restricts the distance value to a simple set of pronounceable numbers.
* @param dist The distance to be processed
* @return distance Simplified distance value
@@ -987,14 +974,14 @@ static int
round_distance_reduced( int dist )
{
int factor = 1;
- if (dist > distance_set_last())
+ if (dist > distances[LAST_DISTANCE])
{
dist=(dist+500)/1000;
factor = 1000;
}
int i=0,d=0,m=0;
- while (distances[i] > 0) {
+ while (i < SIZE_OF_ARRAY_DISTANCES) {
if (!i || abs(distances[i]-dist) <= d) {
d=abs(distances[i]-dist);
m=i;