[open-ils-commits] r11984 - trunk/Open-ILS/src/c-apps

svn at svn.open-ils.org svn at svn.open-ils.org
Mon Jan 26 15:56:37 EST 2009


Author: scottmk
Date: 2009-01-26 15:56:33 -0500 (Mon, 26 Jan 2009)
New Revision: 11984

Modified:
   trunk/Open-ILS/src/c-apps/oils_idl-core.c
Log:
Eliminated all calls to oilsIDLFindPath() in this file.

This change eliminates the overhead of parsing path
strings, including the malloc and free that such
parsing entails.

In addition: in most cases we had been calling
oilsIDLFindPath() twice, once to verify that the class
existed, and again to find whatever piece of it we
wanted.  This duplication of effort is now gone.
-This line, and those below, will be ignored--

M    Open-ILS/src/c-apps/oils_idl-core.c


Modified: trunk/Open-ILS/src/c-apps/oils_idl-core.c
===================================================================
--- trunk/Open-ILS/src/c-apps/oils_idl-core.c	2009-01-26 20:43:41 UTC (rev 11983)
+++ trunk/Open-ILS/src/c-apps/oils_idl-core.c	2009-01-26 20:56:33 UTC (rev 11984)
@@ -418,40 +418,61 @@
 	return obj;
 }
 
+static osrfHash* findClassDef( const char* classname ) {
+	if( !classname || !idlHash )
+		return NULL;
+	else
+		return osrfHashGet( idlHash, classname );
+}
+
 int oilsIDL_classIsFieldmapper ( const char* classname ) {
-	if (!classname) return 0;
-	if(oilsIDLFindPath( "/%s", classname )) return 1;
-	return 0;
+	if( findClassDef( classname ) )
+		return 1;
+	else
+		return 0;
 }
 
 int oilsIDL_ntop (const char* classname, const char* fieldname) {
-	osrfHash* _pos = NULL;
+	osrfHash* class_def_hash = findClassDef( classname );
+	if( !class_def_hash )
+		return -1;			// No such class
+	
+	osrfHash* fields_hash = osrfHashGet( class_def_hash, "fields" );
+	if( !fields_hash )
+		return -1;			// No list of fields fo the class
 
-	if (!oilsIDL_classIsFieldmapper(classname)) return -1;
-	_pos = oilsIDLFindPath( "/%s/fields/%s", classname, fieldname );
-	if (_pos) return atoi( osrfHashGet(_pos, "array_position") );
-	return -1;
+	osrfHash* field_def_hash = osrfHashGet( fields_hash, fieldname );
+	if( !field_def_hash )
+		return -1;			// No such field
+
+	const char* pos_attr = osrfHashGet( field_def_hash, "array_position" );
+	if( !pos_attr )
+		return -1;			// No array_position attribute
+
+	return atoi( pos_attr );	// Return position as int
 }
 
 char * oilsIDL_pton (const char* classname, int pos) {
+	osrfHash* class_def_hash = findClassDef( classname );
+	if( !class_def_hash )
+		return NULL;		// No such class
+	
+	osrfHash* fields_hash = osrfHashGet( class_def_hash, "fields" );
+	if( !fields_hash )
+		return NULL;		// No list of fields fo the class
+
 	char* ret = NULL;
-	osrfHash* f = NULL;
-	osrfHash* fields = NULL;
-	osrfHashIterator* itr = NULL;
+	osrfHash* field_def_hash = NULL;
+	osrfHashIterator* iter = osrfNewHashIterator( fields_hash );
 
-	if (!oilsIDL_classIsFieldmapper(classname)) return NULL;
-
-	fields = oilsIDLFindPath( "/%s/fields", classname );
-	itr = osrfNewHashIterator( fields );
-
-	while ( (f = osrfHashIteratorNext( itr )) ) {
-		if ( atoi(osrfHashGet(f, "array_position")) == pos ) {
-			ret = strdup(osrfHashIteratorKey(itr));
+	while ( ( field_def_hash = osrfHashIteratorNext( iter ) ) ) {
+		if ( atoi( osrfHashGet( field_def_hash, "array_position" ) ) == pos ) {
+			ret = strdup( osrfHashIteratorKey( iter ) );
 			break;
 		}
 	}
 
-	osrfHashIteratorFree( itr );
+	osrfHashIteratorFree( iter );
 
 	return ret;
 }



More information about the open-ils-commits mailing list