Shrink array at most once.

This removes worst-case N^2 behavior, does fewer allocations, and
seems easier to understand. (Admittedly the case where it matters is
probably rare.)

Test: atest PackageManagerTest
Change-Id: I62aa9d84a95a017269953e4e4f4c86e20a5a1838
1 file changed