[fpc-devel] Using case statement instead of VTable

Hairy Pixels genericptr at gmail.com
Tue Apr 11 07:23:42 CEST 2023

Strange question but I heard it brought up during a discussion and I was very curious what compiler people think about it.

The question is, instead of using a virtual method table would it be feasible to use a case statement on the real class type and make a dispatch routine for each method call?

For example assume “type” is the internal type of the class (where a VTable would be) and a call to “animal.DoSomething()” is called which would internally basically be this dispatch table:

 case animal.type of
   TDog: TDog(animal).DoSomething;
   TCat: TCat(animal).DoSomething;
   TMouse: TMouse(animal).DoSomething;

The reason this was brought up was because virtual methods can’t be inlined and this would allow that but I think there would be more overhead overall to have all these case statements on every virtual method call.

	Ryan Joseph

More information about the fpc-devel mailing list