Re: to be effcient or not to be efficient
Tuukka Toivonen <[email protected]>
| Newsgroups | gmane.comp.multimedia.media-api |
|---|---|
| Message-ID | <Pine.GSO.4.58.0401072005040.13044@stekt37> |
On Wed, 7 Jan 2004, Toby Hudon wrote: >Then I'd like to hear it, because my last CS professor's idea of >"efficient" switch handling was replacing a 22 case switch with a system >where you have a class with a pure virtual function and then inherit from >it for 22 subclasses, then in each subclass implement the virtual function >which the orignial function call calls in place of the switch, so that The same in couple of words: a pointer to a function. C++ can do it automatically, but it's easy to do it in C manually too. Actually I'm surprised if an optimizing C compiler can't do it automatically from a switch statement, accessing a table of pointers to functions after bounds checking. Just like linux system calls are handled.