Skip to content

Commit

Permalink
Java full runtime: Avoid allocating when calling asMap on empty Unkno…
Browse files Browse the repository at this point in the history
…wnFieldSet

PiperOrigin-RevId: 631235442
  • Loading branch information
mhansen authored and copybara-github committed May 7, 2024
1 parent f597991 commit d0b016f
Showing 1 changed file with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ public int hashCode() {

/** 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();
}

Expand Down

0 comments on commit d0b016f

Please sign in to comment.