Avoid using dynamic_pointer_cast when possible.

Refs #5246
This commit is contained in:
Gunnar Beutner 2013-12-02 09:16:46 +01:00
parent 954d2d53a2
commit 29f9117e58
4 changed files with 7 additions and 3 deletions

View File

@ -89,7 +89,7 @@ public:
{ {
DynamicObject::Ptr object = GetObject(T::GetTypeName(), name); DynamicObject::Ptr object = GetObject(T::GetTypeName(), name);
return dynamic_pointer_cast<T>(object); return static_pointer_cast<T>(object);
} }
static void DumpObjects(const String& filename, int attributeTypes = FAState); static void DumpObjects(const String& filename, int attributeTypes = FAState);

View File

@ -134,7 +134,7 @@ DynamicObject::Ptr DynamicType::CreateObject(const Dictionary::Ptr& serializedUp
Deserialize(object, serializedUpdate, FAConfig); Deserialize(object, serializedUpdate, FAConfig);
return dynamic_pointer_cast<DynamicObject>(object); return static_pointer_cast<DynamicObject>(object);
} }
boost::mutex& DynamicType::GetStaticMutex(void) boost::mutex& DynamicType::GetStaticMutex(void)

View File

@ -56,7 +56,7 @@ public:
std::vector<shared_ptr<T> > objects; std::vector<shared_ptr<T> > objects;
BOOST_FOREACH(const DynamicObject::Ptr& object, GetObjects(T::GetTypeName())) { BOOST_FOREACH(const DynamicObject::Ptr& object, GetObjects(T::GetTypeName())) {
shared_ptr<T> tobject = dynamic_pointer_cast<T>(object); shared_ptr<T> tobject = static_pointer_cast<T>(object);
ASSERT(tobject); ASSERT(tobject);

View File

@ -97,10 +97,14 @@ public:
if (IsEmpty()) if (IsEmpty())
return shared_ptr<T>(); return shared_ptr<T>();
#ifdef _DEBUG
shared_ptr<T> object = dynamic_pointer_cast<T>(boost::get<Object::Ptr>(m_Value)); shared_ptr<T> object = dynamic_pointer_cast<T>(boost::get<Object::Ptr>(m_Value));
if (!object) if (!object)
BOOST_THROW_EXCEPTION(std::bad_cast()); BOOST_THROW_EXCEPTION(std::bad_cast());
#else /* _DEBUG */
shared_ptr<T> object = static_pointer_cast<T>(boost::get<Object::Ptr>(m_Value));
#endif /* _DEBUG */
return object; return object;
} }