From 736fc2516e2a134eea33af145e3e51a8fb687b58 Mon Sep 17 00:00:00 2001 From: scottmk Date: Mon, 3 Aug 2009 03:02:48 +0000 Subject: [PATCH] In the initialization routines of oils_cstore.c: recoded a couple of loops to use an osrfHashIterator, instead of creating an osrfStringArray of keys and then traversing that. This change eliminates over 500 mallocs and frees. In addition, traversing the osrfHash with an iterator just hops along a linked list, which is almost certainly faster than calculating a hash total for every key. git-svn-id: svn://svn.open-ils.org/ILS/trunk@13789 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/c-apps/oils_cstore.c | 42 +++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/Open-ILS/src/c-apps/oils_cstore.c b/Open-ILS/src/c-apps/oils_cstore.c index 1f4d63c83f..e1dcefb248 100644 --- a/Open-ILS/src/c-apps/oils_cstore.c +++ b/Open-ILS/src/c-apps/oils_cstore.c @@ -228,18 +228,20 @@ int osrfAppInitialize() { const int global_method_count = sizeof( global_method ) / sizeof ( global_method[0] ); - int c_index = 0; - char* classname; - osrfStringArray* classes = osrfHashKeys( oilsIDL() ); - osrfLogDebug(OSRF_LOG_MARK, "%d classes loaded", classes->size ); - osrfLogDebug(OSRF_LOG_MARK, - "At most %d methods will be generated", classes->size * global_method_count); + unsigned long class_count = osrfHashGetCount( oilsIDL() ); + osrfLogDebug(OSRF_LOG_MARK, "%lu classes loaded", class_count ); + osrfLogDebug(OSRF_LOG_MARK, + "At most %lu methods will be generated", + (unsigned long) (class_count * global_method_count) ); + + osrfHashIterator* class_itr = osrfNewHashIterator( oilsIDL() ); + osrfHash* idlClass = NULL; // For each class in IDL... - while ( (classname = osrfStringArrayGetString(classes, c_index++)) ) { - osrfLogInfo(OSRF_LOG_MARK, "Generating class methods for %s", classname); + while( (idlClass = osrfHashIteratorNext( class_itr ) ) ) { - osrfHash* idlClass = osrfHashGet(oilsIDL(), classname); + const char* classname = osrfHashIteratorKey( class_itr ); + osrfLogInfo(OSRF_LOG_MARK, "Generating class methods for %s", classname); if (!osrfStringArrayContains( osrfHashGet(idlClass, "controller"), MODULENAME )) { osrfLogInfo(OSRF_LOG_MARK, "%s is not listed as a controller for %s, moving on", MODULENAME, classname); @@ -332,7 +334,7 @@ int osrfAppInitialize() { } // end for each class in IDL buffer_free( method_name ); - osrfStringArrayFree( classes ); + osrfHashIteratorFree( class_itr ); return 0; } @@ -422,12 +424,11 @@ int osrfAppChildInit() { osrfLogInfo(OSRF_LOG_MARK, "%s successfully connected to the database", MODULENAME); - int i = 0; - char* classname; - osrfStringArray* classes = osrfHashKeys( oilsIDL() ); + osrfHashIterator* class_itr = osrfNewHashIterator( oilsIDL() ); + osrfHash* class = NULL; - while ( (classname = osrfStringArrayGetString(classes, i++)) ) { - osrfHash* class = osrfHashGet( oilsIDL(), classname ); + while( (class = osrfHashIteratorNext( class_itr ) ) ) { + const char* classname = osrfHashIteratorKey( class_itr ); osrfHash* fields = osrfHashGet( class, "fields" ); if( str_is_true( osrfHashGet(class, "virtual") ) ) { @@ -518,13 +519,12 @@ int osrfAppChildInit() { ++columnIndex; } // end while loop for traversing result dbi_result_free(result); - } else { - osrfLogDebug(OSRF_LOG_MARK, "No data found for class [%s]...", (char*)classname); - } - } - - osrfStringArrayFree(classes); + } else { + osrfLogDebug(OSRF_LOG_MARK, "No data found for class [%s]...", (char*)classname); + } + } // end for each class in IDL + osrfHashIteratorFree( class_itr ); child_initialized = 1; return 0; } -- 2.11.0