-
Notifications
You must be signed in to change notification settings - Fork 15.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
C++ Add move constructor for Reflection's SetString #6477
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1223,6 +1223,38 @@ void Reflection::SetString(Message* message, const FieldDescriptor* field, | |
} | ||
|
||
|
||
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also here i believe the value parameter (i.e. the input string) should be moved, so:
|
||
} 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))) = value; | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
std::string Reflection::GetRepeatedString(const Message& message, | ||
const FieldDescriptor* field, | ||
int index) const { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@reed-lau rvalue references cannot be const as they cannot be moved. The overloaded functions rvalue parameter should be SetString(..,..,std::string&& value) without the const!