Skip to content

Commit fea31ea

Browse files
committed
1 parent 7d7e486 commit fea31ea

2 files changed

Lines changed: 31 additions & 6 deletions

File tree

src/main/java/org/apache/commons/codec/language/bm/Languages.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,13 @@ public LanguageSet restrictTo(final LanguageSet other) {
117117
return this;
118118
} else {
119119
final SomeLanguages sl = (SomeLanguages) other;
120-
if (sl.languages.containsAll(languages)) {
121-
return this;
122-
} else {
123-
final Set<String> ls = new HashSet<String>(this.languages);
124-
ls.retainAll(sl.languages);
125-
return from(ls);
120+
final Set<String> ls = new HashSet<String>(Math.min(languages.size(), sl.languages.size()));
121+
for (String lang : languages) {
122+
if (sl.languages.contains(lang)) {
123+
ls.add(lang);
124+
}
126125
}
126+
return from(ls);
127127
}
128128
}
129129

src/test/java/org/apache/commons/codec/language/bm/PhoneticEnginePerformanceTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,31 @@
9292
* <p>
9393
* Patch applied, committed revision 1539788.
9494
* </p>
95+
* <p>
96+
* Before patch https://issues.apache.org/jira/secure/attachment/12613371/CODEC-174-refactor-restrictTo-method-in-SomeLanguages.patch
97+
* </p>
98+
* <ol>
99+
* <li>Time for encoding 80,000 times the input 'Angelo': 13,133 millis.</li>
100+
* <li>Time for encoding 80,000 times the input 'Angelo': 13,064 millis.</li>
101+
* <li>Time for encoding 80,000 times the input 'Angelo': <b>12,838 millis.</b></li>
102+
* <li>Time for encoding 80,000 times the input 'Angelo': 12,970 millis.</li>
103+
* <li>Time for encoding 80,000 times the input 'Angelo': 13,122 millis.</li>
104+
* <li>Time for encoding 80,000 times the input 'Angelo': 13,293 millis.</li>
105+
* </ol>
106+
* <p>
107+
* After patch https://issues.apache.org/jira/secure/attachment/12613371/CODEC-174-refactor-restrictTo-method-in-SomeLanguages.patch
108+
* </p>
109+
* <ol>
110+
* <li>Time for encoding 80,000 times the input 'Angelo': 11,576 millis.</li>
111+
* <li>Time for encoding 80,000 times the input 'Angelo': 11,506 millis.</li>
112+
* <li>Time for encoding 80,000 times the input 'Angelo': 11,361 millis.</li>
113+
* <li>Time for encoding 80,000 times the input 'Angelo': <b>11,142 millis.</b></li>
114+
* <li>Time for encoding 80,000 times the input 'Angelo': 11,430 millis.</li>
115+
* <li>Time for encoding 80,000 times the input 'Angelo': 11,297 millis.</li>
116+
* </ol>
117+
* <p>
118+
* Patch applied, committed revision 1541234.
119+
* </p>
95120
*/
96121
public class PhoneticEnginePerformanceTest {
97122

0 commit comments

Comments
 (0)