[Opensrf-commits] r1841 - trunk/src/router (scottmk)

svn at svn.open-ils.org svn at svn.open-ils.org
Wed Nov 4 11:32:13 EST 2009


Author: scottmk
Date: 2009-11-04 11:32:10 -0500 (Wed, 04 Nov 2009)
New Revision: 1841

Modified:
   trunk/src/router/osrf_router.c
Log:
1. Added an osrfHashIterator as a member of osrfRouter, so that
we can reuse it when repeatedly traversing the list of classes.
This way we don't have to create and destroy an osrfHashIterator
on every iteration.

2. In osrfRouterRun(): eliminated a pointless hash look up in the
innermost loop.

M    src/router/osrf_router.c


Modified: trunk/src/router/osrf_router.c
===================================================================
--- trunk/src/router/osrf_router.c	2009-11-03 22:25:12 UTC (rev 1840)
+++ trunk/src/router/osrf_router.c	2009-11-04 16:32:10 UTC (rev 1841)
@@ -25,6 +25,7 @@
 		osrfRouterClass.
 	*/
 	osrfHash* classes;
+	osrfHashIterator* class_itr;  /**< For traversing the list of classes */
 	char* domain;         /**< Domain name of Jabber server. */
 	char* name;           /**< Router's username for the Jabber logon. */
 	char* resource;       /**< Router's resource name for the Jabber logon. */
@@ -155,6 +156,7 @@
 
 	router->classes = osrfNewHash();
 	osrfHashSetCallback(router->classes, &osrfRouterClassFree);
+	router->class_itr = osrfNewHashIterator( router->classes );
 
 	// Prepare to connect to Jabber, as a non-component, over TCP (not UNIX domain).
 	router->connection = client_init( domain, port, NULL, 0 );
@@ -230,13 +232,14 @@
 		while( numhandled < selectret ) {
 
 			osrfRouterClass* class;
-			osrfHashIterator* itr = osrfNewHashIterator(router->classes);
+			osrfHashIterator* itr = router->class_itr;  // remove a layer of indirection
+			osrfHashIteratorReset( itr );
 
 			while( (class = osrfHashIteratorNext(itr)) ) {
 
 				const char* classname = osrfHashIteratorKey(itr);
 
-				if( classname && (class = osrfRouterFindClass( router, classname )) ) {
+				if( classname ) {
 
 					osrfLogDebug( OSRF_LOG_MARK, "Checking %s for activity...", classname );
 
@@ -247,11 +250,9 @@
 						osrfRouterClassHandleIncoming( router, classname, class );
 					}
 				}
-			}
-
-			osrfHashIteratorFree(itr);
-		}
-	}
+			} // end while
+		} // end while
+	} // end while
 }
 
 
@@ -647,6 +648,7 @@
 void osrfRouterFree( osrfRouter* router ) {
 	if(!router) return;
 
+	osrfHashIteratorFree( router->class_itr);
 	osrfHashFree(router->classes);
 	free(router->domain);
 	free(router->name);



More information about the opensrf-commits mailing list