commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1541234 - in /commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/bm: PhoneticEngine.java Rule.java
Date Tue, 12 Nov 2013 21:06:12 GMT
Author: ggregory
Date: Tue Nov 12 21:06:11 2013
New Revision: 1541234

URL: http://svn.apache.org/r1541234
Log:
[CODEC-174] Small (4-5%) but consistent performance gain with this patch from https://issues.apache.org/jira/secure/attachment/12613346/CODEC-174-refactor-join-method-in-Phoneme.patch

Modified:
    commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/bm/PhoneticEngine.java
    commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/bm/Rule.java

Modified: commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/bm/PhoneticEngine.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/bm/PhoneticEngine.java?rev=1541234&r1=1541233&r2=1541234&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/bm/PhoneticEngine.java
(original)
+++ commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/bm/PhoneticEngine.java
Tue Nov 12 21:06:11 2013
@@ -30,6 +30,9 @@ import java.util.Map;
 import java.util.Set;
 import java.util.TreeSet;
 
+import org.apache.commons.codec.language.bm.Languages.LanguageSet;
+import org.apache.commons.codec.language.bm.Rule.Phoneme;
+
 /**
  * Converts words into potential phonetic representations.
  * <p>
@@ -107,8 +110,9 @@ public class PhoneticEngine {
 
             EXPR: for (final Rule.Phoneme left : this.phonemes) {
                 for (final Rule.Phoneme right : phonemeExpr.getPhonemes()) {
-                    final Rule.Phoneme join = left.join(right);
-                    if (!join.getLanguages().isEmpty()) {
+                	LanguageSet languages = left.getLanguages().restrictTo(right.getLanguages());
+                	if (!languages.isEmpty()) {
+                		final Rule.Phoneme join = new Phoneme(left, right, languages);
                         if (newPhonemes.size() < maxPhonemes) {
                             newPhonemes.add(join);
                         } else {

Modified: commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/bm/Rule.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/bm/Rule.java?rev=1541234&r1=1541233&r2=1541234&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/bm/Rule.java
(original)
+++ commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/bm/Rule.java
Tue Nov 12 21:06:11 2013
@@ -110,9 +110,13 @@ public class Rule {
         }
         
         public Phoneme(final Phoneme phonemeLeft, final Phoneme phonemeRight) {
-            this.phonemeText = new StringBuilder(phonemeLeft.phonemeText);
+            this(phonemeLeft.phonemeText, phonemeLeft.languages);
+            this.phonemeText.append(phonemeRight.phonemeText);
+        }
+
+        public Phoneme(final Phoneme phonemeLeft, final Phoneme phonemeRight, final Languages.LanguageSet
languages) {
+            this(phonemeLeft.phonemeText, languages);
             this.phonemeText.append(phonemeRight.phonemeText);
-            this.languages = phonemeLeft.languages;
         }
 
         public Phoneme  append(final CharSequence str) {
@@ -132,11 +136,6 @@ public class Rule {
         public CharSequence getPhonemeText() {
             return this.phonemeText;
         }
-
-        public Phoneme join(final Phoneme right) {
-            return new Phoneme(this.phonemeText.toString() + right.phonemeText.toString(),
-                               this.languages.restrictTo(right.languages));
-        }
     }
 
     public interface PhonemeExpr {



Mime
View raw message