diff --git a/source/net/filebot/similarity/CommonSequenceMatcher.java b/source/net/filebot/similarity/CommonSequenceMatcher.java index f9078ad3..c24aeaf9 100644 --- a/source/net/filebot/similarity/CommonSequenceMatcher.java +++ b/source/net/filebot/similarity/CommonSequenceMatcher.java @@ -81,18 +81,12 @@ public class CommonSequenceMatcher { return getCollationKeys(SPACE.split(sequence)); } - private final Map collationKeyDictionary = synchronizedMap(new HashMap(256)); + private final Map collationKeyDictionary = synchronizedMap(new HashMap(64, 4)); protected CollationKey[] getCollationKeys(String[] words) { - CollationKey[] keys = new CollationKey[words.length]; - for (int i = 0; i < keys.length; i++) { - keys[i] = collationKeyDictionary.get(words[i]); - if (keys[i] == null) { - keys[i] = collator.getCollationKey(words[i]); - collationKeyDictionary.put(words[i], keys[i]); - } - } - return keys; + return stream(words).map(w -> { + return collationKeyDictionary.computeIfAbsent(w, collator::getCollationKey); + }).toArray(CollationKey[]::new); } protected > E[] firstCommonSequence(E[] seq1, E[] seq2, int maxStartIndex, boolean returnFirstMatch) {