Re: problem using INTERFACE_BUFFER
David Relson <[email protected]> Mon, 23 Dec 2002 11:20:23 -0500
| Newsgroups | gmane.mail.eps |
|---|---|
| Message-ID | <[email protected]> |
At 12:09 PM 12/23/02, [email protected] wrote: > > > > In several places there are "if () elseif () elseif()..." sequences that > > can be nicely replaced by switches. eps.c, content.c, and encode.c are > > places where I've done this. > >Well, the question here becomes (for me at least; since this is a parser >library), >which is going to be the most efficient, or is there no difference after >the compiler interprets the code? Assuming sequential values (such as an enum generates by default), the switch statement will be a tad bit faster. With the if statements, there are multiple "compare, branch" sequences. Branching is bad for any sort of pipelined cpu. With the switch statement, there's an initial bounds check and then a branch through a transfer vector. The biggest effect is on readability because the structure of the switch and its case statements are obvious at a glance. When I see if...else...if..else.., it is necessary to read every test since there is no homogeneity requirement. With a switch, the conditional value is stated at the beginning and the values it compares against are all constants. The statement can be scanned (rather than read).