You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ba...@apache.org on 2008/02/24 04:33:49 UTC

svn commit: r630580 - /commons/proper/lang/trunk/src/java/org/apache/commons/lang/StringUtils.java

Author: bayard
Date: Sat Feb 23 19:33:49 2008
New Revision: 630580

URL: http://svn.apache.org/viewvc?rev=630580&view=rev
Log:
Applying Cedrik Lime's patch to LANG-413; improving the memory footprint of getLevenshteinDistance

Modified:
    commons/proper/lang/trunk/src/java/org/apache/commons/lang/StringUtils.java

Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/StringUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/StringUtils.java?rev=630580&r1=630579&r2=630580&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/StringUtils.java (original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/StringUtils.java Sat Feb 23 19:33:49 2008
@@ -5737,6 +5737,15 @@
             return n;
         }
 
+        if (n > m) {
+            // swap the input strings to consume less memory
+            String tmp = s;
+            s = t;
+            t = tmp;
+            n = m;
+            m = t.length();
+        }
+
         int p[] = new int[n+1]; //'previous' cost array, horizontally
         int d[] = new int[n+1]; // cost array, horizontally
         int _d[]; //placeholder to assist in swapping p and d