types: Don't wrap tombstone in an std::optional

All the callers of do_serialize_mutation_form pass a valid tombstone
that is converted into a non-empty optional. This happens even if the
tombstone is empty (tombstone::timestamp == api::missing_timestamp).

This patch fixes this by passing in a reference to the tombstone which
is convertible to bool, based on whether it is empty or not.

Signed-off-by: Duarte Nunes <duarte@scylladb.com>
Message-Id: <1460620528-3628-1-git-send-email-duarte@scylladb.com>
This commit is contained in:
Duarte Nunes
2016-04-14 09:55:28 +02:00
committed by Tomasz Grabiec
parent 40c1b29701
commit f8d8dbdeb7

View File

@@ -1826,7 +1826,7 @@ bool collection_type_impl::is_any_live(collection_mutation_view cm, tombstone to
template <typename Iterator>
collection_mutation
do_serialize_mutation_form(
std::experimental::optional<tombstone> tomb,
const tombstone& tomb,
boost::iterator_range<Iterator> cells) {
auto element_size = [] (size_t c, auto&& e) -> size_t {
return c + 8 + e.first.size() + e.second.serialize().size();
@@ -1834,14 +1834,14 @@ do_serialize_mutation_form(
auto size = accumulate(cells, (size_t)4, element_size);
size += 1;
if (tomb) {
size += sizeof(tomb->timestamp) + sizeof(tomb->deletion_time);
size += sizeof(tomb.timestamp) + sizeof(tomb.deletion_time);
}
bytes ret(bytes::initialized_later(), size);
bytes::iterator out = ret.begin();
*out++ = bool(tomb);
if (tomb) {
write(out, tomb->timestamp);
write(out, tomb->deletion_time.time_since_epoch().count());
write(out, tomb.timestamp);
write(out, tomb.deletion_time.time_since_epoch().count());
}
auto writeb = [&out] (bytes_view v) {
serialize_int32(out, v.size());