for versus foreach

kris foo at bar.com
Sat Apr 8 14:56:26 PDT 2006


John Demme wrote:
> kris wrote:
> 
>>With the x86-32 architecture, anything that prevents register-spills is
>>a bonus for some types of code, and I found foreach to be a better
>>choice in a number of cases. The potentially negative aspect is that
>>foreach is based upon a callback mechanism, so if the loop-body cannot
>>be "inlined" there will be a call/ret involved for each iteration.
>>Whether or not that's significant is very much application specific.
>>
> 
> 
> I don't think foreach can ever be inlined in the operator overloading case
> since opApply takes a delegate.  DMD might be smarter than I though;
> however, I've refactored delegate parameters into templated code for the
> sole purpose of allowing functions to be inlined.
> 
> ~John Demme

Hmmm; I've almost forgotton the circumstances where I was seeing the 
call/ret being excised away ... ah, yes ~ it's when the foreach is used 
with native types (e.g. mango.convert.Unicode). Thus, there wasn't a 
call/ret present to begin with. Thanks for the prodding.



More information about the Digitalmars-d-learn mailing list