aboutsummaryrefslogtreecommitdiffstats
path: root/Types.cpp
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2015-03-17 00:52:19 +0800
committerchriseth <c@ethdev.com>2015-03-18 01:13:28 +0800
commit2cde4f34044b89bb8bced05cab308c0093bd192d (patch)
tree00c787836993fccec01d16a6ecf5ed072b8e6c2a /Types.cpp
parent895c08342c4b236c2928a5af9fb23def218eca3d (diff)
downloaddexon-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.cpp18
1 files changed, 13 insertions, 5 deletions
diff --git a/Types.cpp b/Types.cpp
index ed3cb8fd..14ea4c73 100644
--- a/Types.cpp
+++ b/Types.cpp
@@ -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