diff options
author | orelogo <orelogo@gmail.com> | 2017-02-25 17:22:57 -0800 |
---|---|---|
committer | orelogo <orelogo@gmail.com> | 2017-02-25 17:22:57 -0800 |
commit | a1201cc95f4d8b7d8f6ce4a89aa675ee7111ab58 (patch) | |
tree | e3738feeefee6a3e0f779093e0766e8317e103ad /core | |
parent | 352b6747cf8a90e7a17685135e3339f8b011b09a (diff) | |
download | AntennaPod-a1201cc95f4d8b7d8f6ce4a89aa675ee7111ab58.zip |
Improve duplicate removal run time by using a hash set
Diffstat (limited to 'core')
-rw-r--r-- | core/src/main/java/de/danoeh/antennapod/core/storage/FeedSearcher.java | 24 |
1 files changed, 6 insertions, 18 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/FeedSearcher.java b/core/src/main/java/de/danoeh/antennapod/core/storage/FeedSearcher.java index 9d136273c..48e574069 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/FeedSearcher.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/FeedSearcher.java @@ -4,7 +4,9 @@ import android.content.Context; import java.util.ArrayList; import java.util.Collections; +import java.util.HashSet; import java.util.List; +import java.util.Set; import java.util.concurrent.ExecutionException; import java.util.concurrent.FutureTask; @@ -51,15 +53,17 @@ public class FeedSearcher { task.run(); } try { + Set<Long> set = new HashSet<>(); + for (int i = 0; i < tasks.size(); i++) { FutureTask<List<FeedItem>> task = tasks.get(i); List<FeedItem> items = task.get(); for (FeedItem item : items) { - if (result.isEmpty() || !isDuplicate(result, item)) { + if (!set.contains(item.getId())) { // to prevent duplicate results result.add(new SearchResult(item, values[i], subtitles[i])); + set.add(item.getId()); } } - } } catch (InterruptedException | ExecutionException e) { e.printStackTrace(); @@ -67,20 +71,4 @@ public class FeedSearcher { Collections.sort(result, new SearchResultValueComparator()); return result; } - - /** - * Determines if the feed item is already in the search result list. - * - * @param result list of search results - * @param item feed item to validate - * @return true if the feed item is already in the results - */ - private static boolean isDuplicate(List<SearchResult> result, FeedItem item) { - for (SearchResult resultItem : result) { - if (resultItem.getComponent().getId() == item.getId()) { - return true; - } - } - return false; - } } |