You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-dev@logging.apache.org by ni...@apache.org on 2004/06/02 18:25:33 UTC

cvs commit: logging-log4net/src/Util CyclicBuffer.cs

nicko       2004/06/02 09:25:33

  Modified:    src/Util CyclicBuffer.cs
  Log:
  Simplified CyclicBuffer.Append method signature. Now just returns the discarded event (if any) rather than having bools and out params
  
  Revision  Changes    Path
  1.5       +14 -7     logging-log4net/src/Util/CyclicBuffer.cs
  
  Index: CyclicBuffer.cs
  ===================================================================
  RCS file: /home/cvs/logging-log4net/src/Util/CyclicBuffer.cs,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- CyclicBuffer.cs	30 May 2004 10:50:43 -0000	1.4
  +++ CyclicBuffer.cs	2 Jun 2004 16:25:33 -0000	1.5
  @@ -58,20 +58,18 @@
   		/// Appends a <paramref name="loggingEvent"/> to the buffer.
   		/// </summary>
   		/// <param name="loggingEvent">The event to append to the buffer.</param>
  -		/// <param name="discardedLoggingEvent">The event discarded from the buffer, if any.</param>
  -		/// <returns><c>true</c> if the buffer is not full, otherwise <c>false</c>.</returns>
  -		public bool Append(LoggingEvent loggingEvent, out LoggingEvent discardedLoggingEvent) 
  +		/// <returns>The event discarded from the buffer, if the buffer is full, otherwise <c>null</c>.</returns>
  +		public LoggingEvent Append(LoggingEvent loggingEvent)
   		{	
  -			discardedLoggingEvent = null;
  -
   			if (loggingEvent == null)
   			{
   				throw new ArgumentNullException("loggingEvent");
   			}
  +
   			lock(this)
   			{
   				// save the discarded event
  -				discardedLoggingEvent = m_events[m_last];
  +				LoggingEvent discardedLoggingEvent = m_events[m_last];
   
   				// overwrite the last event position
   				m_events[m_last] = loggingEvent;	
  @@ -89,7 +87,16 @@
   					m_first = 0;
   				}
   
  -				return (m_numElems < m_maxSize);
  +				if (m_numElems < m_maxSize)
  +				{
  +					// Space remaining
  +					return null;
  +				}
  +				else
  +				{
  +					// Buffer is full and discarding an event
  +					return discardedLoggingEvent;
  +				}
   			}
   		}