From 653858c72cbafd1055ff8b34ac5625124a00fef5 Mon Sep 17 00:00:00 2001 From: scottmk Date: Tue, 16 Mar 2010 04:41:04 +0000 Subject: [PATCH] A small performance tweak. When we receive a new message, we update current_locale with the locale of the message. The tweak: if current_locale is already the same as the locale of the message (which is presumably most of the time in practice), then don't update it. That way we avoid a malloc() and a free(). M src/libopensrf/osrf_message.c git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@1937 9efc2488-bf62-4759-914b-345cdb29e865 --- src/libopensrf/osrf_message.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/libopensrf/osrf_message.c b/src/libopensrf/osrf_message.c index a316c1c..b598ad3 100644 --- a/src/libopensrf/osrf_message.c +++ b/src/libopensrf/osrf_message.c @@ -11,6 +11,7 @@ #include #include +#include "opensrf/osrf_stack.h" static jsonObject* osrfMessageToJSON( const osrfMessage* msg ); static osrfMessage* deserialize_one_message( const jsonObject* message ); @@ -588,15 +589,22 @@ static osrfMessage* deserialize_one_message( const jsonObject* obj ) { // Now that we have the essentials, create an osrfMessage osrfMessage* msg = osrf_message_init( type, trace, protocol ); - // Get the sender's locale, or leave it NULL if not specified. - if ( current_locale ) - free( current_locale ); - + // Update current_locale with the locale of the message + // (or set it to NULL if not specified) tmp = jsonObjectGetKeyConst( obj, "locale" ); if(tmp && ( msg->sender_locale = jsonObjectToSimpleString(tmp))) { - current_locale = strdup( msg->sender_locale ); + if ( current_locale ) { + if( strcmp( current_locale, msg->sender_locale ) ) { + free( current_locale ); + current_locale = strdup( msg->sender_locale ); + } // else they're the same already, so don't replace one with the other + } else + current_locale = strdup( msg->sender_locale ); } else { - current_locale = NULL; + if ( current_locale ) { + free( current_locale ); + current_locale = NULL; + } } tmp = jsonObjectGetKeyConst( obj, "payload" ); -- 2.11.0