Properly clear other hashmap after move.

This commit is contained in:
levlam 2022-02-23 15:58:12 +03:00
parent 5f5205ae6c
commit b3a784f4ba
2 changed files with 6 additions and 7 deletions

View File

@ -275,12 +275,12 @@ class FlatHashTable {
} }
FlatHashTable(FlatHashTable &&other) noexcept : nodes_(std::move(other.nodes_)), used_nodes_(other.used_nodes_) { FlatHashTable(FlatHashTable &&other) noexcept : nodes_(std::move(other.nodes_)), used_nodes_(other.used_nodes_) {
other.used_nodes_ = 0; other.clear();
} }
void operator=(FlatHashTable &&other) noexcept { void operator=(FlatHashTable &&other) noexcept {
nodes_ = std::move(other.nodes_); nodes_ = std::move(other.nodes_);
used_nodes_ = other.used_nodes_; used_nodes_ = other.used_nodes_;
other.used_nodes_ = 0; other.clear();
} }
void swap(FlatHashTable &other) noexcept { void swap(FlatHashTable &other) noexcept {
nodes_.swap(other.nodes_); nodes_.swap(other.nodes_);

View File

@ -435,8 +435,7 @@ static void benchmark_create(td::Slice name) {
table.emplace(rnd(), i); table.emplace(rnd(), i);
} }
auto end = td::Timestamp::now(); auto end = td::Timestamp::now();
LOG(INFO) << name << ":" LOG(INFO) << name << ": create " << N << " elements: " << td::format::as_time(end.at() - start.at());
<< "create " << N << " elements: " << td::format::as_time(end.at() - start.at());
double res = 0; double res = 0;
td::vector<std::pair<std::size_t, td::format::Time>> pauses; td::vector<std::pair<std::size_t, td::format::Time>> pauses;
@ -451,8 +450,8 @@ static void benchmark_create(td::Slice name) {
} }
} }
LOG(INFO) << name << ":" LOG(INFO) << name << ": create another " << N << " elements, max pause = " << td::format::as_time(res) << " "
<< "create another " << N << " elements, max pause = " << td::format::as_time(res) << " " << pauses; << pauses;
} }
} }
@ -559,8 +558,8 @@ BENCHMARK_TEMPLATE(BM_mask, td::MaskSse2);
#endif #endif
#define FOR_EACH_TABLE(F) \ #define FOR_EACH_TABLE(F) \
F(td::FlatHashMapChunks) \
F(td::FlatHashMapImpl) \ F(td::FlatHashMapImpl) \
F(td::FlatHashMapChunks) \
F(folly::F14FastMap) \ F(folly::F14FastMap) \
F(absl::flat_hash_map) \ F(absl::flat_hash_map) \
F(std::unordered_map) \ F(std::unordered_map) \