Restore efficient subobject search

This commit is contained in:
r0qs 2023-08-28 16:04:39 +02:00
parent 98b5b6c916
commit 1ec239c63f
No known key found for this signature in database
GPG Key ID: 61503DBA6667276C
2 changed files with 15 additions and 15 deletions

View File

@ -33,7 +33,6 @@
#include <boost/algorithm/string/split.hpp> #include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/replace.hpp> #include <boost/algorithm/string/replace.hpp>
#include <range/v3/algorithm/find_if.hpp>
#include <range/v3/view/transform.hpp> #include <range/v3/view/transform.hpp>
using namespace solidity; using namespace solidity;
@ -53,6 +52,12 @@ std::string indent(std::string const& _input)
} }
Object const* Object::at(YulString _name) const
{
size_t subIndex = this->subIndexByName.at(_name);
return dynamic_cast<Object const*>(this->subObjects[subIndex].get());
}
std::string Data::toString(Dialect const*, DebugInfoSelection const&, CharStreamProvider const*) const std::string Data::toString(Dialect const*, DebugInfoSelection const&, CharStreamProvider const*) const
{ {
return "data \"" + name.str() + "\" hex\"" + util::toHex(data) + "\""; return "data \"" + name.str() + "\" hex\"" + util::toHex(data) + "\"";
@ -156,22 +161,15 @@ void Object::visitPath(YulString _qualifiedName, std::function<bool(Object const
{ {
yulAssert(!currentSubObjectName.empty(), ""); yulAssert(!currentSubObjectName.empty(), "");
auto subObjectIt = ranges::find_if( YulString subObjectName = YulString{currentSubObjectName};
object->subObjects, yulAssert(
[&currentSubObjectName](auto const& _subObject) { return _subObject->name.str() == currentSubObjectName; } object->subIndexByName.count(subObjectName),
"Assembly object not found or does not contain code."
); );
object = object->at(subObjectName);
if (subObjectIt != object->subObjects.end()) if (object && _visitor(object))
{
object = dynamic_cast<Object const*>(subObjectIt->get());
if (object)
{
yulAssert(object, "Assembly object <" + object->name.str() + "> not found or does not contain code.");
if (_visitor(object))
break; break;
} }
}
}
} }
std::vector<size_t> Object::pathToSubObject(YulString _qualifiedName) const std::vector<size_t> Object::pathToSubObject(YulString _qualifiedName) const

View File

@ -130,6 +130,8 @@ public:
std::function<bool(Object const*)> _visitor std::function<bool(Object const*)> _visitor
) const; ) const;
Object const* at(YulString _name) const;
/// sub id for object if it is subobject of another object, max value if it is not subobject /// sub id for object if it is subobject of another object, max value if it is not subobject
size_t subId = std::numeric_limits<size_t>::max(); size_t subId = std::numeric_limits<size_t>::max();