3 ms·
Indeed, a small integer tag seems much more vulnerable than a C++ virtual table pointer. On modern hardware, how much is the penalty for using magic numbers in
by tlb 6y ago
Indeed, a small integer tag seems much more vulnerable than a C++ virtual table pointer.
On modern hardware, how much is the penalty for using magic numbers instead of small indices? (A magic number meaning a constant like 0x85adb9ad instead of 2). The compiler can't optimize switch(it->type) using a jump table, but I suspect that branch prediction and speculation makes this optimization barely relevant.
- kevincox 6y agoA jump table isn't likely used for very small unions anyways. The biggest downside that I see is that comparing with zero is slightly cheaper if that is a common value.