3 ms·
The problem with rolling your own virtual tables without compiler support is that devirtualization is generally not possible, even in fairly easy cases.
by o11c 3y ago
The problem with rolling your own virtual tables without compiler support is that devirtualization is generally not possible, even in fairly easy cases.
- Dwedit 3y agoIf by "devirtualization" you mean inlining the virtual method and associated optimizations, that can be done with If-else (checking which vtable it is), then explicitly calling the function. Failure to find a known method can proceed to calling the function pointer.
- o11c 3y agoSpeculative or unconditional devirtualization are reasonable things to do if you are the compiler. Writing code by hand, it's quite unwieldy, since the compiler doesn't know that a `FinalFooFrobber` always contains has its vtable set to `FrobberVtable foo_vtable`, which often appears only after inlining. Asking C programmers to do inlining by hand is not sane. This isn't like interpreted languages where inlining sucks - here, the compiler is quite capable of it, just the vtable stuff confuses it.