nicko       2005/01/28 12:51:06

  Modified:    src/Util AppenderAttachedImpl.cs
  Log:
  Cache the appenders list in an array for performance
  
  Revision  Changes    Path
  1.5       +22 -4     logging-log4net/src/Util/AppenderAttachedImpl.cs
  
  Index: AppenderAttachedImpl.cs
  ===================================================================
  RCS file: /home/cvs/logging-log4net/src/Util/AppenderAttachedImpl.cs,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- AppenderAttachedImpl.cs   17 Jan 2005 20:18:47 -0000      1.4
  +++ AppenderAttachedImpl.cs   28 Jan 2005 20:51:06 -0000      1.5
  @@ -55,12 +55,19 @@
                        {
                                throw new ArgumentNullException("loggingEvent");
                        }
  +
  +                     // m_appenderList is null when empty
                        if (m_appenderList == null) 
                        {
                                return 0;
                        }
   
  -                     foreach(IAppender appender in m_appenderList)
  +                     if (m_appenderArray == null)
  +                     {
  +                             m_appenderArray = m_appenderList.ToArray();
  +                     }
  +
  +                     foreach(IAppender appender in m_appenderArray)
                        {
                                try
                                {
  @@ -93,6 +100,7 @@
                                throw new ArgumentNullException("newAppender");
                        }
        
  +                     m_appenderArray = null;
                        if (m_appenderList == null) 
                        {
                                m_appenderList = new AppenderCollection(1);
  @@ -121,7 +129,7 @@
                                }
                                else 
                                {
  -                                     return m_appenderList;
  +                                     return 
AppenderCollection.ReadOnly(m_appenderList);
                                }
                        }
                }
  @@ -170,8 +178,8 @@
                                                
LogLog.Error("AppenderAttachedImpl: Failed to Close appender 
["+appender.Name+"]", ex);
                                        }
                                }
  -                             m_appenderList.Clear();
                                m_appenderList = null;    
  +                             m_appenderArray = null;
                        }
                }
   
  @@ -190,6 +198,11 @@
                        if (appender != null && m_appenderList != null) 
                        {
                                m_appenderList.Remove(appender);
  +                             if (m_appenderList.Count == 0)
  +                             {
  +                                     m_appenderList = null;
  +                             }
  +                             m_appenderArray = null;
                        }
                        return appender;
                }
  @@ -214,10 +227,15 @@
                #region Private Instance Fields
   
                /// <summary>
  -             /// Array of appenders
  +             /// List of appenders
                /// </summary>
                private AppenderCollection m_appenderList;
   
  +             /// <summary>
  +             /// Array of appenders, used to cache the m_appenderList
  +             /// </summary>
  +             private IAppender[] m_appenderArray;
  +
                #endregion Private Instance Fields
        }
   }
  
  
  

Reply via email to