提交 a2de8e52 编写于 作者: S Simon Liu 提交者: Facebook Github Bot

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
上级 b32d087d
......@@ -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() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册