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:
Simon Liu 2018-11-13 14:37:08 -08:00 committed by Facebook Github Bot
parent b32d087dbb
commit a2de8e52bb

View File

@ -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() {