Merge pull request #10028 from ethereum/useArrayLength

Use array length function.
This commit is contained in:
chriseth 2020-10-14 13:35:09 +02:00 committed by GitHub
commit 25b10b9643
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1767,32 +1767,11 @@ void IRGeneratorForStatements::endVisit(MemberAccess const& _memberAccess)
auto const& type = dynamic_cast<ArrayType const&>(*_memberAccess.expression().annotation().type);
if (member == "length")
{
if (!type.isDynamicallySized())
define(_memberAccess) << type.length() << "\n";
else
switch (type.location())
{
case DataLocation::CallData:
define(_memberAccess, IRVariable(_memberAccess.expression()).part("length"));
break;
case DataLocation::Storage:
{
define(_memberAccess) <<
m_utils.arrayLengthFunction(type) <<
"(" <<
IRVariable(_memberAccess.expression()).commaSeparatedList() <<
")\n";
break;
}
case DataLocation::Memory:
define(_memberAccess) <<
"mload(" <<
IRVariable(_memberAccess.expression()).commaSeparatedList() <<
")\n";
break;
}
}
define(_memberAccess) <<
m_utils.arrayLengthFunction(type) <<
"(" <<
IRVariable(_memberAccess.expression()).commaSeparatedList() <<
")\n";
else if (member == "pop" || member == "push")
{
solAssert(type.location() == DataLocation::Storage, "");