From 2a3dcff682048f3385952261496c44e0548356c0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Reimar=20D=C3=B6ffinger?= Date: Sat, 29 Oct 2016 23:43:01 +0200 Subject: [PATCH] Do not needlessly use Linked variants of HashSet/HashMap. --- .../android/dictionary/DictionaryApplication.java | 12 ++++++------ src/com/hughes/android/dictionary/engine/Index.java | 7 +++---- .../hughes/android/dictionary/engine/Language.java | 4 ++-- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/com/hughes/android/dictionary/DictionaryApplication.java b/src/com/hughes/android/dictionary/DictionaryApplication.java index f23f734..5d1ca0e 100644 --- a/src/com/hughes/android/dictionary/DictionaryApplication.java +++ b/src/com/hughes/android/dictionary/DictionaryApplication.java @@ -53,7 +53,7 @@ import java.io.Serializable; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; -import java.util.LinkedHashMap; +import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; @@ -113,7 +113,7 @@ public class DictionaryApplication extends Application { // Useful: // http://www.loc.gov/standards/iso639-2/php/code_list.php - public static final Map isoCodeToResources = new LinkedHashMap(); + public static final Map isoCodeToResources = new HashMap(); static { isoCodeToResources.put("AF", new LanguageResources("Afrikaans", R.string.AF, R.drawable.flag_of_south_africa)); @@ -282,7 +282,7 @@ public class DictionaryApplication extends Application { // present. final List dictionaryFilesOrdered = new ArrayList(); - final Map uncompressedFilenameToDictionaryInfo = new LinkedHashMap(); + final Map uncompressedFilenameToDictionaryInfo = new HashMap(); /** * Sometimes a deserialized version of this data structure isn't valid. @@ -301,7 +301,7 @@ public class DictionaryApplication extends Application { if (DOWNLOADABLE_UNCOMPRESSED_FILENAME_NAME_TO_DICTIONARY_INFO != null) { return; } - DOWNLOADABLE_UNCOMPRESSED_FILENAME_NAME_TO_DICTIONARY_INFO = new LinkedHashMap(); + DOWNLOADABLE_UNCOMPRESSED_FILENAME_NAME_TO_DICTIONARY_INFO = new HashMap(); final BufferedReader reader = new BufferedReader( new InputStreamReader(context.getResources().openRawResource(R.raw.dictionary_info))); try { @@ -481,7 +481,7 @@ public class DictionaryApplication extends Application { String defaultLangISO2 = Locale.getDefault().getLanguage().toLowerCase(); String defaultLangName = null; - final Map fileToNameCache = new LinkedHashMap(); + final Map fileToNameCache = new HashMap(); public String isoCodeToLocalizedLanguageName(final String isoCode) { final Language.LanguageResources languageResources = isoCodeToResources @@ -716,7 +716,7 @@ public class DictionaryApplication extends Application { final List result = new ArrayList( dictionaryConfig.dictionaryFilesOrdered.size()); - final Map remaining = new LinkedHashMap( + final Map remaining = new HashMap( DOWNLOADABLE_UNCOMPRESSED_FILENAME_NAME_TO_DICTIONARY_INFO); remaining.keySet().removeAll(dictionaryConfig.dictionaryFilesOrdered); for (final DictionaryInfo dictionaryInfo : remaining.values()) { diff --git a/src/com/hughes/android/dictionary/engine/Index.java b/src/com/hughes/android/dictionary/engine/Index.java index 65b8e97..a664ce5 100644 --- a/src/com/hughes/android/dictionary/engine/Index.java +++ b/src/com/hughes/android/dictionary/engine/Index.java @@ -44,8 +44,7 @@ import java.util.Collections; import java.util.Comparator; import java.util.EnumMap; import java.util.HashSet; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; @@ -344,7 +343,7 @@ public final class Index implements RAFSerializable { private static final int MAX_SEARCH_ROWS = 1000; - private final Map prefixToNumRows = new LinkedHashMap(); + private final Map prefixToNumRows = new HashMap(); private synchronized final int getUpperBoundOnRowsStartingWith(final String normalizedPrefix, final int maxRows, final AtomicBoolean interrupted) { @@ -379,7 +378,7 @@ public final class Index implements RAFSerializable { final long startMills = System.currentTimeMillis(); final List result = new ArrayList(); - final Set normalizedNonStoplist = new LinkedHashSet(); + final Set normalizedNonStoplist = new HashSet(); String bestPrefix = null; int leastRows = Integer.MAX_VALUE; diff --git a/src/com/hughes/android/dictionary/engine/Language.java b/src/com/hughes/android/dictionary/engine/Language.java index 007ad4b..48ab242 100644 --- a/src/com/hughes/android/dictionary/engine/Language.java +++ b/src/com/hughes/android/dictionary/engine/Language.java @@ -18,7 +18,7 @@ import com.hughes.android.dictionary.DictionaryApplication; import java.text.Collator; import java.util.Comparator; -import java.util.LinkedHashMap; +import java.util.HashMap; import java.util.Locale; import java.util.Map; import java.util.regex.Pattern; @@ -41,7 +41,7 @@ public class Language { } } - private static final Map registry = new LinkedHashMap(); + private static final Map registry = new HashMap(); final String isoCode; final Locale locale; -- 2.43.0