Packing for arrays.

This commit is contained in:
chriseth
2015-03-17 18:13:28 +01:00
parent 895c08342c
commit 2cde4f3404
5 changed files with 240 additions and 76 deletions
+13 -5
View File
@@ -706,13 +706,21 @@ u256 ArrayType::getStorageSize() const
{
if (isDynamicallySized())
return 1;
else
bigint size;
unsigned baseBytes = getBaseType()->getStorageBytes();
if (baseBytes == 0)
size = 1;
else if (baseBytes < 32)
{
bigint size = bigint(getLength()) * getBaseType()->getStorageSize();
if (size >= bigint(1) << 256)
BOOST_THROW_EXCEPTION(TypeError() << errinfo_comment("Array too large for storage."));
return max<u256>(1, u256(size));
unsigned itemsPerSlot = 32 / baseBytes;
size = (bigint(getLength()) + (itemsPerSlot - 1)) / itemsPerSlot;
}
else
size = bigint(getLength()) * getBaseType()->getStorageSize();
if (size >= bigint(1) << 256)
BOOST_THROW_EXCEPTION(TypeError() << errinfo_comment("Array too large for storage."));
return max<u256>(1, u256(size));
}
unsigned ArrayType::getSizeOnStack() const