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

Unified Diff: third_party/protobuf/src/google/protobuf/compiler/java/java_primitive_field_lite.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/java/java_primitive_field_lite.cc
diff --git a/third_party/protobuf/src/google/protobuf/compiler/java/java_primitive_field_lite.cc b/third_party/protobuf/src/google/protobuf/compiler/java/java_primitive_field_lite.cc
index 690dad128fc6e48af36e776350c92e08d70cf33c..ac39f4cf4d751794a416fe1f00065bd5d4f8e23c 100644
--- a/third_party/protobuf/src/google/protobuf/compiler/java/java_primitive_field_lite.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_primitive_field_lite.cc
@@ -61,24 +61,23 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor,
int builderBitIndex,
const FieldGeneratorInfo* info,
ClassNameResolver* name_resolver,
- map<string, string>* variables) {
+ std::map<string, string>* variables) {
SetCommonFieldVariables(descriptor, info, variables);
-
- (*variables)["type"] = PrimitiveTypeName(GetJavaType(descriptor));
- (*variables)["boxed_type"] = BoxedPrimitiveTypeName(GetJavaType(descriptor));
+ JavaType javaType = GetJavaType(descriptor);
+ (*variables)["type"] = PrimitiveTypeName(javaType);
+ (*variables)["boxed_type"] = BoxedPrimitiveTypeName(javaType);
(*variables)["field_type"] = (*variables)["type"];
(*variables)["default"] = ImmutableDefaultValue(descriptor, name_resolver);
- (*variables)["default_init"] = IsDefaultValueJavaDefault(descriptor) ?
- "" : ("= " + ImmutableDefaultValue(descriptor, name_resolver));
(*variables)["capitalized_type"] =
GetCapitalizedType(descriptor, /* immutable = */ true);
- (*variables)["tag"] = SimpleItoa(WireFormat::MakeTag(descriptor));
+ (*variables)["tag"] =
+ SimpleItoa(static_cast<int32>(WireFormat::MakeTag(descriptor)));
(*variables)["tag_size"] = SimpleItoa(
WireFormat::TagSize(descriptor->number(), GetType(descriptor)));
- string capitalized_type = UnderscoresToCamelCase(PrimitiveTypeName(
- GetJavaType(descriptor)), true /* cap_next_letter */);
- switch (GetJavaType(descriptor)) {
+ string capitalized_type = UnderscoresToCamelCase(PrimitiveTypeName(javaType),
+ true /* cap_next_letter */);
+ switch (javaType) {
case JAVATYPE_INT:
case JAVATYPE_LONG:
case JAVATYPE_FLOAT:
@@ -112,7 +111,12 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor,
(*variables)["visit_type_list"] = "visitList";
}
- if (IsReferenceType(GetJavaType(descriptor))) {
+ if (javaType == JAVATYPE_BYTES) {
+ (*variables)["bytes_default"] =
+ ToUpper((*variables)["name"]) + "_DEFAULT_VALUE";
+ }
+
+ if (IsReferenceType(javaType)) {
(*variables)["null_check"] =
" if (value == null) {\n"
" throw new NullPointerException();\n"
@@ -204,6 +208,13 @@ GenerateInterfaceMembers(io::Printer* printer) const {
void ImmutablePrimitiveFieldLiteGenerator::
GenerateMembers(io::Printer* printer) const {
+ if (IsByteStringWithCustomDefaultValue(descriptor_)) {
+ // allocate this once statically since we know ByteStrings are immutable
+ // values that can be reused.
+ printer->Print(
+ variables_,
+ "private static final $field_type$ $bytes_default$ = $default$;\n");
+ }
printer->Print(variables_,
"private $field_type$ $name$_;\n");
PrintExtraFieldInfo(variables_, printer);
@@ -287,7 +298,11 @@ GenerateFieldBuilderInitializationCode(io::Printer* printer) const {
void ImmutablePrimitiveFieldLiteGenerator::
GenerateInitializationCode(io::Printer* printer) const {
- printer->Print(variables_, "$name$_ = $default$;\n");
+ if (IsByteStringWithCustomDefaultValue(descriptor_)) {
+ printer->Print(variables_, "$name$_ = $bytes_default$;\n");
+ } else if (!IsDefaultValueJavaDefault(descriptor_)) {
+ printer->Print(variables_, "$name$_ = $default$;\n");
+ }
}
void ImmutablePrimitiveFieldLiteGenerator::
@@ -817,8 +832,8 @@ GenerateSerializationCode(io::Printer* printer) const {
// That makes it safe to rely on the memoized size here.
printer->Print(variables_,
"if (get$capitalized_name$List().size() > 0) {\n"
- " output.writeRawVarint32($tag$);\n"
- " output.writeRawVarint32($name$MemoizedSerializedSize);\n"
+ " output.writeUInt32NoTag($tag$);\n"
+ " output.writeUInt32NoTag($name$MemoizedSerializedSize);\n"
"}\n"
"for (int i = 0; i < $name$_.size(); i++) {\n"
" output.write$capitalized_type$NoTag($repeated_get$(i));\n"

Powered by Google App Engine
This is Rietveld 408576698