Skip to content

Commit

Permalink
Reduce the number of dynamic casts
Browse files Browse the repository at this point in the history
  • Loading branch information
jstone-lucasfilm authored Oct 15, 2024
1 parent 1f697fc commit 1c4af95
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions source/MaterialXCore/Element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,10 @@ ElementPtr Element::changeChildCategory(ElementPtr child, const string& category
template <class T> shared_ptr<T> Element::getChildOfType(const string& name) const
{
ElementPtr child;
if (isA<Document>() && asA<Document>()->hasDataLibrary())
DocumentPtr doc = asA<Document>();
if (doc && doc->hasDataLibrary())
{
child = asA<Document>()->getDataLibrary()->getChild(name);
child = doc->getDataLibrary()->getChild(name);
}
if (!child)
{
Expand All @@ -301,9 +302,10 @@ template <class T> shared_ptr<T> Element::getChildOfType(const string& name) con
template <class T> vector<shared_ptr<T>> Element::getChildrenOfType(const string& category) const
{
vector<shared_ptr<T>> children;
if (isA<Document>() && asA<Document>()->hasDataLibrary())
DocumentPtr doc = asA<Document>();
if (doc && doc->hasDataLibrary())
{
children = asA<Document>()->getDataLibrary()->getChildrenOfType<T>(category);
children = doc->getDataLibrary()->getChildrenOfType<T>(category);
}
for (ElementPtr child : _childOrder)
{
Expand Down

0 comments on commit 1c4af95

Please sign in to comment.