Skip to content

Commit

Permalink
Add overload for LazyStringArrayList.add(String): boolean
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mhansen authored and copybara-github committed Jul 8, 2024
1 parent 229c958 commit 761d49a
Showing 1 changed file with 23 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,29 @@ private void add(int index, byte[] element) {
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)
Expand Down Expand Up @@ -197,20 +220,6 @@ public void clear() {
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);
Expand Down

0 comments on commit 761d49a

Please sign in to comment.