In oils_cstore.c, function searchWHERE(): rewrote a loop to use an
authorscottmk <scottmk@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 5 Aug 2009 18:58:20 +0000 (18:58 +0000)
committerscottmk <scottmk@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 5 Aug 2009 18:58:20 +0000 (18:58 +0000)
index instead of a jsonIterator, to traverse a jsonObject that is
known to be a JSON_ARRAY.  This change avoids the malloc and
free required to create and destroy a jsonIterator.

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

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

index 05faa91..848c85f 100644 (file)
@@ -2550,19 +2550,18 @@ static char* searchWHERE ( const jsonObject* search_hash, const ClassInfo* class
        int first = 1;
        if ( search_hash->type == JSON_ARRAY ) {
                osrfLogDebug(OSRF_LOG_MARK, "%s: In WHERE clause, condition type is JSON_ARRAY", MODULENAME);
-               jsonIterator* search_itr = jsonNewIterator( search_hash );
-               if( !jsonIteratorHasNext( search_itr ) ) {
+               if( 0 == search_hash->size ) {
                        osrfLogError(
                                OSRF_LOG_MARK,
                                "%s: Invalid predicate structure: empty JSON array",
                                MODULENAME
                        );
-                       jsonIteratorFree( search_itr );
                        buffer_free( sql_buf );
                        return NULL;
                }
 
-               while ( (node = jsonIteratorNext( search_itr )) ) {
+               unsigned long i = 0;
+               while((node = jsonObjectGetIndex( search_hash, i++ ) )) {
                        if (first) {
                                first = 0;
                        } else {
@@ -2574,7 +2573,6 @@ static char* searchWHERE ( const jsonObject* search_hash, const ClassInfo* class
 
                        char* subpred = searchWHERE( node, class_info, opjoin_type, ctx );
                        if( ! subpred ) {
-                               jsonIteratorFree( search_itr );
                                buffer_free( sql_buf );
                                return NULL;
                        }
@@ -2582,7 +2580,6 @@ static char* searchWHERE ( const jsonObject* search_hash, const ClassInfo* class
                        buffer_fadd(sql_buf, "( %s )", subpred);
                        free(subpred);
                }
-               jsonIteratorFree(search_itr);
 
        } else if ( search_hash->type == JSON_HASH ) {
                osrfLogDebug(OSRF_LOG_MARK, "%s: In WHERE clause, condition type is JSON_HASH", MODULENAME);