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); auto const& type = dynamic_cast<ArrayType const&>(*_memberAccess.expression().annotation().type);
if (member == "length") if (member == "length")
{ define(_memberAccess) <<
if (!type.isDynamicallySized()) m_utils.arrayLengthFunction(type) <<
define(_memberAccess) << type.length() << "\n"; "(" <<
else IRVariable(_memberAccess.expression()).commaSeparatedList() <<
switch (type.location()) ")\n";
{
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;
}
}
else if (member == "pop" || member == "push") else if (member == "pop" || member == "push")
{ {
solAssert(type.location() == DataLocation::Storage, ""); solAssert(type.location() == DataLocation::Storage, "");