commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t.@apache.org
Subject svn commit: r1542831 - /commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/bm/PhoneticEngine.java
Date Sun, 17 Nov 2013 21:34:44 GMT
Author: tn
Date: Sun Nov 17 21:34:44 2013
New Revision: 1542831

URL: http://svn.apache.org/r1542831
Log:
[CODEC-174] Improve PhonemeBuilder.apply by updating the internal state instead of creating
a new PhonemeBuilder each time.

Modified:
    commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/bm/PhoneticEngine.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=1542831&r1=1542830&r2=1542831&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
Sun Nov 17 21:34:44 2013
@@ -95,34 +95,34 @@ public class PhoneticEngine {
         }
 
         /**
-         * Creates a new phoneme builder containing the application of the expression to
all phonemes in this builder.
+         * Applies the given phoneme expression to all phonemes in this phoneme builder.
          * <p>
          * This will lengthen phonemes that have compatible language sets to the expression,
and drop those that are
          * incompatible.
          *
          * @param phonemeExpr   the expression to apply
          * @param maxPhonemes   the maximum number of phonemes to build up
-         * @return  a new phoneme builder containing the results of <code>phonemeExpr</code>
applied to each phoneme
-         *      in turn
          */
-        public PhonemeBuilder apply(final Rule.PhonemeExpr phonemeExpr, final int maxPhonemes)
{
-            final Set<Rule.Phoneme> newPhonemes = new LinkedHashSet<Rule.Phoneme>();
+        public void apply(final Rule.PhonemeExpr phonemeExpr, final int maxPhonemes) {
+            final List<Rule.Phoneme> newPhonemes = new ArrayList<Rule.Phoneme>(maxPhonemes);
 
             EXPR: for (final Rule.Phoneme left : this.phonemes) {
                 for (final Rule.Phoneme right : phonemeExpr.getPhonemes()) {
-                    LanguageSet languages = left.getLanguages().restrictTo(right.getLanguages());
+                    final 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 {
-                            break EXPR;
+                            if (newPhonemes.size() >= maxPhonemes) {
+                                break EXPR;
+                            }
                         }
                     }
                 }
             }
 
-            return new PhonemeBuilder(newPhonemes);
+            this.phonemes.clear();
+            this.phonemes.addAll(newPhonemes);
         }
 
         /**
@@ -212,7 +212,7 @@ public class PhoneticEngine {
                     final String pattern = rule.getPattern();
                     patternLength = pattern.length();
                     if (rule.patternAndContextMatches(this.input, this.i)) {
-                        this.phonemeBuilder = this.phonemeBuilder.apply(rule.getPhoneme(),
maxPhonemes);
+                        this.phonemeBuilder.apply(rule.getPhoneme(), maxPhonemes);
                         this.found = true;
                         break;
                     }



Mime
View raw message