Remove unused proto3 field from UnknownFieldSetSchema.

This should reduce some unnecessary branching off of syntax for ManifestSchemaFactory for CODE_SIZE optimization for full using schemas.

PiperOrigin-RevId: 526039969
pull/12527/head
Sandy Zhang 2 years ago committed by Copybara-Service
parent 408afe1eb4
commit cc7116ceeb
  1. 6
      java/core/src/main/java/com/google/protobuf/ManifestSchemaFactory.java
  2. 18
      java/core/src/main/java/com/google/protobuf/SchemaUtil.java
  3. 6
      java/core/src/main/java/com/google/protobuf/UnknownFieldSetSchema.java

@ -64,7 +64,7 @@ final class ManifestSchemaFactory implements SchemaFactory {
messageInfo.getDefaultInstance());
}
return MessageSetSchema.newSchema(
SchemaUtil.proto2UnknownFieldSetSchema(),
SchemaUtil.unknownFieldSetFullSchema(),
ExtensionSchemas.full(),
messageInfo.getDefaultInstance());
}
@ -98,7 +98,7 @@ final class ManifestSchemaFactory implements SchemaFactory {
messageInfo,
NewInstanceSchemas.full(),
ListFieldSchema.full(),
SchemaUtil.proto2UnknownFieldSetSchema(),
SchemaUtil.unknownFieldSetFullSchema(),
ExtensionSchemas.full(),
MapFieldSchemas.full())
: MessageSchema.newSchema(
@ -106,7 +106,7 @@ final class ManifestSchemaFactory implements SchemaFactory {
messageInfo,
NewInstanceSchemas.full(),
ListFieldSchema.full(),
SchemaUtil.proto3UnknownFieldSetSchema(),
SchemaUtil.unknownFieldSetFullSchema(),
/* extensionSchema= */ null,
MapFieldSchemas.full());
}

@ -44,10 +44,8 @@ import java.util.RandomAccess;
@CheckReturnValue
final class SchemaUtil {
private static final Class<?> GENERATED_MESSAGE_CLASS = getGeneratedMessageClass();
private static final UnknownFieldSchema<?, ?> PROTO2_UNKNOWN_FIELD_SET_SCHEMA =
getUnknownFieldSetSchema(false);
private static final UnknownFieldSchema<?, ?> PROTO3_UNKNOWN_FIELD_SET_SCHEMA =
getUnknownFieldSetSchema(true);
private static final UnknownFieldSchema<?, ?> UNKNOWN_FIELD_SET_FULL_SCHEMA =
getUnknownFieldSetSchema();
private static final UnknownFieldSchema<?, ?> UNKNOWN_FIELD_SET_LITE_SCHEMA =
new UnknownFieldSetLiteSchema();
@ -785,25 +783,21 @@ final class SchemaUtil {
return tableSpaceCost + 3 * tableTimeCost <= lookupSpaceCost + 3 * lookupTimeCost;
}
public static UnknownFieldSchema<?, ?> proto2UnknownFieldSetSchema() {
return PROTO2_UNKNOWN_FIELD_SET_SCHEMA;
}
public static UnknownFieldSchema<?, ?> proto3UnknownFieldSetSchema() {
return PROTO3_UNKNOWN_FIELD_SET_SCHEMA;
public static UnknownFieldSchema<?, ?> unknownFieldSetFullSchema() {
return UNKNOWN_FIELD_SET_FULL_SCHEMA;
}
public static UnknownFieldSchema<?, ?> unknownFieldSetLiteSchema() {
return UNKNOWN_FIELD_SET_LITE_SCHEMA;
}
private static UnknownFieldSchema<?, ?> getUnknownFieldSetSchema(boolean proto3) {
private static UnknownFieldSchema<?, ?> getUnknownFieldSetSchema() {
try {
Class<?> clz = getUnknownFieldSetSchemaClass();
if (clz == null) {
return null;
}
return (UnknownFieldSchema) clz.getConstructor(boolean.class).newInstance(proto3);
return (UnknownFieldSchema) clz.getConstructor().newInstance();
} catch (Throwable t) {
return null;
}

@ -34,11 +34,7 @@ import java.io.IOException;
class UnknownFieldSetSchema extends UnknownFieldSchema<UnknownFieldSet, UnknownFieldSet.Builder> {
private final boolean proto3;
public UnknownFieldSetSchema(boolean proto3) {
this.proto3 = proto3;
}
public UnknownFieldSetSchema() {}
@Override
boolean shouldDiscardUnknownFields(Reader reader) {

Loading…
Cancel
Save