[techtalk] switch function in C (or how to read commandline args?)

jenn at simegen.com jenn at simegen.com
Tue Jul 3 08:02:53 EST 2001


Conor Daly wrote:


>> If it really is performance critical to switch on strings, it's fairly likely 
>> that it's because you're having to continuously switch on the same strings.  
>> In that case, converting the strings to tokens once and switching on the 
>> tokens is probably a decent way to go.
> 
> Now that's interesting.  So how do I tokenise the strings?

Well, when I had to do that, I created a Java class (because I 
was working in Java) which consisted of a whole lot of constants.

So FieldCodes.FOO might equal 1; FieldCodes.BAR, 2. FieldCodes.BAZ, 3.


I then replaced every sent parameter which -previously- would have
sent one of the strings with the equivalent constant. And every check
on them with the equivalent constant, as well.

Muuuuuuch more efficient, and equally human-readable.



Jenn V.
-- 
     "Do you ever wonder if there's a whole section of geek culture
             you miss out on by being a geek?" - Dancer.

jenn at simegen.com     Jenn Vesperman     http://www.simegen.com/~jenn/





More information about the Techtalk mailing list