[asterisk-commits] dlee: branch dlee/performance r399979 - /team/dlee/performance/main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Sep 27 12:57:13 CDT 2013


Author: dlee
Date: Fri Sep 27 12:57:11 2013
New Revision: 399979

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=399979
Log:
Ditched table_has_route in preference to just using table_find_route

Modified:
    team/dlee/performance/main/stasis_message_router.c

Modified: team/dlee/performance/main/stasis_message_router.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/performance/main/stasis_message_router.c?view=diff&rev=399979&r1=399978&r2=399979
==============================================================================
--- team/dlee/performance/main/stasis_message_router.c (original)
+++ team/dlee/performance/main/stasis_message_router.c Fri Sep 27 12:57:11 2013
@@ -53,18 +53,24 @@
 	struct stasis_message_route routes[];
 };
 
-static int table_has_route(struct route_table *table,
+static struct stasis_message_route *table_find_route(struct route_table *table,
 	struct stasis_message_type *message_type)
 {
 	size_t idx;
 
+	/* While a linear search for routes may seem very inefficient, most
+	 * route tables have six routes or less. For such small data, it's
+	 * hard to beat a linear search. If we start having larger route
+	 * tables, then we can look into containers with more efficient
+	 * lookups.
+	 */
 	for (idx = 0; idx < table->current_size; ++idx) {
 		if (table->routes[idx].message_type == message_type) {
-			return 1;
+			return &table->routes[idx];
 		}
 	}
 
-	return 0;
+	return NULL;
 }
 
 static int table_add_route(struct route_table **table_ptr,
@@ -74,7 +80,7 @@
 	struct route_table *table = *table_ptr;
 	struct stasis_message_route *route;
 
-	ast_assert(!table_has_route(table, message_type));
+	ast_assert(table_find_route(table, message_type) == NULL);
 
 	if (table->current_size + 1 > table->max_size) {
 		size_t new_max_size = table->max_size ? table->max_size * 2 : 1;
@@ -111,26 +117,6 @@
 		}
 	}
 	return -1;
-}
-
-static struct stasis_message_route *table_find_route(struct route_table *table,
-	struct stasis_message_type *message_type)
-{
-	size_t idx;
-
-	/* While a linear search for routes may seem very inefficient, most
-	 * route tables have six routes or less. For such small data, it's
-	 * hard to beat a linear search. If we start having larger route
-	 * tables, then we can look into containers with more efficient
-	 * lookups.
-	 */
-	for (idx = 0; idx < table->current_size; ++idx) {
-		if (table->routes[idx].message_type == message_type) {
-			return &table->routes[idx];
-		}
-	}
-
-	return NULL;
 }
 
 /*! \internal */
@@ -169,6 +155,8 @@
 	struct stasis_message_type *type = stasis_message_type(message);
 	SCOPED_AO2LOCK(lock, router);
 
+	ast_assert(route_out != NULL);
+
 	if (type == stasis_cache_update_type()) {
 		/* Find a cache route */
 		struct stasis_cache_update *update =




More information about the asterisk-commits mailing list