Skip to content

Commit

Permalink
Cap number of items we attempt to collapse
Browse files Browse the repository at this point in the history
Cap number of items we attempt to collapse at 20. Algorithm used is n^2
and introduces noticeable delays with eg 70 phone numbers for a single contact.

Bug:8888517
Change-Id: Ifaa470a3dd91b783db23d5c694af4529cfbf1293
  • Loading branch information
Jay Shrauner committed May 16, 2013
1 parent 26752ac commit e1348a4
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/com/android/contacts/common/Collapser.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ public final class Collapser {
*/
private Collapser() {}

/*
* The Collapser uses an n^2 algorithm so we don't want it to run on
* lists beyond a certain size. This specifies the maximum size to collapse.
*/
private static final int MAX_LISTSIZE_TO_COLLAPSE = 20;

/*
* Interface implemented by data types that can be collapsed into groups of similar data. This
* can be used for example to collapse similar contact data items into a single item.
Expand All @@ -51,6 +57,10 @@ public interface Collapsible<T> {
public static <T extends Collapsible<T>> void collapseList(List<T> list) {

int listSize = list.size();
// The algorithm below is n^2 so don't run on long lists
if (listSize > MAX_LISTSIZE_TO_COLLAPSE) {
return;
}

for (int i = 0; i < listSize; i++) {
T iItem = list.get(i);
Expand Down

0 comments on commit e1348a4

Please sign in to comment.