logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Benedict <pbened...@apache.org>
Subject Re: No for each loop comment?
Date Thu, 25 Sep 2014 15:51:01 GMT
I would be surprised if foreach over an array makes a speed difference.
AFAIK, foreach is synatic sugar. There is no iterator for an array so it
has to be desugared using a for/index loop like you have there. I don't
think this code is saving anything.


Cheers,
Paul

On Thu, Sep 25, 2014 at 10:47 AM, Remko Popma <remko.popma@gmail.com> wrote:

> Hm.. Why did I think it was configuration? I must have gotten mixed up
> with another commit email...
> The class is MarkerManager in log4j-api.
>
> On Fri, Sep 26, 2014 at 12:18 AM, Ralph Goers <ralph.goers@dslextreme.com>
> wrote:
>
>> Configuration?  If I recall correctly this method is called on every log
>> event that contains a Marker.  But I am just guessing since Gary neglected
>> to say what class this is.  But I do remember doing extensive testing when
>> this code was written.  And I also remember someone (probably Gary)
>> mentioning then that it should use a for-loop and we had this same
>> conversation then.  I think that is why the comment was added.
>>
>> Ralph
>>
>> On Sep 24, 2014, at 9:10 PM, Remko Popma <remko.popma@gmail.com> wrote:
>>
>>
>> On 2014/09/25, at 12:46, Matt Sicker <boards@gmail.com> wrote:
>>
>> From what I remember, it had something to do with the incredibly large
>> difference in speed between for loops and foreach loops on arrays. And by
>> incredibly large, I mean most likely negligible.
>>
>> :-)
>> I do remember reading that someone found a speed difference. But I've
>> never verified it. (Note to self: write a quick jmh benchmark for this.)
>>
>> On the other hand, this is configuration, so it only happens once and is
>> very unlikely to be "hot" code so there is probably not much value in
>> optimizing this loop.
>>
>>
>> On 24 September 2014 22:12, Gary Gregory <garydgregory@gmail.com> wrote:
>>
>>> Why does this "//noinspection ForLoopReplaceableByForEach" comment mean?
>>>
>>> Why not for an enhanced for each loop?
>>>
>>>  private static boolean contains(final Marker parent, final Marker...
>>> localParents) {
>>>             //noinspection ForLoopReplaceableByForEach
>>>             for (int i = 0, localParentsLength = localParents.length; i
>>> < localParentsLength; i++) {
>>>                 final Marker marker = localParents[i];
>>>                 if (marker == parent) {
>>>                     return true;
>>>                 }
>>>             }
>>>             return false;
>>>         }
>>>
>>> Thanks,
>>> Gary
>>>
>>> --
>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>>> Java Persistence with Hibernate, Second Edition
>>> <http://www.manning.com/bauer3/>
>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>>> Spring Batch in Action <http://www.manning.com/templier/>
>>> Blog: http://garygregory.wordpress.com
>>> Home: http://garygregory.com/
>>> Tweet! http://twitter.com/GaryGregory
>>>
>>
>>
>>
>> --
>> Matt Sicker <boards@gmail.com>
>>
>>
>>
>

Mime
View raw message