Skip to content

Commit

Permalink
Merge pull request #500 from evoskuil/master
Browse files Browse the repository at this point in the history
Restore removal of hashmap finalizer.
  • Loading branch information
evoskuil authored Jun 24, 2024
2 parents 5832ec5 + 0c50f96 commit 0749c73
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
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 0749c73

Please sign in to comment.