From 3f720eb838c8b3c21a8c14edecf6400259a736bb Mon Sep 17 00:00:00 2001 From: scottmk Date: Wed, 4 Nov 2009 16:32:10 +0000 Subject: [PATCH] 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 git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@1841 9efc2488-bf62-4759-914b-345cdb29e865 --- src/router/osrf_router.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/router/osrf_router.c b/src/router/osrf_router.c index 7c04279..bbc9446 100644 --- a/src/router/osrf_router.c +++ b/src/router/osrf_router.c @@ -25,6 +25,7 @@ struct osrfRouterStruct { 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 @@ osrfRouter* osrfNewRouter( 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 @@ void osrfRouterRun( osrfRouter* router ) { 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 @@ void osrfRouterRun( osrfRouter* router ) { osrfRouterClassHandleIncoming( router, classname, class ); } } - } - - osrfHashIteratorFree(itr); - } - } + } // end while + } // end while + } // end while } @@ -647,6 +648,7 @@ static void osrfRouterNodeFree( char* remoteId, void* n ) { void osrfRouterFree( osrfRouter* router ) { if(!router) return; + osrfHashIteratorFree( router->class_itr); osrfHashFree(router->classes); free(router->domain); free(router->name); -- 2.11.0