Skip to content

Commit a1df284

Browse files
committed
Improve find unique performance
1 parent 2dfada2 commit a1df284

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

app/src/main/java/de/kaiserdragon/iconrequest/helper/CommonHelper.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,19 @@ public static void makeToast(String text, Context context) {
2323
public static ArrayList<AppInfo> findUnique(ArrayList<AppInfo> appListAll) {
2424
// Using a LinkedHashSet to maintain insertion order and avoid duplicates
2525
Set<String> seenCodes = new LinkedHashSet<>();
26+
Set<String> duplicateCodes = new LinkedHashSet<>();
2627
ArrayList<AppInfo> newList = new ArrayList<>();
28+
for (AppInfo appInfo : appListAll) {
29+
if(!seenCodes.add(appInfo.getCode())){
30+
duplicateCodes.add(appInfo.getCode());
31+
}
32+
}
2733

2834
for (AppInfo appInfo : appListAll) {
2935
// Check if the code has been seen before
30-
if (seenCodes.add(appInfo.getCode())) {
31-
// If the code is unique, add the appInfo to the newList
32-
newList.add(appInfo);
33-
}else
34-
newList.remove(appInfo);
36+
if (!duplicateCodes.contains(appInfo.getCode())) {
37+
newList.add(appInfo);
38+
}
3539
}
3640

3741
// Return the sorted list of unique AppInfo objects
@@ -78,6 +82,7 @@ public static ArrayList<AppInfo> MissingIcon(ArrayList<AppInfo> appListAll) {
7882
}
7983

8084
public static ArrayList<AppInfo> sort(ArrayList<AppInfo> chaos) {
85+
Log.i("CommonHelper", "Begin sort");
8186
Collections.sort(chaos, (object1, object2) -> {
8287
Locale locale = Locale.getDefault();
8388
Collator collator = Collator.getInstance(locale);

0 commit comments

Comments
 (0)