Skip to content

Commit

Permalink
Call reserve before copy_field
Browse files Browse the repository at this point in the history
Summary: This is currently used in copy constructor for structs when it transitively includes unique_ptr on a field. `reserve` to avoid realloc

Differential Revision: D52883837

fbshipit-source-id: d9bb5b444cfcd75b548370f432f088941719c39f
  • Loading branch information
thedavekwon authored and facebook-github-bot committed Jan 19, 2024
1 parent be3fc04 commit e11f1a5
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions thrift/lib/cpp2/gen/module_types_cpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <thrift/lib/cpp/protocol/TType.h>
#include <thrift/lib/cpp2/Thrift.h>
#include <thrift/lib/cpp2/op/Compare.h>
#include <thrift/lib/cpp2/protocol/detail/protocol_methods.h>

namespace apache {
namespace thrift {
Expand Down Expand Up @@ -216,6 +217,7 @@ struct copy_field_rec<type_class::list<ValueTypeClass>> {
template <typename T>
T operator()(T const& t) const {
T result;
::apache::thrift::detail::pm::reserve_if_possible(&result, t.size());
for (const auto& e : t) {
result.push_back(copy_field<ValueTypeClass>(e));
}
Expand All @@ -228,6 +230,7 @@ struct copy_field_rec<type_class::set<ValueTypeClass>> {
template <typename T>
T operator()(T const& t) const {
T result;
::apache::thrift::detail::pm::reserve_if_possible(&result, t.size());
for (const auto& e : t) {
result.emplace_hint(result.end(), copy_field<ValueTypeClass>(e));
}
Expand All @@ -240,6 +243,7 @@ struct copy_field_rec<type_class::map<KeyTypeClass, MappedTypeClass>> {
template <typename T>
T operator()(T const& t) const {
T result;
::apache::thrift::detail::pm::reserve_if_possible(&result, t.size());
for (const auto& pair : t) {
result.emplace_hint(
result.end(),
Expand Down

0 comments on commit e11f1a5

Please sign in to comment.