mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Use LazyInit for MemberList::m_storageOffsets
This commit is contained in:
parent
197f6bf3c8
commit
0e26700f65
@ -207,26 +207,31 @@ void MemberList::combine(MemberList const & _other)
|
|||||||
|
|
||||||
pair<u256, unsigned> const* MemberList::memberStorageOffset(string const& _name) const
|
pair<u256, unsigned> const* MemberList::memberStorageOffset(string const& _name) const
|
||||||
{
|
{
|
||||||
if (!m_storageOffsets)
|
StorageOffsets const& offsets = storageOffsets();
|
||||||
{
|
|
||||||
TypePointers memberTypes;
|
|
||||||
memberTypes.reserve(m_memberTypes.size());
|
|
||||||
for (auto const& member: m_memberTypes)
|
|
||||||
memberTypes.push_back(member.type);
|
|
||||||
m_storageOffsets = std::make_unique<StorageOffsets>();
|
|
||||||
m_storageOffsets->computeOffsets(memberTypes);
|
|
||||||
}
|
|
||||||
for (size_t index = 0; index < m_memberTypes.size(); ++index)
|
for (size_t index = 0; index < m_memberTypes.size(); ++index)
|
||||||
if (m_memberTypes[index].name == _name)
|
if (m_memberTypes[index].name == _name)
|
||||||
return m_storageOffsets->offset(index);
|
return offsets.offset(index);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
u256 const& MemberList::storageSize() const
|
u256 const& MemberList::storageSize() const
|
||||||
{
|
{
|
||||||
// trigger lazy computation
|
return storageOffsets().storageSize();
|
||||||
memberStorageOffset("");
|
}
|
||||||
return m_storageOffsets->storageSize();
|
|
||||||
|
StorageOffsets const& MemberList::storageOffsets() const {
|
||||||
|
return m_storageOffsets.init([&]{
|
||||||
|
TypePointers memberTypes;
|
||||||
|
memberTypes.reserve(m_memberTypes.size());
|
||||||
|
for (auto const& member: m_memberTypes)
|
||||||
|
memberTypes.push_back(member.type);
|
||||||
|
|
||||||
|
StorageOffsets storageOffsets;
|
||||||
|
storageOffsets.computeOffsets(memberTypes);
|
||||||
|
|
||||||
|
return storageOffsets;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Helper functions for type identifier
|
/// Helper functions for type identifier
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
|
|
||||||
#include <libsolutil/Common.h>
|
#include <libsolutil/Common.h>
|
||||||
#include <libsolutil/CommonIO.h>
|
#include <libsolutil/CommonIO.h>
|
||||||
|
#include <libsolutil/LazyInit.h>
|
||||||
#include <libsolutil/Result.h>
|
#include <libsolutil/Result.h>
|
||||||
|
|
||||||
#include <boost/rational.hpp>
|
#include <boost/rational.hpp>
|
||||||
@ -139,8 +140,10 @@ public:
|
|||||||
MemberMap::const_iterator end() const { return m_memberTypes.end(); }
|
MemberMap::const_iterator end() const { return m_memberTypes.end(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
StorageOffsets const& storageOffsets() const;
|
||||||
|
|
||||||
MemberMap m_memberTypes;
|
MemberMap m_memberTypes;
|
||||||
mutable std::unique_ptr<StorageOffsets> m_storageOffsets;
|
util::LazyInit<StorageOffsets> m_storageOffsets;
|
||||||
};
|
};
|
||||||
|
|
||||||
static_assert(std::is_nothrow_move_constructible<MemberList>::value, "MemberList should be noexcept move constructible");
|
static_assert(std::is_nothrow_move_constructible<MemberList>::value, "MemberList should be noexcept move constructible");
|
||||||
|
Loading…
Reference in New Issue
Block a user