Use a template to collapse the 5 different set_ and add_ methods for repeated string fields into one for each overload set.

In translation units relying heavily on protobufs, this leads to a reduction of around 1% of the number of nodes in the AST.

PiperOrigin-RevId: 641170174
pull/17055/head
Protobuf Team Bot 8 months ago committed by Copybara-Service
parent b3bcbd92da
commit 31ead248b8
  1. 209
      src/google/protobuf/compiler/cpp/field_generators/string_field.cc
  2. 4
      src/google/protobuf/compiler/cpp/plugin_unittest.cc
  3. 74
      src/google/protobuf/compiler/plugin.pb.h
  4. 296
      src/google/protobuf/descriptor.pb.h
  5. 54
      src/google/protobuf/generated_message_util.h

@ -59,7 +59,6 @@ std::vector<Sub> Vars(const FieldDescriptor* field, const Options& opts) {
Sub{"lazy_args", !empty_default ? absl::StrCat(lazy_var, ",") : ""}
.WithSuffix(","),
{"byte", bytes ? "void" : "char"},
{"Set", bytes ? "SetBytes" : "Set"},
};
}
@ -840,17 +839,11 @@ void RepeatedString::GenerateAccessorDeclarations(io::Printer* p) const {
p->Emit(R"cc(
$DEPRECATED$ const std::string& $name$(int index) const;
$DEPRECATED$ std::string* $mutable_name$(int index);
$DEPRECATED$ void $set_name$(int index, const std::string& value);
$DEPRECATED$ void $set_name$(int index, std::string&& value);
$DEPRECATED$ void $set_name$(int index, const char* value);
$DEPRECATED$ void $set_name$(int index, const $byte$* value, std::size_t size);
$DEPRECATED$ void $set_name$(int index, absl::string_view value);
template <typename Arg_ = const std::string&, typename... Args_>
$DEPRECATED$ void set_$name$(int index, Arg_&& value, Args_... args);
$DEPRECATED$ std::string* $add_name$();
$DEPRECATED$ void $add_name$(const std::string& value);
$DEPRECATED$ void $add_name$(std::string&& value);
$DEPRECATED$ void $add_name$(const char* value);
$DEPRECATED$ void $add_name$(const $byte$* value, std::size_t size);
$DEPRECATED$ void $add_name$(absl::string_view value);
template <typename Arg_ = const std::string&, typename... Args_>
$DEPRECATED$ void $add_name$(Arg_&& value, Args_... args);
$DEPRECATED$ const $pb$::RepeatedPtrField<std::string>& $name$() const;
$DEPRECATED$ $pb$::RepeatedPtrField<std::string>* $mutable_name$();
@ -863,125 +856,81 @@ void RepeatedString::GenerateAccessorDeclarations(io::Printer* p) const {
}
void RepeatedString::GenerateInlineAccessorDefinitions(io::Printer* p) const {
p->Emit({{"Get", opts_->safe_boundary_check ? "InternalCheckedGet" : "Get"},
{"GetExtraArg",
[&] {
p->Emit(opts_->safe_boundary_check
? ", $pbi$::GetEmptyStringAlreadyInited()"
: "");
}}},
R"cc(
inline std::string* $Msg$::add_$name$()
ABSL_ATTRIBUTE_LIFETIME_BOUND {
$WeakDescriptorSelfPin$;
$TsanDetectConcurrentMutation$;
std::string* _s = _internal_mutable_$name_internal$()->Add();
$annotate_add_mutable$;
// @@protoc_insertion_point(field_add_mutable:$pkg.Msg.field$)
return _s;
}
inline const std::string& $Msg$::$name$(int index) const
ABSL_ATTRIBUTE_LIFETIME_BOUND {
$WeakDescriptorSelfPin$;
$annotate_get$;
// @@protoc_insertion_point(field_get:$pkg.Msg.field$)
return _internal_$name_internal$().$Get$(index$GetExtraArg$);
}
inline std::string* $Msg$::mutable_$name$(int index)
ABSL_ATTRIBUTE_LIFETIME_BOUND {
$WeakDescriptorSelfPin$;
$annotate_mutable$;
// @@protoc_insertion_point(field_mutable:$pkg.Msg.field$)
return _internal_mutable_$name_internal$()->Mutable(index);
}
inline void $Msg$::set_$name$(int index, const std::string& value) {
$WeakDescriptorSelfPin$;
_internal_mutable_$name_internal$()->Mutable(index)->assign(value);
$annotate_set$;
// @@protoc_insertion_point(field_set:$pkg.Msg.field$)
}
inline void $Msg$::set_$name$(int index, std::string&& value) {
$WeakDescriptorSelfPin$;
_internal_mutable_$name_internal$()->Mutable(index)->assign(std::move(value));
$annotate_set$;
// @@protoc_insertion_point(field_set:$pkg.Msg.field$)
}
inline void $Msg$::set_$name$(int index, const char* value) {
$WeakDescriptorSelfPin$;
$DCHK$(value != nullptr);
_internal_mutable_$name_internal$()->Mutable(index)->assign(value);
$annotate_set$;
// @@protoc_insertion_point(field_set_char:$pkg.Msg.field$)
}
inline void $Msg$::set_$name$(int index, const $byte$* value,
std::size_t size) {
$WeakDescriptorSelfPin$;
_internal_mutable_$name_internal$()->Mutable(index)->assign(
reinterpret_cast<const char*>(value), size);
$annotate_set$;
// @@protoc_insertion_point(field_set_pointer:$pkg.Msg.field$)
}
inline void $Msg$::set_$name$(int index, absl::string_view value) {
$WeakDescriptorSelfPin$;
_internal_mutable_$name_internal$()->Mutable(index)->assign(
value.data(), value.size());
$annotate_set$;
// @@protoc_insertion_point(field_set_string_piece:$pkg.Msg.field$)
}
inline void $Msg$::add_$name$(const std::string& value) {
$WeakDescriptorSelfPin$;
$TsanDetectConcurrentMutation$;
_internal_mutable_$name_internal$()->Add()->assign(value);
$annotate_add$;
// @@protoc_insertion_point(field_add:$pkg.Msg.field$)
}
inline void $Msg$::add_$name$(std::string&& value) {
$WeakDescriptorSelfPin$;
$TsanDetectConcurrentMutation$;
_internal_mutable_$name_internal$()->Add(std::move(value));
$annotate_add$;
// @@protoc_insertion_point(field_add:$pkg.Msg.field$)
}
inline void $Msg$::add_$name$(const char* value) {
$WeakDescriptorSelfPin$;
$DCHK$(value != nullptr);
$TsanDetectConcurrentMutation$;
_internal_mutable_$name_internal$()->Add()->assign(value);
$annotate_add$;
// @@protoc_insertion_point(field_add_char:$pkg.Msg.field$)
}
inline void $Msg$::add_$name$(const $byte$* value, std::size_t size) {
$WeakDescriptorSelfPin$;
$TsanDetectConcurrentMutation$;
_internal_mutable_$name_internal$()->Add()->assign(
reinterpret_cast<const char*>(value), size);
$annotate_add$;
// @@protoc_insertion_point(field_add_pointer:$pkg.Msg.field$)
}
inline void $Msg$::add_$name$(absl::string_view value) {
$WeakDescriptorSelfPin$;
$TsanDetectConcurrentMutation$;
_internal_mutable_$name_internal$()->Add()->assign(value.data(),
value.size());
$annotate_add$;
// @@protoc_insertion_point(field_add_string_piece:$pkg.Msg.field$)
}
inline const ::$proto_ns$::RepeatedPtrField<std::string>&
$Msg$::$name$() const ABSL_ATTRIBUTE_LIFETIME_BOUND {
$WeakDescriptorSelfPin$;
$annotate_list$;
// @@protoc_insertion_point(field_list:$pkg.Msg.field$)
return _internal_$name_internal$();
}
inline ::$proto_ns$::RepeatedPtrField<std::string>*
$Msg$::mutable_$name$() ABSL_ATTRIBUTE_LIFETIME_BOUND {
$WeakDescriptorSelfPin$;
$annotate_mutable_list$;
// @@protoc_insertion_point(field_mutable_list:$pkg.Msg.field$)
$TsanDetectConcurrentMutation$;
return _internal_mutable_$name_internal$();
}
)cc");
bool bytes = field_->type() == FieldDescriptor::TYPE_BYTES;
p->Emit(
{
{"Get", opts_->safe_boundary_check ? "InternalCheckedGet" : "Get"},
{"GetExtraArg",
[&] {
p->Emit(opts_->safe_boundary_check
? ", $pbi$::GetEmptyStringAlreadyInited()"
: "");
}},
{"bytes_tag",
[&] {
if (bytes) {
p->Emit(", $pbi$::BytesTag{}");
}
}},
},
R"cc(
inline std::string* $Msg$::add_$name$() ABSL_ATTRIBUTE_LIFETIME_BOUND {
$WeakDescriptorSelfPin$;
$TsanDetectConcurrentMutation$;
std::string* _s = _internal_mutable_$name_internal$()->Add();
$annotate_add_mutable$;
// @@protoc_insertion_point(field_add_mutable:$pkg.Msg.field$)
return _s;
}
inline const std::string& $Msg$::$name$(int index) const
ABSL_ATTRIBUTE_LIFETIME_BOUND {
$WeakDescriptorSelfPin$;
$annotate_get$;
// @@protoc_insertion_point(field_get:$pkg.Msg.field$)
return _internal_$name_internal$().$Get$(index$GetExtraArg$);
}
inline std::string* $Msg$::mutable_$name$(int index)
ABSL_ATTRIBUTE_LIFETIME_BOUND {
$WeakDescriptorSelfPin$;
$annotate_mutable$;
// @@protoc_insertion_point(field_mutable:$pkg.Msg.field$)
return _internal_mutable_$name_internal$()->Mutable(index);
}
template <typename Arg_, typename... Args_>
inline void $Msg$::set_$name$(int index, Arg_&& value, Args_... args) {
$WeakDescriptorSelfPin$;
$pbi$::AssignToString(
*_internal_mutable_$name_internal$()->Mutable(index),
std::forward<Arg_>(value), args... $bytes_tag$);
$annotate_set$;
// @@protoc_insertion_point(field_set:$pkg.Msg.field$)
}
template <typename Arg_, typename... Args_>
inline void $Msg$::add_$name$(Arg_&& value, Args_... args) {
$WeakDescriptorSelfPin$;
$TsanDetectConcurrentMutation$;
$pbi$::AddToRepeatedPtrField(*_internal_mutable_$name_internal$(),
std::forward<Arg_>(value),
args... $bytes_tag$);
$annotate_add$;
// @@protoc_insertion_point(field_add:$pkg.Msg.field$)
}
inline const ::$proto_ns$::RepeatedPtrField<std::string>&
$Msg$::$name$() const ABSL_ATTRIBUTE_LIFETIME_BOUND {
$WeakDescriptorSelfPin$;
$annotate_list$;
// @@protoc_insertion_point(field_list:$pkg.Msg.field$)
return _internal_$name_internal$();
}
inline ::$proto_ns$::RepeatedPtrField<std::string>*
$Msg$::mutable_$name$() ABSL_ATTRIBUTE_LIFETIME_BOUND {
$WeakDescriptorSelfPin$;
$annotate_mutable_list$;
// @@protoc_insertion_point(field_mutable_list:$pkg.Msg.field$)
$TsanDetectConcurrentMutation$;
return _internal_mutable_$name_internal$();
}
)cc");
if (should_split()) {
p->Emit(R"cc(
inline const $pb$::RepeatedPtrField<std::string>&

@ -63,11 +63,7 @@ class TestGenerator : public CodeGenerator {
// Check field accessors for a repeated string:
TryInsert("test.pb.h", "field_get:foo.Bar.repeatedString", context);
TryInsert("test.pb.h", "field_set:foo.Bar.repeatedString", context);
TryInsert("test.pb.h", "field_set_char:foo.Bar.repeatedString", context);
TryInsert("test.pb.h", "field_set_pointer:foo.Bar.repeatedString", context);
TryInsert("test.pb.h", "field_mutable:foo.Bar.repeatedString", context);
TryInsert("test.pb.h", "field_set_char:foo.Bar.repeatedString", context);
TryInsert("test.pb.h", "field_set_pointer:foo.Bar.repeatedString", context);
// Check field accessors for an int inside oneof{}:
TryInsert("test.pb.h", "field_get:foo.Bar.oneOfInt", context);

@ -973,17 +973,11 @@ class PROTOC_EXPORT CodeGeneratorRequest final : public ::google::protobuf::Mess
void clear_file_to_generate() ;
const std::string& file_to_generate(int index) const;
std::string* mutable_file_to_generate(int index);
void set_file_to_generate(int index, const std::string& value);
void set_file_to_generate(int index, std::string&& value);
void set_file_to_generate(int index, const char* value);
void set_file_to_generate(int index, const char* value, std::size_t size);
void set_file_to_generate(int index, absl::string_view value);
template <typename Arg_ = const std::string&, typename... Args_>
void set_file_to_generate(int index, Arg_&& value, Args_... args);
std::string* add_file_to_generate();
void add_file_to_generate(const std::string& value);
void add_file_to_generate(std::string&& value);
void add_file_to_generate(const char* value);
void add_file_to_generate(const char* value, std::size_t size);
void add_file_to_generate(absl::string_view value);
template <typename Arg_ = const std::string&, typename... Args_>
void add_file_to_generate(Arg_&& value, Args_... args);
const ::google::protobuf::RepeatedPtrField<std::string>& file_to_generate() const;
::google::protobuf::RepeatedPtrField<std::string>* mutable_file_to_generate();
@ -1283,8 +1277,7 @@ inline void CodeGeneratorRequest::clear_file_to_generate() {
::google::protobuf::internal::TSanWrite(&_impl_);
_impl_.file_to_generate_.Clear();
}
inline std::string* CodeGeneratorRequest::add_file_to_generate()
ABSL_ATTRIBUTE_LIFETIME_BOUND {
inline std::string* CodeGeneratorRequest::add_file_to_generate() ABSL_ATTRIBUTE_LIFETIME_BOUND {
::google::protobuf::internal::TSanWrite(&_impl_);
std::string* _s = _internal_mutable_file_to_generate()->Add();
// @@protoc_insertion_point(field_add_mutable:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate)
@ -1300,58 +1293,21 @@ inline std::string* CodeGeneratorRequest::mutable_file_to_generate(int index)
// @@protoc_insertion_point(field_mutable:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate)
return _internal_mutable_file_to_generate()->Mutable(index);
}
inline void CodeGeneratorRequest::set_file_to_generate(int index, const std::string& value) {
_internal_mutable_file_to_generate()->Mutable(index)->assign(value);
// @@protoc_insertion_point(field_set:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate)
}
inline void CodeGeneratorRequest::set_file_to_generate(int index, std::string&& value) {
_internal_mutable_file_to_generate()->Mutable(index)->assign(std::move(value));
template <typename Arg_, typename... Args_>
inline void CodeGeneratorRequest::set_file_to_generate(int index, Arg_&& value, Args_... args) {
::google::protobuf::internal::AssignToString(
*_internal_mutable_file_to_generate()->Mutable(index),
std::forward<Arg_>(value), args... );
// @@protoc_insertion_point(field_set:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate)
}
inline void CodeGeneratorRequest::set_file_to_generate(int index, const char* value) {
ABSL_DCHECK(value != nullptr);
_internal_mutable_file_to_generate()->Mutable(index)->assign(value);
// @@protoc_insertion_point(field_set_char:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate)
}
inline void CodeGeneratorRequest::set_file_to_generate(int index, const char* value,
std::size_t size) {
_internal_mutable_file_to_generate()->Mutable(index)->assign(
reinterpret_cast<const char*>(value), size);
// @@protoc_insertion_point(field_set_pointer:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate)
}
inline void CodeGeneratorRequest::set_file_to_generate(int index, absl::string_view value) {
_internal_mutable_file_to_generate()->Mutable(index)->assign(
value.data(), value.size());
// @@protoc_insertion_point(field_set_string_piece:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate)
}
inline void CodeGeneratorRequest::add_file_to_generate(const std::string& value) {
::google::protobuf::internal::TSanWrite(&_impl_);
_internal_mutable_file_to_generate()->Add()->assign(value);
// @@protoc_insertion_point(field_add:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate)
}
inline void CodeGeneratorRequest::add_file_to_generate(std::string&& value) {
template <typename Arg_, typename... Args_>
inline void CodeGeneratorRequest::add_file_to_generate(Arg_&& value, Args_... args) {
::google::protobuf::internal::TSanWrite(&_impl_);
_internal_mutable_file_to_generate()->Add(std::move(value));
::google::protobuf::internal::AddToRepeatedPtrField(*_internal_mutable_file_to_generate(),
std::forward<Arg_>(value),
args... );
// @@protoc_insertion_point(field_add:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate)
}
inline void CodeGeneratorRequest::add_file_to_generate(const char* value) {
ABSL_DCHECK(value != nullptr);
::google::protobuf::internal::TSanWrite(&_impl_);
_internal_mutable_file_to_generate()->Add()->assign(value);
// @@protoc_insertion_point(field_add_char:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate)
}
inline void CodeGeneratorRequest::add_file_to_generate(const char* value, std::size_t size) {
::google::protobuf::internal::TSanWrite(&_impl_);
_internal_mutable_file_to_generate()->Add()->assign(
reinterpret_cast<const char*>(value), size);
// @@protoc_insertion_point(field_add_pointer:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate)
}
inline void CodeGeneratorRequest::add_file_to_generate(absl::string_view value) {
::google::protobuf::internal::TSanWrite(&_impl_);
_internal_mutable_file_to_generate()->Add()->assign(value.data(),
value.size());
// @@protoc_insertion_point(field_add_string_piece:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate)
}
inline const ::google::protobuf::RepeatedPtrField<std::string>&
CodeGeneratorRequest::file_to_generate() const ABSL_ATTRIBUTE_LIFETIME_BOUND {
// @@protoc_insertion_point(field_list:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate)

@ -1075,17 +1075,11 @@ class PROTOBUF_EXPORT SourceCodeInfo_Location final : public ::google::protobuf:
void clear_leading_detached_comments() ;
const std::string& leading_detached_comments(int index) const;
std::string* mutable_leading_detached_comments(int index);
void set_leading_detached_comments(int index, const std::string& value);
void set_leading_detached_comments(int index, std::string&& value);
void set_leading_detached_comments(int index, const char* value);
void set_leading_detached_comments(int index, const char* value, std::size_t size);
void set_leading_detached_comments(int index, absl::string_view value);
template <typename Arg_ = const std::string&, typename... Args_>
void set_leading_detached_comments(int index, Arg_&& value, Args_... args);
std::string* add_leading_detached_comments();
void add_leading_detached_comments(const std::string& value);
void add_leading_detached_comments(std::string&& value);
void add_leading_detached_comments(const char* value);
void add_leading_detached_comments(const char* value, std::size_t size);
void add_leading_detached_comments(absl::string_view value);
template <typename Arg_ = const std::string&, typename... Args_>
void add_leading_detached_comments(Arg_&& value, Args_... args);
const ::google::protobuf::RepeatedPtrField<std::string>& leading_detached_comments() const;
::google::protobuf::RepeatedPtrField<std::string>* mutable_leading_detached_comments();
@ -10043,17 +10037,11 @@ class PROTOBUF_EXPORT EnumDescriptorProto final : public ::google::protobuf::Mes
void clear_reserved_name() ;
const std::string& reserved_name(int index) const;
std::string* mutable_reserved_name(int index);
void set_reserved_name(int index, const std::string& value);
void set_reserved_name(int index, std::string&& value);
void set_reserved_name(int index, const char* value);
void set_reserved_name(int index, const char* value, std::size_t size);
void set_reserved_name(int index, absl::string_view value);
template <typename Arg_ = const std::string&, typename... Args_>
void set_reserved_name(int index, Arg_&& value, Args_... args);
std::string* add_reserved_name();
void add_reserved_name(const std::string& value);
void add_reserved_name(std::string&& value);
void add_reserved_name(const char* value);
void add_reserved_name(const char* value, std::size_t size);
void add_reserved_name(absl::string_view value);
template <typename Arg_ = const std::string&, typename... Args_>
void add_reserved_name(Arg_&& value, Args_... args);
const ::google::protobuf::RepeatedPtrField<std::string>& reserved_name() const;
::google::protobuf::RepeatedPtrField<std::string>* mutable_reserved_name();
@ -10405,17 +10393,11 @@ class PROTOBUF_EXPORT DescriptorProto final : public ::google::protobuf::Message
void clear_reserved_name() ;
const std::string& reserved_name(int index) const;
std::string* mutable_reserved_name(int index);
void set_reserved_name(int index, const std::string& value);
void set_reserved_name(int index, std::string&& value);
void set_reserved_name(int index, const char* value);
void set_reserved_name(int index, const char* value, std::size_t size);
void set_reserved_name(int index, absl::string_view value);
template <typename Arg_ = const std::string&, typename... Args_>
void set_reserved_name(int index, Arg_&& value, Args_... args);
std::string* add_reserved_name();
void add_reserved_name(const std::string& value);
void add_reserved_name(std::string&& value);
void add_reserved_name(const char* value);
void add_reserved_name(const char* value, std::size_t size);
void add_reserved_name(absl::string_view value);
template <typename Arg_ = const std::string&, typename... Args_>
void add_reserved_name(Arg_&& value, Args_... args);
const ::google::protobuf::RepeatedPtrField<std::string>& reserved_name() const;
::google::protobuf::RepeatedPtrField<std::string>* mutable_reserved_name();
@ -10654,17 +10636,11 @@ class PROTOBUF_EXPORT FileDescriptorProto final : public ::google::protobuf::Mes
void clear_dependency() ;
const std::string& dependency(int index) const;
std::string* mutable_dependency(int index);
void set_dependency(int index, const std::string& value);
void set_dependency(int index, std::string&& value);
void set_dependency(int index, const char* value);
void set_dependency(int index, const char* value, std::size_t size);
void set_dependency(int index, absl::string_view value);
template <typename Arg_ = const std::string&, typename... Args_>
void set_dependency(int index, Arg_&& value, Args_... args);
std::string* add_dependency();
void add_dependency(const std::string& value);
void add_dependency(std::string&& value);
void add_dependency(const char* value);
void add_dependency(const char* value, std::size_t size);
void add_dependency(absl::string_view value);
template <typename Arg_ = const std::string&, typename... Args_>
void add_dependency(Arg_&& value, Args_... args);
const ::google::protobuf::RepeatedPtrField<std::string>& dependency() const;
::google::protobuf::RepeatedPtrField<std::string>* mutable_dependency();
@ -11322,8 +11298,7 @@ inline void FileDescriptorProto::clear_dependency() {
::google::protobuf::internal::TSanWrite(&_impl_);
_impl_.dependency_.Clear();
}
inline std::string* FileDescriptorProto::add_dependency()
ABSL_ATTRIBUTE_LIFETIME_BOUND {
inline std::string* FileDescriptorProto::add_dependency() ABSL_ATTRIBUTE_LIFETIME_BOUND {
::google::protobuf::internal::TSanWrite(&_impl_);
std::string* _s = _internal_mutable_dependency()->Add();
// @@protoc_insertion_point(field_add_mutable:google.protobuf.FileDescriptorProto.dependency)
@ -11339,58 +11314,21 @@ inline std::string* FileDescriptorProto::mutable_dependency(int index)
// @@protoc_insertion_point(field_mutable:google.protobuf.FileDescriptorProto.dependency)
return _internal_mutable_dependency()->Mutable(index);
}
inline void FileDescriptorProto::set_dependency(int index, const std::string& value) {
_internal_mutable_dependency()->Mutable(index)->assign(value);
// @@protoc_insertion_point(field_set:google.protobuf.FileDescriptorProto.dependency)
}
inline void FileDescriptorProto::set_dependency(int index, std::string&& value) {
_internal_mutable_dependency()->Mutable(index)->assign(std::move(value));
template <typename Arg_, typename... Args_>
inline void FileDescriptorProto::set_dependency(int index, Arg_&& value, Args_... args) {
::google::protobuf::internal::AssignToString(
*_internal_mutable_dependency()->Mutable(index),
std::forward<Arg_>(value), args... );
// @@protoc_insertion_point(field_set:google.protobuf.FileDescriptorProto.dependency)
}
inline void FileDescriptorProto::set_dependency(int index, const char* value) {
ABSL_DCHECK(value != nullptr);
_internal_mutable_dependency()->Mutable(index)->assign(value);
// @@protoc_insertion_point(field_set_char:google.protobuf.FileDescriptorProto.dependency)
}
inline void FileDescriptorProto::set_dependency(int index, const char* value,
std::size_t size) {
_internal_mutable_dependency()->Mutable(index)->assign(
reinterpret_cast<const char*>(value), size);
// @@protoc_insertion_point(field_set_pointer:google.protobuf.FileDescriptorProto.dependency)
}
inline void FileDescriptorProto::set_dependency(int index, absl::string_view value) {
_internal_mutable_dependency()->Mutable(index)->assign(
value.data(), value.size());
// @@protoc_insertion_point(field_set_string_piece:google.protobuf.FileDescriptorProto.dependency)
}
inline void FileDescriptorProto::add_dependency(const std::string& value) {
::google::protobuf::internal::TSanWrite(&_impl_);
_internal_mutable_dependency()->Add()->assign(value);
// @@protoc_insertion_point(field_add:google.protobuf.FileDescriptorProto.dependency)
}
inline void FileDescriptorProto::add_dependency(std::string&& value) {
template <typename Arg_, typename... Args_>
inline void FileDescriptorProto::add_dependency(Arg_&& value, Args_... args) {
::google::protobuf::internal::TSanWrite(&_impl_);
_internal_mutable_dependency()->Add(std::move(value));
::google::protobuf::internal::AddToRepeatedPtrField(*_internal_mutable_dependency(),
std::forward<Arg_>(value),
args... );
// @@protoc_insertion_point(field_add:google.protobuf.FileDescriptorProto.dependency)
}
inline void FileDescriptorProto::add_dependency(const char* value) {
ABSL_DCHECK(value != nullptr);
::google::protobuf::internal::TSanWrite(&_impl_);
_internal_mutable_dependency()->Add()->assign(value);
// @@protoc_insertion_point(field_add_char:google.protobuf.FileDescriptorProto.dependency)
}
inline void FileDescriptorProto::add_dependency(const char* value, std::size_t size) {
::google::protobuf::internal::TSanWrite(&_impl_);
_internal_mutable_dependency()->Add()->assign(
reinterpret_cast<const char*>(value), size);
// @@protoc_insertion_point(field_add_pointer:google.protobuf.FileDescriptorProto.dependency)
}
inline void FileDescriptorProto::add_dependency(absl::string_view value) {
::google::protobuf::internal::TSanWrite(&_impl_);
_internal_mutable_dependency()->Add()->assign(value.data(),
value.size());
// @@protoc_insertion_point(field_add_string_piece:google.protobuf.FileDescriptorProto.dependency)
}
inline const ::google::protobuf::RepeatedPtrField<std::string>&
FileDescriptorProto::dependency() const ABSL_ATTRIBUTE_LIFETIME_BOUND {
// @@protoc_insertion_point(field_list:google.protobuf.FileDescriptorProto.dependency)
@ -12732,8 +12670,7 @@ inline void DescriptorProto::clear_reserved_name() {
::google::protobuf::internal::TSanWrite(&_impl_);
_impl_.reserved_name_.Clear();
}
inline std::string* DescriptorProto::add_reserved_name()
ABSL_ATTRIBUTE_LIFETIME_BOUND {
inline std::string* DescriptorProto::add_reserved_name() ABSL_ATTRIBUTE_LIFETIME_BOUND {
::google::protobuf::internal::TSanWrite(&_impl_);
std::string* _s = _internal_mutable_reserved_name()->Add();
// @@protoc_insertion_point(field_add_mutable:google.protobuf.DescriptorProto.reserved_name)
@ -12749,58 +12686,21 @@ inline std::string* DescriptorProto::mutable_reserved_name(int index)
// @@protoc_insertion_point(field_mutable:google.protobuf.DescriptorProto.reserved_name)
return _internal_mutable_reserved_name()->Mutable(index);
}
inline void DescriptorProto::set_reserved_name(int index, const std::string& value) {
_internal_mutable_reserved_name()->Mutable(index)->assign(value);
// @@protoc_insertion_point(field_set:google.protobuf.DescriptorProto.reserved_name)
}
inline void DescriptorProto::set_reserved_name(int index, std::string&& value) {
_internal_mutable_reserved_name()->Mutable(index)->assign(std::move(value));
template <typename Arg_, typename... Args_>
inline void DescriptorProto::set_reserved_name(int index, Arg_&& value, Args_... args) {
::google::protobuf::internal::AssignToString(
*_internal_mutable_reserved_name()->Mutable(index),
std::forward<Arg_>(value), args... );
// @@protoc_insertion_point(field_set:google.protobuf.DescriptorProto.reserved_name)
}
inline void DescriptorProto::set_reserved_name(int index, const char* value) {
ABSL_DCHECK(value != nullptr);
_internal_mutable_reserved_name()->Mutable(index)->assign(value);
// @@protoc_insertion_point(field_set_char:google.protobuf.DescriptorProto.reserved_name)
}
inline void DescriptorProto::set_reserved_name(int index, const char* value,
std::size_t size) {
_internal_mutable_reserved_name()->Mutable(index)->assign(
reinterpret_cast<const char*>(value), size);
// @@protoc_insertion_point(field_set_pointer:google.protobuf.DescriptorProto.reserved_name)
}
inline void DescriptorProto::set_reserved_name(int index, absl::string_view value) {
_internal_mutable_reserved_name()->Mutable(index)->assign(
value.data(), value.size());
// @@protoc_insertion_point(field_set_string_piece:google.protobuf.DescriptorProto.reserved_name)
}
inline void DescriptorProto::add_reserved_name(const std::string& value) {
::google::protobuf::internal::TSanWrite(&_impl_);
_internal_mutable_reserved_name()->Add()->assign(value);
// @@protoc_insertion_point(field_add:google.protobuf.DescriptorProto.reserved_name)
}
inline void DescriptorProto::add_reserved_name(std::string&& value) {
template <typename Arg_, typename... Args_>
inline void DescriptorProto::add_reserved_name(Arg_&& value, Args_... args) {
::google::protobuf::internal::TSanWrite(&_impl_);
_internal_mutable_reserved_name()->Add(std::move(value));
::google::protobuf::internal::AddToRepeatedPtrField(*_internal_mutable_reserved_name(),
std::forward<Arg_>(value),
args... );
// @@protoc_insertion_point(field_add:google.protobuf.DescriptorProto.reserved_name)
}
inline void DescriptorProto::add_reserved_name(const char* value) {
ABSL_DCHECK(value != nullptr);
::google::protobuf::internal::TSanWrite(&_impl_);
_internal_mutable_reserved_name()->Add()->assign(value);
// @@protoc_insertion_point(field_add_char:google.protobuf.DescriptorProto.reserved_name)
}
inline void DescriptorProto::add_reserved_name(const char* value, std::size_t size) {
::google::protobuf::internal::TSanWrite(&_impl_);
_internal_mutable_reserved_name()->Add()->assign(
reinterpret_cast<const char*>(value), size);
// @@protoc_insertion_point(field_add_pointer:google.protobuf.DescriptorProto.reserved_name)
}
inline void DescriptorProto::add_reserved_name(absl::string_view value) {
::google::protobuf::internal::TSanWrite(&_impl_);
_internal_mutable_reserved_name()->Add()->assign(value.data(),
value.size());
// @@protoc_insertion_point(field_add_string_piece:google.protobuf.DescriptorProto.reserved_name)
}
inline const ::google::protobuf::RepeatedPtrField<std::string>&
DescriptorProto::reserved_name() const ABSL_ATTRIBUTE_LIFETIME_BOUND {
// @@protoc_insertion_point(field_list:google.protobuf.DescriptorProto.reserved_name)
@ -14388,8 +14288,7 @@ inline void EnumDescriptorProto::clear_reserved_name() {
::google::protobuf::internal::TSanWrite(&_impl_);
_impl_.reserved_name_.Clear();
}
inline std::string* EnumDescriptorProto::add_reserved_name()
ABSL_ATTRIBUTE_LIFETIME_BOUND {
inline std::string* EnumDescriptorProto::add_reserved_name() ABSL_ATTRIBUTE_LIFETIME_BOUND {
::google::protobuf::internal::TSanWrite(&_impl_);
std::string* _s = _internal_mutable_reserved_name()->Add();
// @@protoc_insertion_point(field_add_mutable:google.protobuf.EnumDescriptorProto.reserved_name)
@ -14405,58 +14304,21 @@ inline std::string* EnumDescriptorProto::mutable_reserved_name(int index)
// @@protoc_insertion_point(field_mutable:google.protobuf.EnumDescriptorProto.reserved_name)
return _internal_mutable_reserved_name()->Mutable(index);
}
inline void EnumDescriptorProto::set_reserved_name(int index, const std::string& value) {
_internal_mutable_reserved_name()->Mutable(index)->assign(value);
// @@protoc_insertion_point(field_set:google.protobuf.EnumDescriptorProto.reserved_name)
}
inline void EnumDescriptorProto::set_reserved_name(int index, std::string&& value) {
_internal_mutable_reserved_name()->Mutable(index)->assign(std::move(value));
template <typename Arg_, typename... Args_>
inline void EnumDescriptorProto::set_reserved_name(int index, Arg_&& value, Args_... args) {
::google::protobuf::internal::AssignToString(
*_internal_mutable_reserved_name()->Mutable(index),
std::forward<Arg_>(value), args... );
// @@protoc_insertion_point(field_set:google.protobuf.EnumDescriptorProto.reserved_name)
}
inline void EnumDescriptorProto::set_reserved_name(int index, const char* value) {
ABSL_DCHECK(value != nullptr);
_internal_mutable_reserved_name()->Mutable(index)->assign(value);
// @@protoc_insertion_point(field_set_char:google.protobuf.EnumDescriptorProto.reserved_name)
}
inline void EnumDescriptorProto::set_reserved_name(int index, const char* value,
std::size_t size) {
_internal_mutable_reserved_name()->Mutable(index)->assign(
reinterpret_cast<const char*>(value), size);
// @@protoc_insertion_point(field_set_pointer:google.protobuf.EnumDescriptorProto.reserved_name)
}
inline void EnumDescriptorProto::set_reserved_name(int index, absl::string_view value) {
_internal_mutable_reserved_name()->Mutable(index)->assign(
value.data(), value.size());
// @@protoc_insertion_point(field_set_string_piece:google.protobuf.EnumDescriptorProto.reserved_name)
}
inline void EnumDescriptorProto::add_reserved_name(const std::string& value) {
::google::protobuf::internal::TSanWrite(&_impl_);
_internal_mutable_reserved_name()->Add()->assign(value);
// @@protoc_insertion_point(field_add:google.protobuf.EnumDescriptorProto.reserved_name)
}
inline void EnumDescriptorProto::add_reserved_name(std::string&& value) {
template <typename Arg_, typename... Args_>
inline void EnumDescriptorProto::add_reserved_name(Arg_&& value, Args_... args) {
::google::protobuf::internal::TSanWrite(&_impl_);
_internal_mutable_reserved_name()->Add(std::move(value));
::google::protobuf::internal::AddToRepeatedPtrField(*_internal_mutable_reserved_name(),
std::forward<Arg_>(value),
args... );
// @@protoc_insertion_point(field_add:google.protobuf.EnumDescriptorProto.reserved_name)
}
inline void EnumDescriptorProto::add_reserved_name(const char* value) {
ABSL_DCHECK(value != nullptr);
::google::protobuf::internal::TSanWrite(&_impl_);
_internal_mutable_reserved_name()->Add()->assign(value);
// @@protoc_insertion_point(field_add_char:google.protobuf.EnumDescriptorProto.reserved_name)
}
inline void EnumDescriptorProto::add_reserved_name(const char* value, std::size_t size) {
::google::protobuf::internal::TSanWrite(&_impl_);
_internal_mutable_reserved_name()->Add()->assign(
reinterpret_cast<const char*>(value), size);
// @@protoc_insertion_point(field_add_pointer:google.protobuf.EnumDescriptorProto.reserved_name)
}
inline void EnumDescriptorProto::add_reserved_name(absl::string_view value) {
::google::protobuf::internal::TSanWrite(&_impl_);
_internal_mutable_reserved_name()->Add()->assign(value.data(),
value.size());
// @@protoc_insertion_point(field_add_string_piece:google.protobuf.EnumDescriptorProto.reserved_name)
}
inline const ::google::protobuf::RepeatedPtrField<std::string>&
EnumDescriptorProto::reserved_name() const ABSL_ATTRIBUTE_LIFETIME_BOUND {
// @@protoc_insertion_point(field_list:google.protobuf.EnumDescriptorProto.reserved_name)
@ -19810,8 +19672,7 @@ inline void SourceCodeInfo_Location::clear_leading_detached_comments() {
::google::protobuf::internal::TSanWrite(&_impl_);
_impl_.leading_detached_comments_.Clear();
}
inline std::string* SourceCodeInfo_Location::add_leading_detached_comments()
ABSL_ATTRIBUTE_LIFETIME_BOUND {
inline std::string* SourceCodeInfo_Location::add_leading_detached_comments() ABSL_ATTRIBUTE_LIFETIME_BOUND {
::google::protobuf::internal::TSanWrite(&_impl_);
std::string* _s = _internal_mutable_leading_detached_comments()->Add();
// @@protoc_insertion_point(field_add_mutable:google.protobuf.SourceCodeInfo.Location.leading_detached_comments)
@ -19827,58 +19688,21 @@ inline std::string* SourceCodeInfo_Location::mutable_leading_detached_comments(i
// @@protoc_insertion_point(field_mutable:google.protobuf.SourceCodeInfo.Location.leading_detached_comments)
return _internal_mutable_leading_detached_comments()->Mutable(index);
}
inline void SourceCodeInfo_Location::set_leading_detached_comments(int index, const std::string& value) {
_internal_mutable_leading_detached_comments()->Mutable(index)->assign(value);
// @@protoc_insertion_point(field_set:google.protobuf.SourceCodeInfo.Location.leading_detached_comments)
}
inline void SourceCodeInfo_Location::set_leading_detached_comments(int index, std::string&& value) {
_internal_mutable_leading_detached_comments()->Mutable(index)->assign(std::move(value));
template <typename Arg_, typename... Args_>
inline void SourceCodeInfo_Location::set_leading_detached_comments(int index, Arg_&& value, Args_... args) {
::google::protobuf::internal::AssignToString(
*_internal_mutable_leading_detached_comments()->Mutable(index),
std::forward<Arg_>(value), args... );
// @@protoc_insertion_point(field_set:google.protobuf.SourceCodeInfo.Location.leading_detached_comments)
}
inline void SourceCodeInfo_Location::set_leading_detached_comments(int index, const char* value) {
ABSL_DCHECK(value != nullptr);
_internal_mutable_leading_detached_comments()->Mutable(index)->assign(value);
// @@protoc_insertion_point(field_set_char:google.protobuf.SourceCodeInfo.Location.leading_detached_comments)
}
inline void SourceCodeInfo_Location::set_leading_detached_comments(int index, const char* value,
std::size_t size) {
_internal_mutable_leading_detached_comments()->Mutable(index)->assign(
reinterpret_cast<const char*>(value), size);
// @@protoc_insertion_point(field_set_pointer:google.protobuf.SourceCodeInfo.Location.leading_detached_comments)
}
inline void SourceCodeInfo_Location::set_leading_detached_comments(int index, absl::string_view value) {
_internal_mutable_leading_detached_comments()->Mutable(index)->assign(
value.data(), value.size());
// @@protoc_insertion_point(field_set_string_piece:google.protobuf.SourceCodeInfo.Location.leading_detached_comments)
}
inline void SourceCodeInfo_Location::add_leading_detached_comments(const std::string& value) {
::google::protobuf::internal::TSanWrite(&_impl_);
_internal_mutable_leading_detached_comments()->Add()->assign(value);
// @@protoc_insertion_point(field_add:google.protobuf.SourceCodeInfo.Location.leading_detached_comments)
}
inline void SourceCodeInfo_Location::add_leading_detached_comments(std::string&& value) {
template <typename Arg_, typename... Args_>
inline void SourceCodeInfo_Location::add_leading_detached_comments(Arg_&& value, Args_... args) {
::google::protobuf::internal::TSanWrite(&_impl_);
_internal_mutable_leading_detached_comments()->Add(std::move(value));
::google::protobuf::internal::AddToRepeatedPtrField(*_internal_mutable_leading_detached_comments(),
std::forward<Arg_>(value),
args... );
// @@protoc_insertion_point(field_add:google.protobuf.SourceCodeInfo.Location.leading_detached_comments)
}
inline void SourceCodeInfo_Location::add_leading_detached_comments(const char* value) {
ABSL_DCHECK(value != nullptr);
::google::protobuf::internal::TSanWrite(&_impl_);
_internal_mutable_leading_detached_comments()->Add()->assign(value);
// @@protoc_insertion_point(field_add_char:google.protobuf.SourceCodeInfo.Location.leading_detached_comments)
}
inline void SourceCodeInfo_Location::add_leading_detached_comments(const char* value, std::size_t size) {
::google::protobuf::internal::TSanWrite(&_impl_);
_internal_mutable_leading_detached_comments()->Add()->assign(
reinterpret_cast<const char*>(value), size);
// @@protoc_insertion_point(field_add_pointer:google.protobuf.SourceCodeInfo.Location.leading_detached_comments)
}
inline void SourceCodeInfo_Location::add_leading_detached_comments(absl::string_view value) {
::google::protobuf::internal::TSanWrite(&_impl_);
_internal_mutable_leading_detached_comments()->Add()->assign(value.data(),
value.size());
// @@protoc_insertion_point(field_add_string_piece:google.protobuf.SourceCodeInfo.Location.leading_detached_comments)
}
inline const ::google::protobuf::RepeatedPtrField<std::string>&
SourceCodeInfo_Location::leading_detached_comments() const ABSL_ATTRIBUTE_LIFETIME_BOUND {
// @@protoc_insertion_point(field_list:google.protobuf.SourceCodeInfo.Location.leading_detached_comments)

@ -37,6 +37,7 @@
#include "google/protobuf/message_lite.h"
#include "google/protobuf/port.h"
#include "google/protobuf/repeated_field.h"
#include "google/protobuf/repeated_ptr_field.h"
#include "google/protobuf/wire_format_lite.h"
@ -321,6 +322,59 @@ struct WeakDescriptorDefaultTail {
size_t size;
};
// Tag to distinguish overloads below:
// - if last argument is `BytesTag tag = BytesTag{}` then the overload is
// available to both string and byte fields.
// - if last argument is `BytesTag tag` then the overload is only available to
// byte fields.
// - if there is no BytesTag argument, then the overload is only available to
// string fields.
struct BytesTag {
explicit BytesTag() = default;
};
// Assigns to `dest` the content of `value`, optionally bounded by `size`.
// This overload set is used to implement `set_xxx()` methods for repeated
// string fields in generated code.
inline void AssignToString(std::string& dest, const std::string& value,
BytesTag tag = BytesTag{}) {
dest.assign(value);
}
inline void AssignToString(std::string& dest, std::string&& value,
BytesTag tag = BytesTag{}) {
dest.assign(std::move(value));
}
inline void AssignToString(std::string& dest, const char* value,
BytesTag tag = BytesTag{}) {
dest.assign(value);
}
inline void AssignToString(std::string& dest, const char* value,
std::size_t size) {
dest.assign(value, size);
}
inline void AssignToString(std::string& dest, const void* value,
std::size_t size, BytesTag tag) {
dest.assign(reinterpret_cast<const char*>(value), size);
}
inline void AssignToString(std::string& dest, absl::string_view value,
BytesTag tag = BytesTag{}) {
dest.assign(value.data(), value.size());
}
// Adds `value`, optionally bounded by `size`, as the last element of `dest`.
// This overload set is used to implement `add_xxx()` methods for repeated
// string fields in generated code.
template <typename Arg, typename... Args>
void AddToRepeatedPtrField(google::protobuf::RepeatedPtrField<std::string>& dest,
Arg&& value, Args... args) {
AssignToString(*dest.Add(), std::forward<Arg>(value), args...);
}
inline void AddToRepeatedPtrField(google::protobuf::RepeatedPtrField<std::string>& dest,
std::string&& value,
BytesTag tag = BytesTag{}) {
dest.Add(std::move(value));
}
} // namespace internal
} // namespace protobuf
} // namespace google

Loading…
Cancel
Save