commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1539788 - in /commons/proper/codec/trunk/src: main/java/org/apache/commons/codec/language/bm/ test/java/org/apache/commons/codec/language/bm/
Date Thu, 07 Nov 2013 20:11:23 GMT
Author: ggregory
Date: Thu Nov  7 20:11:23 2013
New Revision: 1539788

URL: http://svn.apache.org/r1539788
Log:
[CODEC-174] Apply patch https://issues.apache.org/jira/secure/attachment/12612178/CODEC-174-reuse-set-in-PhonemeBuilder.patch.
Thanks to Thomas Champagne.

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
    commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/language/bm/PhoneticEnginePerformanceTest.java
    commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/language/bm/RuleTest.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=1539788&r1=1539787&r2=1539788&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
Thu Nov  7 20:11:23 2013
@@ -66,12 +66,17 @@ public class PhoneticEngine {
          * @return  a new, empty phoneme builder
          */
         public static PhonemeBuilder empty(final Languages.LanguageSet languages) {
-            return new PhonemeBuilder(Collections.singleton(new Rule.Phoneme("", languages)));
+            return new PhonemeBuilder(new Rule.Phoneme("", languages));
         }
 
         private final Set<Rule.Phoneme> phonemes;
 
-        private PhonemeBuilder(final Set<Rule.Phoneme> phonemes) {
+        private PhonemeBuilder(Rule.Phoneme phoneme) {
+            this.phonemes = new LinkedHashSet<Rule.Phoneme>();
+            this.phonemes.add(phoneme);
+        }
+        
+        private PhonemeBuilder(Set<Rule.Phoneme> phonemes) {
             this.phonemes = phonemes;
         }
 
@@ -81,14 +86,10 @@ public class PhoneticEngine {
          * @param str   the characters to append to the phonemes
          * @return  a new phoneme builder lenghtened by <code>str</code>
          */
-        public PhonemeBuilder append(final CharSequence str) {
-            final Set<Rule.Phoneme> newPhonemes = new LinkedHashSet<Rule.Phoneme>();
-
+        public void append(final CharSequence str) {
             for (final Rule.Phoneme ph : this.phonemes) {
-                newPhonemes.add(ph.append(str));
+            	ph.append(str);
             }
-
-            return new PhonemeBuilder(newPhonemes);
         }
 
         /**
@@ -380,7 +381,7 @@ public class PhoneticEngine {
 
                 if (!found) {
                     // not found, appending as-is
-                    subBuilder = subBuilder.append(phonemeText.subSequence(i, i + 1));
+                    subBuilder.append(phonemeText.subSequence(i, i + 1));
                 }
 
                 i = rulesApplication.getI();

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=1539788&r1=1539787&r2=1539788&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
Thu Nov  7 20:11:23 2013
@@ -101,16 +101,22 @@ public class Rule {
             }
         };
 
-        private final CharSequence phonemeText;
+        private final StringBuilder phonemeText;
         private final Languages.LanguageSet languages;
 
         public Phoneme(final CharSequence phonemeText, final Languages.LanguageSet languages)
{
-            this.phonemeText = phonemeText;
+            this.phonemeText = new StringBuilder(phonemeText);
             this.languages = languages;
         }
+        
+        public Phoneme(final Phoneme phonemeLeft, final Phoneme phonemeRight) {
+        	this.phonemeText = new StringBuilder(phonemeLeft.phonemeText);
+        	this.phonemeText.append(phonemeRight.phonemeText);
+        	this.languages = phonemeLeft.languages;
+        }
 
-        public Phoneme append(final CharSequence str) {
-            return new Phoneme(this.phonemeText.toString() + str.toString(), this.languages);
+        public void append(final CharSequence str) {
+        	this.phonemeText.append(str);
         }
 
         public Languages.LanguageSet getLanguages() {

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=1539788&r1=1539787&r2=1539788&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
Thu Nov  7 20:11:23 2013
@@ -76,6 +76,22 @@ import org.junit.Test;
  * <p>
  * Patch not applied.
  * </p>
+ * <p>
+ * On this file's revision 1539787, with patch <a
+ * href="https://issues.apache.org/jira/secure/attachment/12612178/CODEC-174-reuse-set-in-PhonemeBuilder.patch"
+ * >CODEC-174-reuse-set-in-PhonemeBuilder.patch</a>:
+ * </p>
+ * <ol>
+ * <li>Time for encoding 80,000 times the input 'Angelo': 13,724 millis.</li>
+ * <li>Time for encoding 80,000 times the input 'Angelo': 13,451 millis.</li>
+ * <li>Time for encoding 80,000 times the input 'Angelo': 13,742 millis.</li>
+ * <li>Time for encoding 80,000 times the input 'Angelo': 13,186 millis.</li>
+ * <li>Time for encoding 80,000 times the input 'Angelo': 13,600 millis.</li>
+ * <li>Time for encoding 80,000 times the input 'Angelo': 16,405 millis.</li>
+ * </ol>
+ * <p>
+ * 
+ * </p>
  */
 public class PhoneticEnginePerformanceTest {
 

Modified: commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/language/bm/RuleTest.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/language/bm/RuleTest.java?rev=1539788&r1=1539787&r2=1539788&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/language/bm/RuleTest.java
(original)
+++ commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/language/bm/RuleTest.java
Thu Nov  7 20:11:23 2013
@@ -107,14 +107,14 @@ public class RuleTest {
         assertEquals('k', jkl.getPhonemeText().charAt(1));
         assertEquals('l', jkl.getPhonemeText().charAt(2));
 
-        final Rule.Phoneme a_b = a.append(b.getPhonemeText());
+        final Rule.Phoneme a_b = new Rule.Phoneme(a, b);
         assertEquals('a', a_b.getPhonemeText().charAt(0));
         assertEquals('b', a_b.getPhonemeText().charAt(1));
         assertEquals("ab", a_b.getPhonemeText().subSequence(0, 2).toString());
         assertEquals("a", a_b.getPhonemeText().subSequence(0, 1).toString());
         assertEquals("b", a_b.getPhonemeText().subSequence(1, 2).toString());
 
-        final Rule.Phoneme cd_ef = cd.append(ef.getPhonemeText());
+        final Rule.Phoneme cd_ef = new Rule.Phoneme(cd, ef);
         assertEquals('c', cd_ef.getPhonemeText().charAt(0));
         assertEquals('d', cd_ef.getPhonemeText().charAt(1));
         assertEquals('e', cd_ef.getPhonemeText().charAt(2));
@@ -130,7 +130,7 @@ public class RuleTest {
         assertEquals("def", cd_ef.getPhonemeText().subSequence(1, 4).toString());
         assertEquals("cdef", cd_ef.getPhonemeText().subSequence(0, 4).toString());
 
-        final Rule.Phoneme a_b_cd = a.append(b.getPhonemeText()).append(cd.getPhonemeText());
+        final Rule.Phoneme a_b_cd = new Rule.Phoneme(new Rule.Phoneme(a, b), cd);
         assertEquals('a', a_b_cd.getPhonemeText().charAt(0));
         assertEquals('b', a_b_cd.getPhonemeText().charAt(1));
         assertEquals('c', a_b_cd.getPhonemeText().charAt(2));



Mime
View raw message