[PATCH] hdparm new option parsing

Rob Landley rob at landley.net
Mon May 8 15:36:57 UTC 2006


On Monday 08 May 2006 7:53 am, Tito wrote:
> Seems yes if you think of a switch statement as
>
> if(a == 1)
>
> else if(a == 2)
>
> else if(a == n)
>
> else {
> 	/* do the default */
> }
>
> This way you have only one if in the body of the function replacing some 30
> of them.

And to compensate for that you have an extra parameter to each function you 
call.  Is testing the value with an if() cheaper than pushing it onto the 
stack as an extra parameter to the function?  (I don't know, but function 
parameters aren't free.  You've got the comparison anyway, and performing the 
comparison already sets the processor flag that the test instruction would 
test...)

Rob
-- 
Never bet against the cheap plastic solution.



More information about the busybox mailing list