[Opensrf-commits] r1937 - trunk/src/libopensrf (scottmk)
svn at svn.open-ils.org
svn at svn.open-ils.org
Tue Mar 16 00:41:07 EDT 2010
Author: scottmk
Date: 2010-03-16 00:41:04 -0400 (Tue, 16 Mar 2010)
New Revision: 1937
Modified:
trunk/src/libopensrf/osrf_message.c
Log:
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
Modified: trunk/src/libopensrf/osrf_message.c
===================================================================
--- trunk/src/libopensrf/osrf_message.c 2010-03-12 17:06:56 UTC (rev 1936)
+++ trunk/src/libopensrf/osrf_message.c 2010-03-16 04:41:04 UTC (rev 1937)
@@ -11,6 +11,7 @@
#include <libxml/tree.h>
#include <opensrf/osrf_message.h>
+#include "opensrf/osrf_stack.h"
static jsonObject* osrfMessageToJSON( const osrfMessage* msg );
static osrfMessage* deserialize_one_message( const jsonObject* message );
@@ -588,15 +589,22 @@
// 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" );
More information about the opensrf-commits
mailing list