mirror of
https://github.com/facebook/rocksdb.git
synced 2024-11-25 22:44:05 +00:00
optimized the performance of autovector::emplace_back. (#4606)
Summary: It called the autovector::push_back simply in autovector::emplace_back. This was not efficient, and then optimazed this function through the perfect forwarding. This was the src and result of the benchmark(using the google'benchmark library, the type of elem in autovector was std::string, and call emplace_back with the "char *" type): https://gist.github.com/monadbobo/93448b89a42737b08cbada81de75c5cd PS: The benchmark's result of previous PR was not accurate, and so I update the test case and result. Pull Request resolved: https://github.com/facebook/rocksdb/pull/4606 Differential Revision: D13046813 Pulled By: sagar0 fbshipit-source-id: 19cde1bcadafe899aa454b703acb35737a1cc02d
This commit is contained in:
parent
b32d087dbb
commit
a2de8e52bb
|
@ -271,7 +271,12 @@ class autovector {
|
|||
|
||||
template <class... Args>
|
||||
void emplace_back(Args&&... args) {
|
||||
push_back(value_type(args...));
|
||||
if (num_stack_items_ < kSize) {
|
||||
values_[num_stack_items_++] =
|
||||
std::move(value_type(std::forward<Args>(args)...));
|
||||
} else {
|
||||
vect_.emplace_back(std::forward<Args>(args)...);
|
||||
}
|
||||
}
|
||||
|
||||
void pop_back() {
|
||||
|
|
Loading…
Reference in a new issue