What is the purpose of dyn_cast<> in include/core/typeinfo.h? Why don't we just
use dynamic_cast<>? And can we either replace the former with the latter, or
add a comment to the former explaining its purpose?
Looks like an optimization for speed, but has anyone actually profiled and
found dynamic_cast to be a bottleneck? It's not exactly heavy.
/**
* Function dyn_cast()
*
* A lightweight dynamic downcast. Casts aObject to type Casted*.
* Uses EDA_ITEM::Type() and EDA_ITEM::ClassOf() to check if type matches.
* @param aObject object to be casted
* @return down-casted object or NULL if type doesn't match Casted.
*/
template<class Casted, class From>
Casted dyn_cast( From aObject )
{
if( remove_pointer<Casted>::type::ClassOf ( aObject ) )
return static_cast<Casted>( aObject );
return NULL;
}
--
Chris
_______________________________________________
Mailing list: https://launchpad.net/~kicad-developers
Post to : [email protected]
Unsubscribe : https://launchpad.net/~kicad-developers
More help : https://help.launchpad.net/ListHelp