Everywhere: Use Optional<T>::ensure() where useful

No functional changes.
This commit is contained in:
Jelle Raaijmakers
2025-09-17 15:48:22 +02:00
committed by Tim Flynn
parent 0fe9255991
commit c31eff6a47
Notes: github-actions[bot] 2025-09-17 16:02:17 +00:00
14 changed files with 53 additions and 87 deletions

View File

@@ -360,13 +360,11 @@ FLATTEN SignedBigInteger SignedBigInteger::negated_value() const
u32 SignedBigInteger::hash() const
{
if (m_hash.has_value())
return *m_hash;
auto buffer = MUST(ByteBuffer::create_zeroed(byte_length()));
auto result = export_data(buffer);
m_hash = string_hash(reinterpret_cast<char const*>(result.data()), result.size());
return *m_hash;
return m_hash.ensure([&] {
auto buffer = MUST(ByteBuffer::create_zeroed(byte_length()));
auto result = export_data(buffer);
return string_hash(reinterpret_cast<char const*>(result.data()), result.size());
});
}
bool SignedBigInteger::operator==(SignedBigInteger const& other) const