Skip to content

Commit

Permalink
Down integrate to GitHub
Browse files Browse the repository at this point in the history
  • Loading branch information
Hao Nguyen committed Jun 11, 2019
1 parent 6153f80 commit 09cab82
Show file tree
Hide file tree
Showing 64 changed files with 1,794 additions and 2,012 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public FieldDescriptor getOneofFieldDescriptor(OneofDescriptor oneof) {

@Override
public final String toString() {
return TextFormat.printToString(this);
return TextFormat.printer().printToString(this);
}

@Override
Expand Down Expand Up @@ -468,7 +468,7 @@ public Message.Builder getRepeatedFieldBuilder(final FieldDescriptor field, int

@Override
public String toString() {
return TextFormat.printToString(this);
return TextFormat.printer().printToString(this);
}

/** Construct an UninitializedMessageException reporting missing fields in the given message. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ 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";

Expand Down Expand Up @@ -107,7 +111,9 @@ public static void setEagerlyParseMessageSets(boolean isEagerlyParse) {
* available.
*/
public static ExtensionRegistryLite newInstance() {
return ExtensionRegistryFactory.create();
return doFullRuntimeInheritanceCheck
? ExtensionRegistryFactory.create()
: new ExtensionRegistryLite();
}

private static volatile ExtensionRegistryLite emptyRegistry;
Expand All @@ -122,7 +128,11 @@ public static ExtensionRegistryLite getEmptyRegistry() {
synchronized (ExtensionRegistryLite.class) {
result = emptyRegistry;
if (result == null) {
result = emptyRegistry = ExtensionRegistryFactory.createEmpty();
result =
emptyRegistry =
doFullRuntimeInheritanceCheck
? ExtensionRegistryFactory.createEmpty()
: EMPTY_REGISTRY_LITE;
}
}
}
Expand Down Expand Up @@ -163,7 +173,7 @@ public final void add(ExtensionLite<?, ?> extension) {
if (GeneratedMessageLite.GeneratedExtension.class.isAssignableFrom(extension.getClass())) {
add((GeneratedMessageLite.GeneratedExtension<?, ?>) extension);
}
if (ExtensionRegistryFactory.isFullRegistry(this)) {
if (doFullRuntimeInheritanceCheck && ExtensionRegistryFactory.isFullRegistry(this)) {
try {
this.getClass().getMethod("add", extensionClass).invoke(this, extension);
} catch (Exception e) {
Expand Down
2 changes: 1 addition & 1 deletion java/core/src/main/java/com/google/protobuf/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public interface Message extends MessageLite, MessageOrBuilder {

/**
* Converts the message to a string in protocol buffer text format. This is just a trivial wrapper
* around {@link TextFormat#printToString(MessageOrBuilder)}.
* around {@link TextFormat.Printer#printToString(MessageOrBuilder)}.
*/
@Override
String toString();
Expand Down
Loading

0 comments on commit 09cab82

Please sign in to comment.