Forum in repository mode. No new members allowed.
Started by Theo Gottwald, March 01, 2008, 09:27:41 PM
0 Members and 1 Guest are viewing this topic.
' Creating a virtual jump table for extreme constants#COMPILE EXE#DIM ALLFUNCTION PBMAIN () AS LONG LOCAL i,j,vtable,which AS LONG DIM t(1e5) AS LONG vtable=VARPTR(t(0)) j=CODEPTR(xit) ' default location FOR i=0 TO 1e5:t(i)=j:NEXT t(01024)=CODEPTR(aa) ' case constant t(42935)=CODEPTR(bb) ' case constant t(99900)=CODEPTR(cc) ' case constant '... ' select case as const which=42935 'example ! mov eax,which ! shl eax,2 ! add eax,vtable ! jmp dword ptr [eax] aa: 'case MSGBOX "AA": GOTO xit bb: 'case MSGBOX "BB": GOTO xit cc: MSGBOX "CC": GOTO xit xit: ' end selectEND FUNCTION
QuoteA structure with 20,000 CASE's executes in the same elapsed time as one with 2 CASE's
Quote from: Theo Gottwald on March 05, 2008, 09:25:41 PMBob, if you read this, maybe you can clarify one thing for me, that noone else can.In my tests, it showed - exctly as you said - that SELECT CASE AS CONST is good, for a large number of choices, as it does not need to go through all those needless comparison but jumps directly where it should.
Page created in 0.315 seconds with 22 queries.