Avoid creating copy of the object

This commit is contained in:
r0qs 2023-08-28 14:06:06 +02:00
parent 61162deea7
commit 98b5b6c916
No known key found for this signature in database
GPG Key ID: 61503DBA6667276C
3 changed files with 6 additions and 7 deletions

View File

@ -192,9 +192,8 @@ std::vector<size_t> Object::pathToSubObject(YulString _qualifiedName) const
return path; return path;
} }
std::shared_ptr<Object> Object::subObjectAt(std::string const& _qualifiedName) Object const* Object::subObjectAt(std::string const& _qualifiedName)
{ {
if (_qualifiedName.empty()) if (_qualifiedName.empty())
return nullptr; return nullptr;
@ -206,11 +205,11 @@ std::shared_ptr<Object> Object::subObjectAt(std::string const& _qualifiedName)
if (targetObjectPos != std::string::npos) if (targetObjectPos != std::string::npos)
targetObjectName = _qualifiedName.substr(targetObjectPos + 1); targetObjectName = _qualifiedName.substr(targetObjectPos + 1);
std::shared_ptr<Object> foundObject = nullptr; Object const* foundObject = nullptr;
this->visitPath(YulString(_qualifiedName), [&](Object const* _subObject) -> bool { this->visitPath(YulString(_qualifiedName), [&](Object const* _subObject) -> bool {
if (targetObjectName == _subObject->name.str()) if (targetObjectName == _subObject->name.str())
{ {
foundObject = std::make_shared<Object>(*_subObject); foundObject = _subObject;
return true; return true;
} }
return false; return false;

View File

@ -118,8 +118,8 @@ public:
std::vector<size_t> pathToSubObject(YulString _qualifiedName) const; std::vector<size_t> pathToSubObject(YulString _qualifiedName) const;
/// Searches for a subobject at @param _qualifiedName within the current object. /// Searches for a subobject at @param _qualifiedName within the current object.
/// @returns a shared_ptr to the subobject or a nullptr if it was not found. /// @returns a pointer to the subobject or a nullptr if it was not found.
std::shared_ptr<Object> subObjectAt(std::string const& _qualifiedName); Object const* subObjectAt(std::string const& _qualifiedName);
/// Visits all subobjects in the path given by the @a _qualifiedName /// Visits all subobjects in the path given by the @a _qualifiedName
/// of the current object applying the function @a _visitor. /// of the current object applying the function @a _visitor.

View File

@ -253,7 +253,7 @@ public:
{ {
if (!m_inputIsCodeBlock) if (!m_inputIsCodeBlock)
{ {
shared_ptr<Object> subObject = m_object->subObjectAt(_objectPath); Object const* subObject = m_object->subObjectAt(_objectPath);
if (subObject == nullptr) if (subObject == nullptr)
solThrow(Exception, "Assembly object not found."); solThrow(Exception, "Assembly object not found.");