← Back to team overview

kicad-developers team mailing list archive

Re: Edit text and graphic properties behavior


Hi Jeff,

On 10/17/2018 12:01 AM, Jeff Young wrote:

> I think one of the original justifications of dyn_cast<> was that it was faster.  Do I have that wrong, or do we not believe it to be material?

It probably is faster, as comparing values can be inlined, while
dynamic_cast<> cannot. Whether it has a measurable impact I can't really
tell. What's interesting is that neither gcc nor msvc can cache results
of type checks with either system (where I would have expected
dynamic_cast<> to come out ahead as the type of an object is generally
fairly immutable).

Compiler Explorer link: https://godbolt.org/z/HwKrp6

> (Other than that I’d love to get rid of it.  It’s bitten me more than once.)

We also have a (large) number of instances where people have
reimplemented dyn_cast<> by checking the Type() and using static_cast<>,
reinterpret_cast<> or a C-style cast afterwards.

FWIW, I'd rather store everything in typed containers and have no
polymorphism at all, that would probably give the best speedup of all,
because we don't even need to look at objects we don't care about.