Short-circuit the second instanceof check in addAllCheckingNulls

If the first check passed (we're an ArrayList) then we aren't a ProtobufArrayList, and there's no point checking.

Micro-optimisation.

PiperOrigin-RevId: 683793700
pull/18682/head
Mark Hansen 2 months ago committed by Copybara-Service
parent 429a93d5fd
commit 4e44304dee
  1. 3
      java/core/src/main/java/com/google/protobuf/AbstractMessageLite.java

@ -344,8 +344,7 @@ public abstract class AbstractMessageLite<
int growth = ((Collection<T>) values).size();
if (list instanceof ArrayList) {
((ArrayList<T>) list).ensureCapacity(list.size() + growth);
}
if (list instanceof ProtobufArrayList) {
} else if (list instanceof ProtobufArrayList) {
((ProtobufArrayList<T>) list).ensureCapacity(list.size() + growth);
}
}

Loading…
Cancel
Save