Skip to content
Permalink
Browse files

replace 'const std::string&' with 'std::string'(by value)

  • Loading branch information...
reed-lau authored and acozzette committed Aug 7, 2019
1 parent e4c7ead commit c132a4aa165d8ce2b65af62d4bde4a7ce08d07c3
@@ -268,8 +268,7 @@ class PROTOBUF_EXPORT ExtensionSet {
void SetDouble(int number, FieldType type, double value, desc);
void SetBool(int number, FieldType type, bool value, desc);
void SetEnum(int number, FieldType type, int value, desc);
void SetString(int number, FieldType type, const std::string& value, desc);
void SetString(int number, FieldType type, std::string&& value, desc);
void SetString(int number, FieldType type, std::string value, desc);
std::string* MutableString(int number, FieldType type, desc);
MessageLite* MutableMessage(int number, FieldType type,
const MessageLite& prototype, desc);
@@ -332,8 +331,7 @@ class PROTOBUF_EXPORT ExtensionSet {
void SetRepeatedDouble(int number, int index, double value);
void SetRepeatedBool(int number, int index, bool value);
void SetRepeatedEnum(int number, int index, int value);
void SetRepeatedString(int number, int index, const std::string& value);
void SetRepeatedString(int number, int index, std::string&& value);
void SetRepeatedString(int number, int index, std::string value);
std::string* MutableRepeatedString(int number, int index);
MessageLite* MutableRepeatedMessage(int number, int index);

@@ -346,8 +344,7 @@ class PROTOBUF_EXPORT ExtensionSet {
void AddDouble(int number, FieldType type, bool packed, double value, desc);
void AddBool(int number, FieldType type, bool packed, bool value, desc);
void AddEnum(int number, FieldType type, bool packed, int value, desc);
void AddString(int number, FieldType type, const std::string& value, desc);
void AddString(int number, FieldType type, std::string&& value, desc);
void AddString(int number, FieldType type, std::string value, desc);
std::string* AddString(int number, FieldType type, desc);
MessageLite* AddMessage(int number, FieldType type,
const MessageLite& prototype, desc);
@@ -861,32 +858,18 @@ class PROTOBUF_EXPORT ExtensionSet {

// These are just for convenience...
inline void ExtensionSet::SetString(int number, FieldType type,
const std::string& value,
std::string value,
const FieldDescriptor* descriptor) {
MutableString(number, type, descriptor)->assign(value);
}
inline void ExtensionSet::SetString(int number, FieldType type,
std::string&& value,
const FieldDescriptor* descriptor) {
*MutableString(number, type, descriptor) = std::move(value);
}
inline void ExtensionSet::SetRepeatedString(int number, int index,
const std::string& value) {
MutableRepeatedString(number, index)->assign(value);
MutableString(number, type, descriptor)->assign(std::move(value));
}
inline void ExtensionSet::SetRepeatedString(int number, int index,
std::string&& value) {
*MutableRepeatedString(number, index) = std::move(value);
}
inline void ExtensionSet::AddString(int number, FieldType type,
const std::string& value,
const FieldDescriptor* descriptor) {
AddString(number, type, descriptor)->assign(value);
std::string value) {
MutableRepeatedString(number, index)->assign(std::move(value));
}
inline void ExtensionSet::AddString(int number, FieldType type,
std::string&& value,
std::string value,
const FieldDescriptor* descriptor) {
*AddString(number, type, descriptor) = std::move(value);
AddString(number, type, descriptor)->assign(std::move(value));
}
// ===================================================================
// Glue for generated extension accessors
@@ -1191,40 +1191,7 @@ const std::string& Reflection::GetStringReference(const Message& message,


void Reflection::SetString(Message* message, const FieldDescriptor* field,
const std::string& value) const {
USAGE_CHECK_ALL(SetString, SINGULAR, STRING);
if (field->is_extension()) {
return MutableExtensionSet(message)->SetString(field->number(),
field->type(), value, field);
} else {
switch (field->options().ctype()) {
default: // TODO(kenton): Support other string reps.
case FieldOptions::STRING: {
if (IsInlined(field)) {
MutableField<InlinedStringField>(message, field)
->SetNoArena(nullptr, value);
break;
}

const std::string* default_ptr =
&DefaultRaw<ArenaStringPtr>(field).Get();
if (field->containing_oneof() && !HasOneofField(*message, field)) {
ClearOneof(message, field->containing_oneof());
MutableField<ArenaStringPtr>(message, field)
->UnsafeSetDefault(default_ptr);
}
MutableField<ArenaStringPtr>(message, field)
->Mutable(default_ptr, GetArena(message))
->assign(value);
break;
}
}
}
}


void Reflection::SetString(Message* message, const FieldDescriptor* field,
std::string&& value) const {
std::string value) const {
USAGE_CHECK_ALL(SetString, SINGULAR, STRING);
if (field->is_extension()) {
return MutableExtensionSet(message)->SetString(field->number(),
@@ -1235,7 +1202,7 @@ void Reflection::SetString(Message* message, const FieldDescriptor* field,
case FieldOptions::STRING: {
if (IsInlined(field)) {
MutableField<InlinedStringField>(message, field)
->SetNoArena(nullptr, value);
->SetNoArena(nullptr, std::move(value));
break;
}

@@ -1246,8 +1213,8 @@ void Reflection::SetString(Message* message, const FieldDescriptor* field,
MutableField<ArenaStringPtr>(message, field)
->UnsafeSetDefault(default_ptr);
}
*(MutableField<ArenaStringPtr>(message, field)
->Mutable(default_ptr, GetArena(message))) = std::move(value);
MutableField<ArenaStringPtr>(message, field)
->Mutable(default_ptr, GetArena(message))->assign(std::move(value));
break;
}
}
@@ -1288,25 +1255,7 @@ const std::string& Reflection::GetRepeatedStringReference(

void Reflection::SetRepeatedString(Message* message,
const FieldDescriptor* field, int index,
const std::string& value) const {
USAGE_CHECK_ALL(SetRepeatedString, REPEATED, STRING);
if (field->is_extension()) {
MutableExtensionSet(message)->SetRepeatedString(field->number(), index,
value);
} else {
switch (field->options().ctype()) {
default: // TODO(kenton): Support other string reps.
case FieldOptions::STRING:
*MutableRepeatedField<std::string>(message, field, index) = value;
break;
}
}
}


void Reflection::SetRepeatedString(Message* message,
const FieldDescriptor* field, int index,
std::string&& value) const {
std::string value) const {
USAGE_CHECK_ALL(SetRepeatedString, REPEATED, STRING);
if (field->is_extension()) {
MutableExtensionSet(message)->SetRepeatedString(field->number(), index,
@@ -1315,31 +1264,15 @@ void Reflection::SetRepeatedString(Message* message,
switch (field->options().ctype()) {
default: // TODO(kenton): Support other string reps.
case FieldOptions::STRING:
*MutableRepeatedField<std::string>(message, field, index) = std::move(value);
break;
}
}
}

void Reflection::AddString(Message* message, const FieldDescriptor* field,
const std::string& value) const {
USAGE_CHECK_ALL(AddString, REPEATED, STRING);
if (field->is_extension()) {
MutableExtensionSet(message)->AddString(field->number(), field->type(),
value, field);
} else {
switch (field->options().ctype()) {
default: // TODO(kenton): Support other string reps.
case FieldOptions::STRING:
*AddField<std::string>(message, field) = value;
MutableRepeatedField<std::string>(message, field, index)->assign(std::move(value));
break;
}
}
}


void Reflection::AddString(Message* message, const FieldDescriptor* field,
std::string&& value) const {
std::string value) const {
USAGE_CHECK_ALL(AddString, REPEATED, STRING);
if (field->is_extension()) {
MutableExtensionSet(message)->AddString(field->number(), field->type(),
@@ -1348,12 +1281,13 @@ void Reflection::AddString(Message* message, const FieldDescriptor* field,
switch (field->options().ctype()) {
default: // TODO(kenton): Support other string reps.
case FieldOptions::STRING:
*AddField<std::string>(message, field) = std::move(value);
AddField<std::string>(message, field)->assign(std::move(value));
break;
}
}
}


// -------------------------------------------------------------------

const EnumValueDescriptor* Reflection::GetEnum(
@@ -539,9 +539,7 @@ class PROTOBUF_EXPORT Reflection final {
void SetBool(Message* message, const FieldDescriptor* field,
bool value) const;
void SetString(Message* message, const FieldDescriptor* field,
const std::string& value) const;
void SetString(Message* message, const FieldDescriptor* field,
std::string&& value) const;
std::string value) const;
void SetEnum(Message* message, const FieldDescriptor* field,
const EnumValueDescriptor* value) const;
// Set an enum field's value with an integer rather than EnumValueDescriptor.
@@ -641,9 +639,7 @@ class PROTOBUF_EXPORT Reflection final {
void SetRepeatedBool(Message* message, const FieldDescriptor* field,
int index, bool value) const;
void SetRepeatedString(Message* message, const FieldDescriptor* field,
int index, const std::string& value) const;
void SetRepeatedString(Message* message, const FieldDescriptor* field,
int index, std::string&& value) const;
int index, std::string value) const;
void SetRepeatedEnum(Message* message, const FieldDescriptor* field,
int index, const EnumValueDescriptor* value) const;
// Set an enum field's value with an integer rather than EnumValueDescriptor.
@@ -680,9 +676,7 @@ class PROTOBUF_EXPORT Reflection final {
void AddBool(Message* message, const FieldDescriptor* field,
bool value) const;
void AddString(Message* message, const FieldDescriptor* field,
const std::string& value) const;
void AddString(Message* message, const FieldDescriptor* field,
std::string&& value) const;
std::string value) const;
void AddEnum(Message* message, const FieldDescriptor* field,
const EnumValueDescriptor* value) const;
// Add an integer value to a repeated enum field rather than

0 comments on commit c132a4a

Please sign in to comment.
You can’t perform that action at this time.