Remove unnecessary allocation during String field emptiness checks (#7526)
This commit is contained in:
parent
4644980d81
commit
37b18c5f12
@ -3068,6 +3068,14 @@ public abstract class GeneratedMessageV3 extends AbstractMessage
|
||||
return (Extension<MessageType, T>) extension;
|
||||
}
|
||||
|
||||
protected static boolean isStringEmpty(final Object value) {
|
||||
if (value instanceof String) {
|
||||
return ((String) value).isEmpty();
|
||||
} else {
|
||||
return ((ByteString) value).isEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
protected static int computeStringSize(final int fieldNumber, final Object value) {
|
||||
if (value instanceof String) {
|
||||
return CodedOutputStream.computeStringSize(fieldNumber, (String) value);
|
||||
|
@ -80,6 +80,8 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor,
|
||||
" if (value == null) {\n"
|
||||
" throw new NullPointerException();\n"
|
||||
" }\n";
|
||||
(*variables)["isStringEmpty"] = "com.google.protobuf.GeneratedMessage" +
|
||||
GeneratedCodeVersionSuffix() + ".isStringEmpty";
|
||||
(*variables)["writeString"] = "com.google.protobuf.GeneratedMessage" +
|
||||
GeneratedCodeVersionSuffix() + ".writeString";
|
||||
(*variables)["computeStringSize"] = "com.google.protobuf.GeneratedMessage" +
|
||||
@ -117,7 +119,7 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor,
|
||||
(*variables)["clear_has_field_bit_builder"] = "";
|
||||
|
||||
(*variables)["is_field_present_message"] =
|
||||
"!get" + (*variables)["capitalized_name"] + "Bytes().isEmpty()";
|
||||
"!" + (*variables)["isStringEmpty"] + "(" + (*variables)["name"] + "_)";
|
||||
}
|
||||
|
||||
// For repeated builders, one bit is used for whether the array is immutable.
|
||||
|
Loading…
Reference in New Issue
Block a user