From the nimble fingers of Edwards, Waverly (Waverly.Edwards@...) (23/4/02 6:44 PM) came... > I have the need for speed. Does anyone have a > better idea for a jump table to replace a SELECT/CASE > structure? > > What I would like to do is to jump to a certain section > based on the contents of a string. The string will be one > to four characters in length, all capitals. > > What I am doing now is easy and flexible but > I think there may be a faster, less flexible way to do > the same thing. Ultimately, I want to see if I can gain > enough speed to warrant some ugly inflexible code. > > This is what I do now. > > SELECT myString$ > CASE "BD" > // do this ... > CASE "LI" > // do this ... > CASE "SIMM" > // do this ... > CASE "XY" > // do this ... > CASE "D" > // do this ... > .... > .... > .... > // THERE ARE ABOUT 40 CASE STATEMENTS > // ORDERED BY FREQUENCY FOR SPEED. In assembly in a small microcomputer, I'd set up a series of tables: Btable fcc abcdefg ... Ctable fcc abcdefg... ... Xtable fcc abcdefg... ... Then load the first character into an index register (a pointer) and hop to the right table. Load the 2nd character into the same index reg and hop to the proper entry in the proper (already selected) table. The offset from the start of that table would be loaded into that same index register and hop to another table which holds the start address of the appropriate routine. Do this until all of the possibilities are unambiguously decoded; there might be a total of 4 jumps which would be quite fast. How to do that in FB is another matter... -- Ted Spencer; tedspencer@... -- On a cellular level, I'm really quite busy.