Java full runtime: Avoid allocating when calling asMap on empty UnknownFieldSet

PiperOrigin-RevId: 631235442
pull/16746/head
Mark Hansen 7 months ago committed by Copybara-Service
parent f597991857
commit d0b016fcfc
  1. 4
      java/core/src/main/java/com/google/protobuf/UnknownFieldSet.java

@ -85,6 +85,10 @@ public final class UnknownFieldSet implements MessageLite {
/** Get a map of fields in the set by number. */
public Map<Integer, Field> asMap() {
// Avoid an allocation for the common case of an empty map.
if (fields.isEmpty()) {
return Collections.emptyMap();
}
return (Map<Integer, Field>) fields.clone();
}

Loading…
Cancel
Save