tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From marcs...@apache.org
Subject cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/util RequestUtil.java
Date Tue, 01 Jul 2003 21:07:43 GMT
marcsaeg    2003/07/01 14:07:43

  Modified:    src/share/org/apache/tomcat/util Tag: tomcat_32
                        RequestUtil.java
  Log:
  Several performance improvements.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.14.2.9  +38 -35    jakarta-tomcat/src/share/org/apache/tomcat/util/Attic/RequestUtil.java
  
  Index: RequestUtil.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/Attic/RequestUtil.java,v
  retrieving revision 1.14.2.8
  retrieving revision 1.14.2.9
  diff -u -r1.14.2.8 -r1.14.2.9
  --- RequestUtil.java	5 Oct 2001 21:03:54 -0000	1.14.2.8
  +++ RequestUtil.java	1 Jul 2003 21:07:43 -0000	1.14.2.9
  @@ -303,9 +303,10 @@
           while (strPos < strLen) {
               int laPos;        // lookahead position
   
  +            char[] ca = str.toCharArray();
               // look ahead to next URLencoded metacharacter, if any
               for (laPos = strPos; laPos < strLen; laPos++) {
  -                char laChar = str.charAt(laPos);
  +                char laChar = ca[laPos];
                   if ((laChar == '+') || (laChar == '%')) {
                       break;
                   }
  @@ -313,7 +314,7 @@
   
               // if there were non-metacharacters, copy them all as a block
               if (laPos > strPos) {
  -                dec.append(str.substring(strPos,laPos));
  +                dec.append(ca, strPos, laPos);
                   strPos = laPos;
               }
   
  @@ -331,7 +332,7 @@
               } else if (metaChar == '%') {
                   char c = (char) Integer.parseInt(str.substring(strPos + 1, strPos + 3),
16);
                   if(c == '/' || c == '%' || c=='.' || c == '\\' || c == '\0')
  -                    dec.append(str.substring(strPos, strPos+3));
  +                    dec.append(ca, strPos, strPos+3);
                   else
                       dec.append(c);
                   strPos += 3;
  @@ -341,40 +342,42 @@
           return dec.toString();
       }
   
  -    public static String unUrlDecode(String data) {
  -	StringBuffer buf = new StringBuffer();
  -	for (int i = 0; i < data.length(); i++) {
  -	    char c = data.charAt(i);
  -	    switch (c) {
  -	    case '+':
  -		buf.append(' ');
  -		break;
  -	    case '%':
  -		// XXX XXX 
  -		try {
  -		    buf.append((char) Integer.parseInt(data.substring(i+1,
  -                        i+3), 16));
  -		    i += 2;
  -		} catch (NumberFormatException e) {
  +    public static String unUrlDecode(String data)
  +    {
  +        StringBuffer buf = new StringBuffer(data.length());
  +        char ca[] = data.toCharArray();
  +        for (int i = 0; i < data.length(); i++) {
  +            char c = ca[i];
  +            switch (c) {
  +            case '+':
  +                buf.append(' ');
  +                break;
  +            case '%':
  +                // XXX XXX 
  +                try {
  +                    buf.append((char) Integer.parseInt(data.substring(i+1,
  +                                                                      i+3), 16));
  +                    i += 2;
  +                } catch (NumberFormatException e) {
                       String msg = "Decode error ";
  -		    // XXX no need to add sm just for that
  -		    // sm.getString("serverRequest.urlDecode.nfe", data);
  +                    // XXX no need to add sm just for that
  +                    // sm.getString("serverRequest.urlDecode.nfe", data);
  +
  +                    throw new IllegalArgumentException(msg);
  +                } catch (StringIndexOutOfBoundsException e) {
  +                    String rest  = data.substring(i);
  +                    buf.append(rest);
  +                    if (rest.length()==2)
  +                        i++;
  +                }
   
  -		    throw new IllegalArgumentException(msg);
  -		} catch (StringIndexOutOfBoundsException e) {
  -		    String rest  = data.substring(i);
  -		    buf.append(rest);
  -		    if (rest.length()==2)
  -			i++;
  -		}
  -		
  -		break;
  -	    default:
  -		buf.append(c);
  -		break;
  -	    }
  -	}
  -	return buf.toString();
  +                break;
  +            default:
  +                buf.append(c);
  +                break;
  +            }
  +        }
  +        return buf.toString();
       }           
   	
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org


Mime
View raw message