From 96d674f6dd1960431464cabb618290c7ad58eeab Mon Sep 17 00:00:00 2001 From: scottmk Date: Wed, 5 Aug 2009 18:58:20 +0000 Subject: [PATCH] In oils_cstore.c, function searchWHERE(): rewrote a loop to use an 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 | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Open-ILS/src/c-apps/oils_cstore.c b/Open-ILS/src/c-apps/oils_cstore.c index 05faa91dd2..848c85f762 100644 --- a/Open-ILS/src/c-apps/oils_cstore.c +++ b/Open-ILS/src/c-apps/oils_cstore.c @@ -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); -- 2.11.0