Re: GNOME CVS: glib jgarzik



In <URL:news:local.gtk> on Sun 24 Jan, Jeff Garzik wrote:
> On Sun, 24 Jan 1999, Tor Lillqvist wrote:
> > Gnome CVS User writes:
> >  > - Replaced "if (!hash_node) return;" with
> >  > "if (hash_node) {do stuff}".
> >  > Testing takes up less code space than explicit call to
> >  > 'return' before end of function.  (look at gcc -S)
> > 
> > Hmm, is it worth it to sacrifice code clarity (presumably) for a
> > alleged gain of some nanoseconds with one compiler, on one
> > architecture?
> 
> 
> IMHO clarity wasn't sacrificed.  And AFAIK all the asm dumps on x86,
> SPARC, and Alpha are shorter when using a cmp/near-jump combo than when
> using multiple return statements.  I've only timed it to be [slightly]
> faster on x86, not yet on Alpha and SPARC.
> 
> 	Jeff
> 

It majorly sacrifices clarity when it happens more than once, as the
rest of the function ends up nested inside purposeless extra levels,
and so its NASTY even when it only happens once.

Think of exception handling - the return is like an early exit
from the function disposing of a case that has been handled - we
don't want to have to think of it ever again, especially not
when some maintainer puts code outside that extra {}.

Its slower on my architecture (arm) where return is always just one
(conditional) instruction. (A well designed modern RISC processor)

Surely any compiler worth its salt will be capable of reversing
the jump order to suit its architecture anyway, and/or unifying
all the function return sequence.

Please don't do this sort of thing.

-- 
Brian_Brunswick__bdb@eidos.co.uk____Wit___Disclaimer___!Shortsig!



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]