Skip to content

Commit 143bf17

Browse files
authored
Merge pull request #486 from SYaoJun/223_emplace_back
perf: Replace push_back with emplace_back to optimize object construc…
2 parents 0d71e2c + 13bb3a9 commit 143bf17

3 files changed

Lines changed: 6 additions & 6 deletions

File tree

theta/include/theta_set_difference_base_impl.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ CS theta_set_difference_base<EN, EK, CS, A>::compute(FwdSketch&& a, const Sketch
6969
const uint64_t hash = EK()(entry);
7070
if (hash < theta) {
7171
auto result = table.find(hash);
72-
if (!result.second) entries.push_back(conditional_forward<FwdSketch>(entry));
72+
if (!result.second) entries.emplace_back(conditional_forward<FwdSketch>(entry));
7373
} else if (a.is_ordered()) {
7474
break; // early stop
7575
}

tuple/include/array_tuple_sketch_impl.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ compact_array_tuple_sketch<Array, Allocator> compact_array_tuple_sketch<Array, A
166166
for (size_t i = 0; i < num_entries; ++i) {
167167
Array summary(num_values, 0, allocator);
168168
read(is, summary.data(), num_values * sizeof(typename Array::value_type));
169-
entries.push_back(Entry(keys[i], std::move(summary)));
169+
entries.emplace_back(keys[i], std::move(summary));
170170
}
171171
}
172172
if (!is.good()) throw std::runtime_error("error reading from std::istream");
@@ -213,7 +213,7 @@ compact_array_tuple_sketch<Array, Allocator> compact_array_tuple_sketch<Array, A
213213
for (size_t i = 0; i < num_entries; ++i) {
214214
Array summary(num_values, 0, allocator);
215215
ptr += copy_from_mem(ptr, summary.data(), num_values * sizeof(typename Array::value_type));
216-
entries.push_back(Entry(keys[i], std::move(summary)));
216+
entries.emplace_back(keys[i], std::move(summary));
217217
}
218218
}
219219
const bool is_empty = flags_byte & (1 << flags::IS_EMPTY);

tuple/include/tuple_sketch_impl.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ entries_(other.get_allocator())
315315
{
316316
entries_.reserve(other.get_num_retained());
317317
for (uint64_t hash: other) {
318-
entries_.push_back(Entry(hash, summary));
318+
entries_.emplace_back(hash, summary);
319319
}
320320
if (ordered && !other.is_ordered()) std::sort(entries_.begin(), entries_.end(), comparator());
321321
}
@@ -518,7 +518,7 @@ compact_tuple_sketch<S, A> compact_tuple_sketch<S, A>::deserialize(std::istream&
518518
for (size_t i = 0; i < num_entries; ++i) {
519519
const auto key = read<uint64_t>(is);
520520
sd.deserialize(is, summary.get(), 1);
521-
entries.push_back(Entry(key, std::move(*summary)));
521+
entries.emplace_back(key, std::move(*summary));
522522
(*summary).~S();
523523
}
524524
}
@@ -585,7 +585,7 @@ compact_tuple_sketch<S, A> compact_tuple_sketch<S, A>::deserialize(const void* b
585585
uint64_t key;
586586
ptr += copy_from_mem(ptr, key);
587587
ptr += sd.deserialize(ptr, base + size - ptr, summary.get(), 1);
588-
entries.push_back(Entry(key, std::move(*summary)));
588+
entries.emplace_back(key, std::move(*summary));
589589
(*summary).~S();
590590
}
591591
}

0 commit comments

Comments
 (0)