In SELECT(): replaced an osrfStringArray with an osrfHashIterator, in
authorscottmk <scottmk@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Sun, 22 Feb 2009 14:30:41 +0000 (14:30 +0000)
committerscottmk <scottmk@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Sun, 22 Feb 2009 14:30:41 +0000 (14:30 +0000)
order to reduce the number of mallocs and frees when traversing an osrfHash.

git-svn-id: svn://svn.open-ils.org/ILS/trunk@12262 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/c-apps/oils_cstore.c

index 5a8eca8..2b9a6a6 100644 (file)
@@ -2463,22 +2463,23 @@ char* SELECT (
                OSRF_BUFFER_ADD_CHAR( select_buf, '*' );
        else {
 
-               // If we need to build a default list, do so
+               // If we need to build a default list, prepare to do so
                jsonObject* _tmp = jsonObjectGetKey( selhash, core_class );
                if ( _tmp && !_tmp->size ) {
 
-                       int i = 0;
-                       char* field;
                        osrfHash* core_fields = osrfHashGet( core_meta, "fields" );
 
-               osrfStringArray* keys = osrfHashKeys( core_fields );
-                       while ( (field = osrfStringArrayGetString(keys, i++)) ) {
-                               if( ! str_is_true( osrfHashGet( osrfHashGet( core_fields, field ), "virtual" ) ) )
-                                       jsonObjectPush( _tmp, jsonNewObject( field ) );   // not virtual; use it
-               }
-                       osrfStringArrayFree(keys);
+                       osrfHashIterator* field_itr = osrfNewHashIterator( core_fields );
+                       osrfHash* field_def;
+                       while( ( field_def = osrfHashIteratorNext( field_itr ) ) ) {
+                               if( ! str_is_true( osrfHashGet( field_def, "virtual" ) ) ) {
+                                       // This field is not virtual, so add it to the list
+                                       jsonObjectPush( _tmp, jsonNewObject( osrfHashIteratorKey( field_itr ) ) );
+                               }
+                       }
+                       osrfHashIteratorFree( field_itr );
                }
-       
+
                // Now build the actual select list
            int sel_pos = 1;
            jsonObject* is_agg = jsonObjectFindPath(selhash, "//aggregate");