Author: bayard
Date: Tue Oct 24 13:29:44 2006
New Revision: 467467

URL: http://svn.apache.org/viewvc?view=rev&rev=467467
Log:
Applying optimisation from LANG-287. Thanks to Stepan Koltsov and Holger 
Hoffstatte. 

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

Modified: 
jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/Entities.java
URL: 
http://svn.apache.org/viewvc/jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/Entities.java?view=diff&rev=467467&r1=467466&r2=467467
==============================================================================
--- 
jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/Entities.java
 (original)
+++ 
jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/Entities.java
 Tue Oct 24 13:29:44 2006
@@ -811,9 +811,14 @@
      * @return A new escaped <code>String</code>.
      */
     public String unescape(String str) {
+        int firstAmp = str.indexOf('&');
+        if (firstAmp < 0) {
+            return str;
+        }
+
         StringBuffer buf = new StringBuffer(str.length());
-        int i;
-        for (i = 0; i < str.length(); ++i) {
+        buf.append(str.substring(0, firstAmp));
+        for (int i = firstAmp; i < str.length(); ++i) {
             char ch = str.charAt(i);
             if (ch == '&') {
                 int semi = str.indexOf(';', i + 1);
@@ -877,11 +882,15 @@
      * @see Writer
      */
     public void unescape(Writer writer, String string) throws IOException {
-        int len = string.length();
-        if (len == 0) {
+        int firstAmp = string.indexOf('&');
+        if (firstAmp < 0) {
+            writer.write(string);
             return;
         }
-        for (int i = 0; i < len; i++) {
+
+        writer.write(string, 0, firstAmp);
+        int len = string.length();
+        for (int i = firstAmp; i < len; i++) {
             char c = string.charAt(i);
             if (c == '&') {
                 int nextIdx = i+1;



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to