Avoid iterator allocation in FieldSet.isInitialized

PiperOrigin-RevId: 650814506
pull/17340/head
Mark Hansen 5 months ago committed by Copybara-Service
parent 08a0994f4b
commit 1a18882a5d
  1. 7
      java/core/src/main/java/com/google/protobuf/FieldSet.java

@ -442,12 +442,17 @@ final class FieldSet<T extends FieldSet.FieldDescriptorLite<T>> {
return true; return true;
} }
// Avoid iterator allocation.
@SuppressWarnings({"ForeachList", "ForeachListWithUserVar"})
private static <T extends FieldDescriptorLite<T>> boolean isInitialized( private static <T extends FieldDescriptorLite<T>> boolean isInitialized(
final Map.Entry<T, Object> entry) { final Map.Entry<T, Object> entry) {
final T descriptor = entry.getKey(); final T descriptor = entry.getKey();
if (descriptor.getLiteJavaType() == WireFormat.JavaType.MESSAGE) { if (descriptor.getLiteJavaType() == WireFormat.JavaType.MESSAGE) {
if (descriptor.isRepeated()) { if (descriptor.isRepeated()) {
for (final Object element : (List<?>) entry.getValue()) { List<?> list = (List<?>) entry.getValue();
int listSize = list.size();
for (int i = 0; i < listSize; i++) {
Object element = list.get(i);
if (!isMessageFieldValueInitialized(element)) { if (!isMessageFieldValueInitialized(element)) {
return false; return false;
} }

Loading…
Cancel
Save