You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by mr...@apache.org on 2004/03/28 18:12:19 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/util URI.java

mrglavas    2004/03/28 08:12:19

  Modified:    java/src/org/apache/xerces/util URI.java
  Log:
  Performance: Reducing the number of characters visited while
  scanning a URI. A URI has a scheme if it contains a ':' which is
  not preceeded by a '?', '/', '#'.  If a ':' has been found in the
  string, we need only search to the left of it instead of over
  the entire string.
  
  Revision  Changes    Path
  1.17      +27 -22    xml-xerces/java/src/org/apache/xerces/util/URI.java
  
  Index: URI.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/util/URI.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- URI.java	24 Feb 2004 23:15:53 -0000	1.16
  +++ URI.java	28 Mar 2004 16:12:19 -0000	1.17
  @@ -454,28 +454,33 @@
       // Check for scheme, which must be before '/', '?' or '#'. Also handle
       // names with DOS drive letters ('D:'), so 1-character schemes are not
       // allowed.
  -    int colonIdx    = uriSpec.indexOf(':');
  -    int slashIdx    = uriSpec.indexOf('/');
  -    int queryIdx    = uriSpec.indexOf('?');
  -    int fragmentIdx = uriSpec.indexOf('#');
  -
  -    if ((colonIdx < 2) ||
  -        (colonIdx > slashIdx && slashIdx != -1) ||
  -        (colonIdx > queryIdx && queryIdx != -1) ||
  -        (colonIdx > fragmentIdx && fragmentIdx != -1)) {
  -      // A standalone base is a valid URI according to spec
  -      if (colonIdx == 0 || (p_base == null && fragmentIdx != 0)) {
  -        throw new MalformedURIException("No scheme found in URI.");
  -      }
  +    int colonIdx = uriSpec.indexOf(':');
  +    if (colonIdx != -1) {
  +        final int searchFrom = colonIdx - 1;
  +        // search backwards starting from character before ':'.
  +        int slashIdx = uriSpec.lastIndexOf('/', searchFrom);
  +        int queryIdx = uriSpec.lastIndexOf('?', searchFrom);
  +        int fragmentIdx = uriSpec.lastIndexOf('#', searchFrom);
  +       
  +        if (colonIdx < 2 || slashIdx != -1 || 
  +            queryIdx != -1 || fragmentIdx != -1) {
  +            // A standalone base is a valid URI according to spec
  +            if (colonIdx == 0 || (p_base == null && fragmentIdx != 0)) {
  +                throw new MalformedURIException("No scheme found in URI.");
  +            }
  +        }
  +        else {
  +            initializeScheme(uriSpec);
  +            index = m_scheme.length()+1;
  +            
  +            // Neither 'scheme:' or 'scheme:#fragment' are valid URIs.
  +            if (colonIdx == uriSpecLen - 1 || uriSpec.charAt(colonIdx+1) == '#') {
  +            	throw new MalformedURIException("Scheme specific part cannot be empty.");	
  +            }
  +        }
       }
  -    else {
  -      initializeScheme(uriSpec);
  -      index = m_scheme.length()+1;
  -      
  -      // Neither 'scheme:' or 'scheme:#fragment' are valid URIs.
  -      if (colonIdx == uriSpecLen - 1 || uriSpec.charAt(colonIdx+1) == '#') {
  -      	throw new MalformedURIException("Scheme specific part cannot be empty.");	
  -      }
  +    else if (p_base == null && uriSpec.indexOf('#') != 0) {
  +        throw new MalformedURIException("No scheme found in URI.");    
       }
   
       // Two slashes means we may have authority, but definitely means we're either
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org