You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4cxx-dev@logging.apache.org by mc...@apache.org on 2004/04/02 10:42:39 UTC

cvs commit: logging-log4cxx/src loggingevent.cpp

mcatan      2004/04/02 00:42:39

  Modified:    include/log4cxx/spi loggingevent.h
               src      loggingevent.cpp
  Log:
  optimization
  
  Revision  Changes    Path
  1.13      +3 -1      logging-log4cxx/include/log4cxx/spi/loggingevent.h
  
  Index: loggingevent.h
  ===================================================================
  RCS file: /home/cvs/logging-log4cxx/include/log4cxx/spi/loggingevent.h,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- loggingevent.h	4 Feb 2004 01:11:17 -0000	1.12
  +++ loggingevent.h	2 Apr 2004 08:42:39 -0000	1.13
  @@ -86,6 +86,8 @@
   				const LevelPtr& level,	const String& message,
   				const char* file=0, int line=-1);
   
  +			~LoggingEvent();
  +
   			/** Return the #level of this event. */
   			inline const LevelPtr& getLevel() const
   				{ return level; }
  @@ -216,7 +218,7 @@
   			/**
   			* A map of String keys and String values.
   			*/
  -			std::map<String, String> properties;
  +			std::map<String, String> * properties;
   
   			/** Have we tried to do an NDC lookup? If we did, there is no need
   			*  to do it again.  Note that its value is always false when
  
  
  
  1.12      +41 -14    logging-log4cxx/src/loggingevent.cpp
  
  Index: loggingevent.cpp
  ===================================================================
  RCS file: /home/cvs/logging-log4cxx/src/loggingevent.cpp,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- loggingevent.cpp	4 Feb 2004 00:37:58 -0000	1.11
  +++ loggingevent.cpp	2 Apr 2004 08:42:39 -0000	1.12
  @@ -37,7 +37,7 @@
   
   LoggingEvent::LoggingEvent()
   : timeStamp(0), ndcLookupRequired(true), line(0),
  -mdcCopyLookupRequired(true)
  +mdcCopyLookupRequired(true), properties(0)
   {
   }
   
  @@ -47,11 +47,19 @@
   : fqnOfCategoryClass(fqnOfCategoryClass), logger(logger), level(level),
   message(message), file((char*)file), line(line),
   timeStamp(System::currentTimeMillis()), ndcLookupRequired(true),
  -mdcCopyLookupRequired(true)
  +mdcCopyLookupRequired(true), properties(0)
   {
   	threadId = Thread::getCurrentThreadId();
   }
   
  +LoggingEvent::~LoggingEvent()
  +{
  +	if (properties != 0)
  +	{
  +		delete properties;
  +	}
  +}
  +
   const String& LoggingEvent::getLoggerName() const
   { 
   	return logger->getName();
  @@ -130,9 +138,14 @@
   
   String LoggingEvent::getProperty(const String& key) const
   {
  -	std::map<String, String>::const_iterator  it = properties.find(key);
  +	if (properties == 0)
  +	{
  +		return String();
  +	}
   
  -	if (it != properties.end())
  +	std::map<String, String>::const_iterator  it = properties->find(key);
  +
  +	if (it != properties->end())
   	{
   		const String& p = it->second;
   
  @@ -148,10 +161,14 @@
   std::set<String> LoggingEvent::getPropertyKeySet() const
   {
   	std::set<String> set;
  -	std::map<String, String>::const_iterator it;
  -	for (it = properties.begin(); it != properties.end(); it++)
  +
  +	if (properties != 0)
   	{
  -		set.insert(it->first);
  +		std::map<String, String>::const_iterator it;
  +		for (it = properties->begin(); it != properties->end(); it++)
  +		{
  +			set.insert(it->first);
  +		}
   	}
   
   	return set;
  @@ -212,7 +229,7 @@
   	{
   		is->read(key);
   		is->read(value);
  -		properties[key] = value;
  +		setProperty(key, value);
   	}
   
   	// threadId
  @@ -253,7 +270,12 @@
   
   void LoggingEvent::setProperty(const String& key, const String& value)
   {
  -	properties[key] = value;
  +	if (properties == 0)
  +	{
  +		properties = new std::map<String, String>;
  +	}
  +
  +	(*properties)[key] = value;
   }
   
   void LoggingEvent::write(helpers::SocketOutputStreamPtr& os) const
  @@ -299,12 +321,17 @@
   	}
   
   	// properties
  -	os->write((int)properties.size());
  -	std::map<String, String>::const_iterator it2;
  -	for (it2 = properties.begin(); it2 != properties.end(); it2++)
  +	int size = (properties != 0) ? (int)properties->size() : 0;
  +	os->write(size);
  +
  +	if (size > 0)
   	{
  -		os->write(it2->first);
  -		os->write(it2->second);
  +		std::map<String, String>::const_iterator it;
  +		for (it = properties->begin(); it != properties->end(); it++)
  +		{
  +			os->write(it->first);
  +			os->write(it->second);
  +		}
   	}
   
   	// threadId