Avoid creating copy of the object

This commit is contained in:
r0qs
2023-10-02 14:35:38 +02:00
parent 61162deea7
commit 98b5b6c916
3 changed files with 6 additions and 7 deletions
+3 -4
View File
@@ -192,9 +192,8 @@ std::vector<size_t> Object::pathToSubObject(YulString _qualifiedName) const
return path;
}
std::shared_ptr<Object> Object::subObjectAt(std::string const& _qualifiedName)
Object const* Object::subObjectAt(std::string const& _qualifiedName)
{
if (_qualifiedName.empty())
return nullptr;
@@ -206,11 +205,11 @@ std::shared_ptr<Object> Object::subObjectAt(std::string const& _qualifiedName)
if (targetObjectPos != std::string::npos)
targetObjectName = _qualifiedName.substr(targetObjectPos + 1);
std::shared_ptr<Object> foundObject = nullptr;
Object const* foundObject = nullptr;
this->visitPath(YulString(_qualifiedName), [&](Object const* _subObject) -> bool {
if (targetObjectName == _subObject->name.str())
{
foundObject = std::make_shared<Object>(*_subObject);
foundObject = _subObject;
return true;
}
return false;
+2 -2
View File
@@ -118,8 +118,8 @@ public:
std::vector<size_t> pathToSubObject(YulString _qualifiedName) const;
/// 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.
std::shared_ptr<Object> subObjectAt(std::string const& _qualifiedName);
/// @returns a pointer to the subobject or a nullptr if it was not found.
Object const* subObjectAt(std::string const& _qualifiedName);
/// Visits all subobjects in the path given by the @a _qualifiedName
/// of the current object applying the function @a _visitor.
+1 -1
View File
@@ -253,7 +253,7 @@ public:
{
if (!m_inputIsCodeBlock)
{
shared_ptr<Object> subObject = m_object->subObjectAt(_objectPath);
Object const* subObject = m_object->subObjectAt(_objectPath);
if (subObject == nullptr)
solThrow(Exception, "Assembly object not found.");