From 29f9117e58b82caa3e7efcca7f59f96860c32c29 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Mon, 2 Dec 2013 09:16:46 +0100 Subject: [PATCH] Avoid using dynamic_pointer_cast when possible. Refs #5246 --- lib/base/dynamicobject.h | 2 +- lib/base/dynamictype.cpp | 2 +- lib/base/dynamictype.h | 2 +- lib/base/value.h | 4 ++++ 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/base/dynamicobject.h b/lib/base/dynamicobject.h index 1383f66f3..9c7cfacb9 100644 --- a/lib/base/dynamicobject.h +++ b/lib/base/dynamicobject.h @@ -89,7 +89,7 @@ public: { DynamicObject::Ptr object = GetObject(T::GetTypeName(), name); - return dynamic_pointer_cast(object); + return static_pointer_cast(object); } static void DumpObjects(const String& filename, int attributeTypes = FAState); diff --git a/lib/base/dynamictype.cpp b/lib/base/dynamictype.cpp index eecdc2134..1f0ad3f76 100644 --- a/lib/base/dynamictype.cpp +++ b/lib/base/dynamictype.cpp @@ -134,7 +134,7 @@ DynamicObject::Ptr DynamicType::CreateObject(const Dictionary::Ptr& serializedUp Deserialize(object, serializedUpdate, FAConfig); - return dynamic_pointer_cast(object); + return static_pointer_cast(object); } boost::mutex& DynamicType::GetStaticMutex(void) diff --git a/lib/base/dynamictype.h b/lib/base/dynamictype.h index a547652a5..4862b1e2f 100644 --- a/lib/base/dynamictype.h +++ b/lib/base/dynamictype.h @@ -56,7 +56,7 @@ public: std::vector > objects; BOOST_FOREACH(const DynamicObject::Ptr& object, GetObjects(T::GetTypeName())) { - shared_ptr tobject = dynamic_pointer_cast(object); + shared_ptr tobject = static_pointer_cast(object); ASSERT(tobject); diff --git a/lib/base/value.h b/lib/base/value.h index ecac6ee86..6c2324440 100644 --- a/lib/base/value.h +++ b/lib/base/value.h @@ -97,10 +97,14 @@ public: if (IsEmpty()) return shared_ptr(); +#ifdef _DEBUG shared_ptr object = dynamic_pointer_cast(boost::get(m_Value)); if (!object) BOOST_THROW_EXCEPTION(std::bad_cast()); +#else /* _DEBUG */ + shared_ptr object = static_pointer_cast(boost::get(m_Value)); +#endif /* _DEBUG */ return object; } -- 2.40.0