From a3e2aeab94b2af855d77050a4b22c227531dbb8d Mon Sep 17 00:00:00 2001 From: Felix Guendling Date: Wed, 6 Nov 2019 11:43:51 +0100 Subject: [PATCH] improve serialization speed --- include/cista/serialization.h | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/include/cista/serialization.h b/include/cista/serialization.h index 81d39ce3..d06eb014 100755 --- a/include/cista/serialization.h +++ b/include/cista/serialization.h @@ -108,10 +108,7 @@ struct serialization_context { std::optional resolve_vector_range_ptr(Ptr ptr) { if (vector_ranges_.empty()) { return std::nullopt; - } else if (auto const vec_it = std::upper_bound( - begin(vector_ranges_), end(vector_ranges_), - std::pair{static_cast(ptr), vector_range{0, 0}}, - compare); + } else if (auto const vec_it = vector_ranges_.upper_bound(ptr); vec_it == begin(vector_ranges_)) { return std::nullopt; } else { @@ -125,7 +122,7 @@ struct serialization_context { uint64_t checksum(offset_t const from) const { return t_.checksum(from); } cista::raw::hash_map offsets_; - std::vector> vector_ranges_; + std::map vector_ranges_; std::vector pending_; Target& t_; }; @@ -184,12 +181,7 @@ void serialize(Ctx& c, if constexpr (Indexed) { if (origin->el_ != nullptr) { - auto p = std::pair{static_cast(origin->el_), - vector_range{start, size}}; - c.vector_ranges_.emplace( - std::upper_bound(begin(c.vector_ranges_), end(c.vector_ranges_), p, - Ctx::compare), - p); + c.vector_ranges_.emplace(origin->el_, vector_range{start, size}); } }