Add overload for LazyStringArrayList.add(String): boolean

This is a performance optimisation that avoids us going through from
AbstractList.add(E) to LazyStringArrayList.add(int index, String) and then
having to call the index-based add in ArrayList, which has more bookkeeping
around moving elements across if necessary.

We can avoid that bookkeeping by adding this overload.

Also, group together overloads to squash a style warning.

PiperOrigin-RevId: 650089286
pull/17337/head
Mark Hansen 8 months ago committed by Copybara-Service
parent 229c958a5c
commit 761d49a270
  1. 37
      java/core/src/main/java/com/google/protobuf/LazyStringArrayList.java

@ -145,6 +145,29 @@ public class LazyStringArrayList extends AbstractProtobufList<String>
modCount++;
}
@Override
@CanIgnoreReturnValue
public boolean add(String element) {
ensureIsMutable();
list.add(element);
modCount++;
return true;
}
@Override
public void add(ByteString element) {
ensureIsMutable();
list.add(element);
modCount++;
}
@Override
public void add(byte[] element) {
ensureIsMutable();
list.add(element);
modCount++;
}
@Override
public boolean addAll(Collection<? extends String> c) {
// The default implementation of AbstractCollection.addAll(Collection)
@ -197,20 +220,6 @@ public class LazyStringArrayList extends AbstractProtobufList<String>
modCount++;
}
@Override
public void add(ByteString element) {
ensureIsMutable();
list.add(element);
modCount++;
}
@Override
public void add(byte[] element) {
ensureIsMutable();
list.add(element);
modCount++;
}
@Override
public Object getRaw(int index) {
return list.get(index);

Loading…
Cancel
Save