Skip to content

Commit

Permalink
Restore removal of hashmap finalizer.
Browse files Browse the repository at this point in the history
evoskuil committed Jun 24, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 5832ec5 commit 0c50f96
Showing 1 changed file with 6 additions and 24 deletions.
30 changes: 6 additions & 24 deletions include/bitcoin/database/impl/primitives/hashmap.ipp
Original file line number Diff line number Diff line change
@@ -273,24 +273,15 @@ bool CLASS::put_link(Link& link, const Key& key,
if (!ptr)
return false;

// iostream.flush is a nop (direct copy).
iostream stream{ *ptr };
finalizer sink{ stream };
sink.skip_bytes(Link::size);
sink.write_bytes(key);

// The finalizer provides deferred index commit following serialization.
// Because the lambda captures ptr and is in turn held as a member of sink,
// ptr is guaranteed in scope until sink destruction, which follows flush.
// It may be possible to instead assign ptr to a sink member, but not being
// referenced would make it subject to optimization (volatile might work).
sink.set_finalizer([this, link, index = head_.index(key), ptr]() NOEXCEPT
{
auto& next = unsafe_array_cast<uint8_t, Link::size>(ptr->begin());
return head_.push(link, next, index);
});

if constexpr (!is_slab) { BC_DEBUG_ONLY(sink.set_limit(Size * count);) }
return element.to_data(sink) && sink.finalize();
auto& next = unsafe_array_cast<uint8_t, Link::size>(ptr->begin());
return element.to_data(sink) && head_.push(link, next, head_.index(key));
}

TEMPLATE
@@ -311,24 +302,15 @@ bool CLASS::put(const Link& link, const Key& key,
if (!ptr)
return false;

// iostream.flush is a nop (direct copy).
iostream stream{ *ptr };
finalizer sink{ stream };
sink.skip_bytes(Link::size);
sink.write_bytes(key);

// The finalizer provides deferred index commit following serialization.
// Because the lambda captures ptr and is in turn held as a member of sink,
// ptr is guaranteed in scope until sink destruction, which follows flush.
// It may be possible to instead assign ptr to a sink member, but not being
// referenced would make it subject to optimization (volatile might work).
sink.set_finalizer([this, link, index = head_.index(key), ptr]() NOEXCEPT
{
auto& next = unsafe_array_cast<uint8_t, Link::size>(ptr->begin());
return head_.push(link, next, index);
});

if constexpr (!is_slab) { BC_DEBUG_ONLY(sink.set_limit(Size * count);) }
return element.to_data(sink) && sink.finalize();
auto& next = unsafe_array_cast<uint8_t, Link::size>(ptr->begin());
return element.to_data(sink) && head_.push(link, next, head_.index(key));
}

TEMPLATE

0 comments on commit 0c50f96

Please sign in to comment.