Author: ggregory
Date: Tue Nov 12 21:20:05 2013
New Revision: 1541239
URL: http://svn.apache.org/r1541239
Log:
[CODEC-174] 15% performance gain with this patch from
https://issues.apache.org/jira/secure/attachment/12613371/CODEC-174-refactor-restrictTo-method-in-SomeLanguages.patch.
See test Javadoc.
Modified:
commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/bm/Languages.java
commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/language/bm/PhoneticEnginePerformanceTest.java
Modified:
commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/bm/Languages.java
URL:
http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/bm/Languages.java?rev=1541239&r1=1541238&r2=1541239&view=diff
==============================================================================
---
commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/bm/Languages.java
(original)
+++
commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/bm/Languages.java
Tue Nov 12 21:20:05 2013
@@ -117,13 +117,13 @@ public class Languages {
return this;
} else {
final SomeLanguages sl = (SomeLanguages) other;
- if (sl.languages.containsAll(languages)) {
- return this;
- } else {
- final Set<String> ls = new HashSet<String>(this.languages);
- ls.retainAll(sl.languages);
- return from(ls);
+ final Set<String> ls = new
HashSet<String>(Math.min(languages.size(), sl.languages.size()));
+ for (String lang : languages) {
+ if (sl.languages.contains(lang)) {
+ ls.add(lang);
+ }
}
+ return from(ls);
}
}
Modified:
commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/language/bm/PhoneticEnginePerformanceTest.java
URL:
http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/language/bm/PhoneticEnginePerformanceTest.java?rev=1541239&r1=1541238&r2=1541239&view=diff
==============================================================================
---
commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/language/bm/PhoneticEnginePerformanceTest.java
(original)
+++
commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/language/bm/PhoneticEnginePerformanceTest.java
Tue Nov 12 21:20:05 2013
@@ -92,6 +92,31 @@ import org.junit.Test;
* <p>
* Patch applied, committed revision 1539788.
* </p>
+ * <p>
+ * Before patch
https://issues.apache.org/jira/secure/attachment/12613371/CODEC-174-refactor-restrictTo-method-in-SomeLanguages.patch
+ * </p>
+ * <ol>
+ * <li>Time for encoding 80,000 times the input 'Angelo': 13,133 millis.</li>
+ * <li>Time for encoding 80,000 times the input 'Angelo': 13,064 millis.</li>
+ * <li>Time for encoding 80,000 times the input 'Angelo': <b>12,838
millis.</b></li>
+ * <li>Time for encoding 80,000 times the input 'Angelo': 12,970 millis.</li>
+ * <li>Time for encoding 80,000 times the input 'Angelo': 13,122 millis.</li>
+ * <li>Time for encoding 80,000 times the input 'Angelo': 13,293 millis.</li>
+ * </ol>
+ * <p>
+ * After patch
https://issues.apache.org/jira/secure/attachment/12613371/CODEC-174-refactor-restrictTo-method-in-SomeLanguages.patch
+ * </p>
+ * <ol>
+ * <li>Time for encoding 80,000 times the input 'Angelo': 11,576 millis.</li>
+ * <li>Time for encoding 80,000 times the input 'Angelo': 11,506 millis.</li>
+ * <li>Time for encoding 80,000 times the input 'Angelo': 11,361 millis.</li>
+ * <li>Time for encoding 80,000 times the input 'Angelo': <b>11,142
millis.</b></li>
+ * <li>Time for encoding 80,000 times the input 'Angelo': 11,430 millis.</li>
+ * <li>Time for encoding 80,000 times the input 'Angelo': 11,297 millis.</li>
+ * </ol>
+ * <p>
+ * Patch applied, committed revision 1541234.
+ * </p>
*/
public class PhoneticEnginePerformanceTest {