inlining a generic lookup-table lazarus / 62-General ---------------------------------------------------------------------- yogo1212 · 2014-05-12 11:08 Hi, im trying to do this weird thing to optimise my code. Having to do a lookup-table everywhere you want you want one can be really annoying... That's why i am trying to insert a level of abstraction; which is potentially slower, but still better than losing hundreds of cycles with a pipeline flush. My current idea is: Code: [Select]// ok... trying to make sure the inlined code is being optimised... // not sure how inlining is implemented {$OPTIMIZATION ON} // inline for less stack-frames. procedure genericLookup(second: Boolean; a,b: TObjProc); inline; procedure genericLookup(really: Boolean; a: TObjProc); inline; overload; {$OPTIMIZATION DEFAULT} implementation {$OPTIMIZATION ON} // Is this crap? procedure genericLookup(second: Boolean; a, b: TObjProc); // cant make this a global variable because not thread-safe. :-( // where does it land anyway? register? that makes the lookup really weird. // Hope it's not on the stack... var genericBinaryLookupTable: Array[Boolean] of TObjProc; begin   genericBinaryLookupTable[False] := a;   genericBinaryLookupTable[True] := b;   genericBinaryLookupTable[second](); end; procedure genericLookup(really: Boolean; a: TObjProc); var genericSingularLookupTable: Array[Boolean] of TObjProc; begin   PPointer(@genericSingularLookupTable[False])^ := Pointer(@DoNothing);   genericSingularLookupTable[True] := a;   genericSingularLookupTable[really](); end; {$OPTIMIZATION DEFAULT} Is this bogus? If so, why? Any ideas how to improve? kind regards EDIT: Is there a guide about writing code that helps make use of optimisation?