> -----Original Message----- > From: Ron Grabowski [mailto:[EMAIL PROTECTED] > Sent: 14 October 2006 19:11 > To: [email protected] > Subject: Set Logger's Level to its EffectiveLevel to avoid for() loop > > I noticed that the logger's Level isn't checked before its > EffectiveLevel. Shouldn't this code: > > return level >= this.EffectiveLevel; > > be changed to this: > > if (m_level != null) > { > return level >= m_level; > } > else > { > return level >= this.EffectiveLevel; > } > > in log4net.Repository.Hierarchy.Logger? > > I'll keep hacking at it... >
This is really just unrolling the first loop from the EffectiveLevel property. Doing this check in the IsEnabledFor method would speed up the case where the logger has a level set, however this is actually not the common case, typically the level will be set somewhere in the parent chain of the logger. Adding this check would add an additional test in the common case (when m_level is null). I guess that this is something that should be performance benchmarked before we do it, although the cost of the virtual method call may be so great that the additional test and branch is insignificant. It would also be possible to unroll the first iteration of the for loop in the EffectiveLevel property. The first time round the loop it checks the level on 'this'. It does a check to see if this is null, we know that for the first iteration this (c) must be not null so we could avoid one test if we did the tests on this outside the for loop and only used the for loop for the parents. Again this is something that we need to benchmark before we do it. Nicko
