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/replace.hpp>
#include <range/v3/algorithm/find_if.hpp>
#include <range/v3/view/transform.hpp>
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
{
return "data \"" + name.str() + "\" hex\"" + util::toHex(data) + "\"";
@ -156,21 +161,14 @@ void Object::visitPath(YulString _qualifiedName, std::function<bool(Object const
{
yulAssert(!currentSubObjectName.empty(), "");
auto subObjectIt = ranges::find_if(
object->subObjects,
[&currentSubObjectName](auto const& _subObject) { return _subObject->name.str() == currentSubObjectName; }
YulString subObjectName = YulString{currentSubObjectName};
yulAssert(
object->subIndexByName.count(subObjectName),
"Assembly object not found or does not contain code."
);
if (subObjectIt != object->subObjects.end())
{
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;
}
}
object = object->at(subObjectName);
if (object && _visitor(object))
break;
}
}

View File

@ -130,6 +130,8 @@ public:
std::function<bool(Object const*)> _visitor
) 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
size_t subId = std::numeric_limits<size_t>::max();