|
![](/i/fill.gif) |
In article <38a91600@news.povray.org> , Nieminen Juha
<war### [at] sarakerttunen cs tut fi> wrote:
> I don't know how the compiler handles those switch constructs, but if the
> item to be selected is an integer type, I can't think of anything but a
> bunch of if...else if...else if... structures. This, of course, is rather
> slow when there is a considerable amount of cases.
No, usually it is done by a jump table (if the case variables are close and
not distributed over the whole range of integers - a long story :-) ). You
can then have a constant time to perform the switch-case. Just thing of it
as and array of function points (not exactly the same, but close enough to
get the idea):
switch(i)
{
case 1:
// .....
break;
case 2:
// .....
break;
case 3:
// .....
break;
default:
// .....
break;
}
int (*casefunc)()[3];
if(i < 0 || i > 2)
// default
else
// case casefunc[i]()
Thorsten
____________________________________________________
Thorsten Froehlich, Duisburg, Germany
e-mail: tho### [at] trf de
Visit POV-Ray on the web: http://mac.povray.org
Post a reply to this message
|
![](/i/fill.gif) |