Avoid dynamic_cast in critcal path code.