Skip to content

Commit

Permalink
improve serialization speed
Browse files Browse the repository at this point in the history
  • Loading branch information
felixguendling committed Nov 6, 2019
1 parent d6f282d commit a3e2aea
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions include/cista/serialization.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,7 @@ struct serialization_context {
std::optional<offset_t> 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<void const*>(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 {
Expand All @@ -125,7 +122,7 @@ struct serialization_context {
uint64_t checksum(offset_t const from) const { return t_.checksum(from); }

cista::raw::hash_map<void const*, offset_t> offsets_;
std::vector<std::pair<void const*, vector_range>> vector_ranges_;
std::map<void const*, vector_range> vector_ranges_;
std::vector<pending_offset> pending_;
Target& t_;
};
Expand Down Expand Up @@ -184,12 +181,7 @@ void serialize(Ctx& c,

if constexpr (Indexed) {
if (origin->el_ != nullptr) {
auto p = std::pair{static_cast<void const*>(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});
}
}

Expand Down

0 comments on commit a3e2aea

Please sign in to comment.