Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Unified Diff: third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc

Issue 2495533002: third_party/protobuf: Update to HEAD (83d681ee2c) (Closed)
Patch Set: Make chrome settings proto generated file a component Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc
diff --git a/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc
index 650f0381e5b12462221224231095f499ca3ec35a..240a6e0af19a75e5a140bebaa496626123c4a654 100644
--- a/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc
@@ -80,7 +80,7 @@ int FixedSize(FieldDescriptor::Type type) {
}
void SetPrimitiveVariables(const FieldDescriptor* descriptor,
- map<string, string>* variables,
+ std::map<string, string>* variables,
const Options& options) {
SetCommonFieldVariables(descriptor, variables, options);
(*variables)["type"] = PrimitiveTypeName(descriptor->cpp_type());
@@ -122,14 +122,14 @@ GenerateAccessorDeclarations(io::Printer* printer) const {
void PrimitiveFieldGenerator::
GenerateInlineAccessorDefinitions(io::Printer* printer, bool is_inline) const {
- map<string, string> variables(variables_);
- variables["inline"] = is_inline ? "inline" : "";
+ std::map<string, string> variables(variables_);
+ variables["inline"] = is_inline ? "inline " : "";
printer->Print(variables,
- "$inline$ $type$ $classname$::$name$() const {\n"
+ "$inline$$type$ $classname$::$name$() const {\n"
" // @@protoc_insertion_point(field_get:$full_name$)\n"
" return $name$_;\n"
"}\n"
- "$inline$ void $classname$::set_$name$($type$ value) {\n"
+ "$inline$void $classname$::set_$name$($type$ value) {\n"
" $set_hasbit$\n"
" $name$_ = value;\n"
" // @@protoc_insertion_point(field_set:$full_name$)\n"
@@ -157,12 +157,17 @@ GenerateConstructorCode(io::Printer* printer) const {
}
void PrimitiveFieldGenerator::
+GenerateCopyConstructorCode(io::Printer* printer) const {
+ printer->Print(variables_, "$name$_ = from.$name$_;\n");
+}
+
+void PrimitiveFieldGenerator::
GenerateMergeFromCodedStream(io::Printer* printer) const {
printer->Print(variables_,
+ "$set_hasbit$\n"
"DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<\n"
" $type$, $wire_format_field_type$>(\n"
- " input, &$name$_)));\n"
- "$set_hasbit$\n");
+ " input, &$name$_)));\n");
}
void PrimitiveFieldGenerator::
@@ -206,17 +211,17 @@ PrimitiveOneofFieldGenerator::~PrimitiveOneofFieldGenerator() {}
void PrimitiveOneofFieldGenerator::
GenerateInlineAccessorDefinitions(io::Printer* printer, bool is_inline) const {
- map<string, string> variables(variables_);
- variables["inline"] = is_inline ? "inline" : "";
+ std::map<string, string> variables(variables_);
+ variables["inline"] = is_inline ? "inline " : "";
printer->Print(variables,
- "$inline$ $type$ $classname$::$name$() const {\n"
+ "$inline$$type$ $classname$::$name$() const {\n"
" // @@protoc_insertion_point(field_get:$full_name$)\n"
" if (has_$name$()) {\n"
" return $oneof_prefix$$name$_;\n"
" }\n"
" return $default$;\n"
"}\n"
- "$inline$ void $classname$::set_$name$($type$ value) {\n"
+ "$inline$void $classname$::set_$name$($type$ value) {\n"
" if (!has_$name$()) {\n"
" clear_$oneof_name$();\n"
" set_has_$name$();\n"
@@ -240,7 +245,7 @@ void PrimitiveOneofFieldGenerator::
GenerateConstructorCode(io::Printer* printer) const {
printer->Print(
variables_,
- " $classname$_default_oneof_instance_->$name$_ = $default$;\n");
+ " $classname$_default_oneof_instance_.$name$_ = $default$;\n");
}
void PrimitiveOneofFieldGenerator::
@@ -297,28 +302,28 @@ GenerateAccessorDeclarations(io::Printer* printer) const {
void RepeatedPrimitiveFieldGenerator::
GenerateInlineAccessorDefinitions(io::Printer* printer, bool is_inline) const {
- map<string, string> variables(variables_);
- variables["inline"] = is_inline ? "inline" : "";
+ std::map<string, string> variables(variables_);
+ variables["inline"] = is_inline ? "inline " : "";
printer->Print(variables,
- "$inline$ $type$ $classname$::$name$(int index) const {\n"
+ "$inline$$type$ $classname$::$name$(int index) const {\n"
" // @@protoc_insertion_point(field_get:$full_name$)\n"
" return $name$_.Get(index);\n"
"}\n"
- "$inline$ void $classname$::set_$name$(int index, $type$ value) {\n"
+ "$inline$void $classname$::set_$name$(int index, $type$ value) {\n"
" $name$_.Set(index, value);\n"
" // @@protoc_insertion_point(field_set:$full_name$)\n"
"}\n"
- "$inline$ void $classname$::add_$name$($type$ value) {\n"
+ "$inline$void $classname$::add_$name$($type$ value) {\n"
" $name$_.Add(value);\n"
" // @@protoc_insertion_point(field_add:$full_name$)\n"
"}\n");
printer->Print(variables,
- "$inline$ const ::google::protobuf::RepeatedField< $type$ >&\n"
+ "$inline$const ::google::protobuf::RepeatedField< $type$ >&\n"
"$classname$::$name$() const {\n"
" // @@protoc_insertion_point(field_list:$full_name$)\n"
" return $name$_;\n"
"}\n"
- "$inline$ ::google::protobuf::RepeatedField< $type$ >*\n"
+ "$inline$::google::protobuf::RepeatedField< $type$ >*\n"
"$classname$::mutable_$name$() {\n"
" // @@protoc_insertion_point(field_mutable_list:$full_name$)\n"
" return &$name$_;\n"
@@ -346,11 +351,16 @@ GenerateConstructorCode(io::Printer* printer) const {
}
void RepeatedPrimitiveFieldGenerator::
+GenerateCopyConstructorCode(io::Printer* printer) const {
+ printer->Print(variables_, "$name$_.CopyFrom(from.$name$_);\n");
+}
+
+void RepeatedPrimitiveFieldGenerator::
GenerateMergeFromCodedStream(io::Printer* printer) const {
printer->Print(variables_,
"DO_((::google::protobuf::internal::WireFormatLite::$repeated_reader$<\n"
" $type$, $wire_format_field_type$>(\n"
- " $tag_size$, $tag$, input, this->mutable_$name$())));\n");
+ " $tag_size$, $tag$u, input, this->mutable_$name$())));\n");
}
void RepeatedPrimitiveFieldGenerator::
@@ -420,18 +430,19 @@ void RepeatedPrimitiveFieldGenerator::
GenerateByteSize(io::Printer* printer) const {
printer->Print(variables_,
"{\n"
- " int data_size = 0;\n");
+ " size_t data_size = 0;\n"
+ " unsigned int count = this->$name$_size();\n");
printer->Indent();
int fixed_size = FixedSize(descriptor_->type());
if (fixed_size == -1) {
printer->Print(variables_,
- "for (int i = 0; i < this->$name$_size(); i++) {\n"
+ "for (unsigned int i = 0; i < count; i++) {\n"
" data_size += ::google::protobuf::internal::WireFormatLite::\n"
" $declared_type$Size(this->$name$(i));\n"
"}\n");
} else {
printer->Print(variables_,
- "data_size = $fixed_size$ * this->$name$_size();\n");
+ "data_size = $fixed_size$UL * count;\n");
}
if (descriptor_->is_packed()) {
@@ -440,13 +451,16 @@ GenerateByteSize(io::Printer* printer) const {
" total_size += $tag_size$ +\n"
" ::google::protobuf::internal::WireFormatLite::Int32Size(data_size);\n"
"}\n"
+ "int cached_size = ::google::protobuf::internal::ToCachedSize(data_size);\n"
"GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();\n"
- "_$name$_cached_byte_size_ = data_size;\n"
+ "_$name$_cached_byte_size_ = cached_size;\n"
"GOOGLE_SAFE_CONCURRENT_WRITES_END();\n"
"total_size += data_size;\n");
} else {
printer->Print(variables_,
- "total_size += $tag_size$ * this->$name$_size() + data_size;\n");
+ "total_size += $tag_size$ *\n"
+ " ::google::protobuf::internal::FromIntSize(this->$name$_size());\n"
+ "total_size += data_size;\n");
}
printer->Outdent();
printer->Print("}\n");

Powered by Google App Engine
This is Rietveld 408576698