On Wednesday, 20 May 2015 at 09:49:06 UTC, Temtaime wrote:
First version isn't any slow. It's clear and can be optimized
with gdc:
http://goo.gl/Q7HKcU
Yes, and besides, if one cares about these minor performance
issues, that most likely will disappear in the pipeline if you
are a little bit careful about how you arrange your code, then
one one would be better off letting the compiler take advantage
of statically available information about size:
@always_inline
... allocate(ulong size){
if(size==0) return _my_alloc_zero();
if(is_log2_or_zero(size)) return _my_alloc_log2size(size);
return _my_alloc_nonlog2size(size);
}
So basically a version that preserves the tests that the compiler
most easily can get rid of can lead to faster code even if it in
isolation has a few extra instructions.