aboutsummaryrefslogtreecommitdiff
path: root/src/google/protobuf/compiler/cpp/cpp_string_field.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/google/protobuf/compiler/cpp/cpp_string_field.cc')
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_string_field.cc24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/google/protobuf/compiler/cpp/cpp_string_field.cc b/src/google/protobuf/compiler/cpp/cpp_string_field.cc
index 359e5e26..664a2779 100644
--- a/src/google/protobuf/compiler/cpp/cpp_string_field.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_string_field.cc
@@ -830,12 +830,18 @@ GenerateAccessorDeclarations(io::Printer* printer) const {
"$deprecated_attr$const ::std::string& $name$(int index) const;\n"
"$deprecated_attr$::std::string* mutable_$name$(int index);\n"
"$deprecated_attr$void set_$name$(int index, const ::std::string& value);\n"
+ "#if LANG_CXX11\n"
+ "$deprecated_attr$void set_$name$(int index, ::std::string&& value);\n"
+ "#endif\n"
"$deprecated_attr$void set_$name$(int index, const char* value);\n"
""
"$deprecated_attr$void set_$name$("
"int index, const $pointer_type$* value, size_t size);\n"
"$deprecated_attr$::std::string* add_$name$();\n"
"$deprecated_attr$void add_$name$(const ::std::string& value);\n"
+ "#if LANG_CXX11\n"
+ "$deprecated_attr$void add_$name$(::std::string&& value);\n"
+ "#endif\n"
"$deprecated_attr$void add_$name$(const char* value);\n"
"$deprecated_attr$void add_$name$(const $pointer_type$* value, size_t size)"
";\n"
@@ -869,6 +875,12 @@ GenerateInlineAccessorDefinitions(io::Printer* printer,
" // @@protoc_insertion_point(field_set:$full_name$)\n"
" $name$_.Mutable(index)->assign(value);\n"
"}\n"
+ "#if LANG_CXX11\n"
+ "$inline$void $classname$::set_$name$(int index, ::std::string&& value) {\n"
+ " // @@protoc_insertion_point(field_set:$full_name$)\n"
+ " $name$_.Mutable(index)->assign(std::move(value));\n"
+ "}\n"
+ "#endif\n"
"$inline$void $classname$::set_$name$(int index, const char* value) {\n"
" $name$_.Mutable(index)->assign(value);\n"
" // @@protoc_insertion_point(field_set_char:$full_name$)\n"
@@ -888,6 +900,12 @@ GenerateInlineAccessorDefinitions(io::Printer* printer,
" $name$_.Add()->assign(value);\n"
" // @@protoc_insertion_point(field_add:$full_name$)\n"
"}\n"
+ "#if LANG_CXX11\n"
+ "$inline$void $classname$::add_$name$(::std::string&& value) {\n"
+ " $name$_.Add()->assign(std::move(value));\n"
+ " // @@protoc_insertion_point(field_add:$full_name$)\n"
+ "}\n"
+ "#endif\n"
"$inline$void $classname$::add_$name$(const char* value) {\n"
" $name$_.Add()->assign(value);\n"
" // @@protoc_insertion_point(field_add_char:$full_name$)\n"
@@ -951,7 +969,7 @@ GenerateMergeFromCodedStream(io::Printer* printer) const {
void RepeatedStringFieldGenerator::
GenerateSerializeWithCachedSizes(io::Printer* printer) const {
printer->Print(variables_,
- "for (int i = 0; i < this->$name$_size(); i++) {\n");
+ "for (int i = 0, n = this->$name$_size(); i < n; i++) {\n");
printer->Indent();
if (descriptor_->type() == FieldDescriptor::TYPE_STRING) {
GenerateUtf8CheckCodeForString(
@@ -968,7 +986,7 @@ GenerateSerializeWithCachedSizes(io::Printer* printer) const {
void RepeatedStringFieldGenerator::
GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const {
printer->Print(variables_,
- "for (int i = 0; i < this->$name$_size(); i++) {\n");
+ "for (int i = 0, n = this->$name$_size(); i < n; i++) {\n");
printer->Indent();
if (descriptor_->type() == FieldDescriptor::TYPE_STRING) {
GenerateUtf8CheckCodeForString(
@@ -987,7 +1005,7 @@ GenerateByteSize(io::Printer* printer) const {
printer->Print(variables_,
"total_size += $tag_size$ *\n"
" ::google::protobuf::internal::FromIntSize(this->$name$_size());\n"
- "for (int i = 0; i < this->$name$_size(); i++) {\n"
+ "for (int i = 0, n = this->$name$_size(); i < n; i++) {\n"
" total_size += ::google::protobuf::internal::WireFormatLite::$declared_type$Size(\n"
" this->$name$(i));\n"
"}\n");