diff options
author | chriseth <c@ethdev.com> | 2015-03-17 00:52:19 +0800 |
---|---|---|
committer | chriseth <c@ethdev.com> | 2015-03-18 01:13:28 +0800 |
commit | 2cde4f34044b89bb8bced05cab308c0093bd192d (patch) | |
tree | 00c787836993fccec01d16a6ecf5ed072b8e6c2a /Types.cpp | |
parent | 895c08342c4b236c2928a5af9fb23def218eca3d (diff) | |
download | dexon-solidity-2cde4f34044b89bb8bced05cab308c0093bd192d.tar.gz dexon-solidity-2cde4f34044b89bb8bced05cab308c0093bd192d.tar.zst dexon-solidity-2cde4f34044b89bb8bced05cab308c0093bd192d.zip |
Packing for arrays.
Diffstat (limited to 'Types.cpp')
-rw-r--r-- | Types.cpp | 18 |
1 files changed, 13 insertions, 5 deletions
@@ -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 |