Internal changes/optimizations
PiperOrigin-RevId: 632146543
parent
bc80135f10
commit
85c57193d5
|
@ -53,10 +53,6 @@ public class ExtensionRegistryLite {
|
|||
// applications. Need to support this feature on smaller granularity.
|
||||
private static volatile boolean eagerlyParseMessageSets = false;
|
||||
|
||||
// short circuit the ExtensionRegistryFactory via assumevalues trickery
|
||||
@SuppressWarnings("JavaOptionalSuggestions")
|
||||
private static boolean doFullRuntimeInheritanceCheck = true;
|
||||
|
||||
// Visible for testing.
|
||||
static final String EXTENSION_CLASS_NAME = "com.google.protobuf.Extension";
|
||||
|
||||
|
@ -88,9 +84,9 @@ public class ExtensionRegistryLite {
|
|||
* available.
|
||||
*/
|
||||
public static ExtensionRegistryLite newInstance() {
|
||||
return doFullRuntimeInheritanceCheck
|
||||
? ExtensionRegistryFactory.create()
|
||||
: new ExtensionRegistryLite();
|
||||
return Protobuf.assumeLiteRuntime
|
||||
? new ExtensionRegistryLite()
|
||||
: ExtensionRegistryFactory.create();
|
||||
}
|
||||
|
||||
private static volatile ExtensionRegistryLite emptyRegistry;
|
||||
|
@ -100,7 +96,7 @@ public class ExtensionRegistryLite {
|
|||
* ExtensionRegistry} (if the full (non-Lite) proto libraries are available).
|
||||
*/
|
||||
public static ExtensionRegistryLite getEmptyRegistry() {
|
||||
if (!doFullRuntimeInheritanceCheck) {
|
||||
if (Protobuf.assumeLiteRuntime) {
|
||||
return EMPTY_REGISTRY_LITE;
|
||||
}
|
||||
ExtensionRegistryLite result = emptyRegistry;
|
||||
|
@ -148,7 +144,7 @@ public class ExtensionRegistryLite {
|
|||
if (GeneratedMessageLite.GeneratedExtension.class.isAssignableFrom(extension.getClass())) {
|
||||
add((GeneratedMessageLite.GeneratedExtension<?, ?>) extension);
|
||||
}
|
||||
if (doFullRuntimeInheritanceCheck && ExtensionRegistryFactory.isFullRegistry(this)) {
|
||||
if (!Protobuf.assumeLiteRuntime && ExtensionRegistryFactory.isFullRegistry(this)) {
|
||||
try {
|
||||
this.getClass().getMethod("add", ExtensionClassHolder.INSTANCE).invoke(this, extension);
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -125,6 +125,9 @@ final class ManifestSchemaFactory implements SchemaFactory {
|
|||
};
|
||||
|
||||
private static MessageInfoFactory getDescriptorMessageInfoFactory() {
|
||||
if (Protobuf.assumeLiteRuntime) {
|
||||
return EMPTY_FACTORY;
|
||||
}
|
||||
try {
|
||||
Class<?> clazz = Class.forName("com.google.protobuf.DescriptorMessageInfoFactory");
|
||||
return (MessageInfoFactory) clazz.getDeclaredMethod("getInstance").invoke(null);
|
||||
|
@ -134,6 +137,6 @@ final class ManifestSchemaFactory implements SchemaFactory {
|
|||
}
|
||||
|
||||
private static boolean useLiteRuntime(Class<?> messageType) {
|
||||
return GeneratedMessageLite.class.isAssignableFrom(messageType);
|
||||
return Protobuf.assumeLiteRuntime || GeneratedMessageLite.class.isAssignableFrom(messageType);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,13 @@ import java.util.concurrent.ConcurrentMap;
|
|||
final class Protobuf {
|
||||
private static final Protobuf INSTANCE = new Protobuf();
|
||||
|
||||
// short circuit the full runtime support via assumevalues trickery
|
||||
// this value should only be set to true via AppReduce -assumevalues
|
||||
// directives when doing whole program optimization of Android applications
|
||||
// to enable discarding of full runtime support.
|
||||
@SuppressWarnings("JavaOptionalSuggestions")
|
||||
static boolean assumeLiteRuntime = false;
|
||||
|
||||
private final SchemaFactory schemaFactory;
|
||||
|
||||
// TODO: Consider using ClassValue instead.
|
||||
|
|
Loading…
Reference in New Issue