[fpc-pascal] CASE
Anton Tichawa
anton.tichawa at chello.at
Wed Nov 9 05:28:42 CET 2005
Paul Davidson wrote:
>
> On Nov 8, 2005, at 12:11, Peter Vreman wrote:
>
>>>
>>> # [735] case l3o3.FormType of
>>> // Select 3o3 processor
>>> lwz r2,160(r1)
>>> cmplwi cr0,r2,0
>>> beq cr0,L1051
>>> cmplwi cr0,r2,1
>>> beq cr0,L1052
>>> cmplwi cr0,r2,2
>>> beq cr0,L1053
>>> cmplwi cr0,r2,3
>>> beq cr0,L1054
>>>
>>> etc.
>>>
>>> Any hints?
>>
>>
>> Use 2.1.1
>>
>>
>> Peter
>>
>> _______________________________________________
>> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
>> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>>
>>
>
> version 2.1.1 [2005/11/08] for powerpc
> Same result, Peter :|
>
> P Davidson
> http://CoraxNetworks.com
>
> _______________________________________________
> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>
You could use an array of procedures. It's members are initialized once,
var my_table: array [0 .. 146] of procedure;
my_table[0] := @my_proc_0;
my_tyble[1] := @my_proc_1;
...
and the 'case' statement is simply replaced with
begin
..
my_table[x];
..
end;
which is fast, because it performs no compare, but loads the procedure
address from the array, indexed with x.
Anton.
More information about the fpc-pascal
mailing list