Author: j16sdiz
Date: 2008-12-19 13:24:35 +0000 (Fri, 19 Dec 2008)
New Revision: 24587

Modified:
   trunk/freenet/src/freenet/keys/FreenetURI.java
Log:
optimization: combine all stripping
 - FreenetURI(String) is now 15% faster
 - as a side effect, it now accept http://../freenet:CHK@ in additional to 
http://../CHK@ and freenet:CHK@

Modified: trunk/freenet/src/freenet/keys/FreenetURI.java
===================================================================
--- trunk/freenet/src/freenet/keys/FreenetURI.java      2008-12-19 13:24:08 UTC 
(rev 24586)
+++ trunk/freenet/src/freenet/keys/FreenetURI.java      2008-12-19 13:24:35 UTC 
(rev 24587)
@@ -236,19 +236,14 @@
                this.suggestedEdition = suggestedEdition;
        }
 
+       // Strip http:// and freenet: prefix
+       protected final static Pattern URI_PREFIX = 
Pattern.compile("^(http://[^/]+/+)?(freenet:)?");
+       
        public FreenetURI(String URI) throws MalformedURLException {
                if(URI == null)
                        throw new MalformedURLException("No URI specified");
                
                URI = URI.trim();
-               if(URI.startsWith("freenet:"))
-                       URI = URI.substring("freenet:".length());
-
-               // Strip any leading /
-               while(URI.startsWith("/")) {
-                       URI = URI.substring(1);
-               }
-
                if(URI.indexOf('@') < 0 || URI.indexOf('/') < 0)
                        // Encoded URL?
                        try {
@@ -256,10 +251,9 @@
                        } catch(URLEncodedFormatException e) {
                                throw new MalformedURLException("Invalid URI: 
no @ or /, or @ or / is escaped but there are invalid escapes");
                        }
-
-               // Strip http:// prefix
-               URI = URI.replaceFirst("^http://[^/]+/+";, "");
-
+               
+               URI = URI_PREFIX.matcher(URI).replaceFirst("");
+                       
                // decode keyType
                int atchar = URI.indexOf('@');
                if(atchar == -1)
@@ -267,7 +261,7 @@
 
                String _keyType = URI.substring(0, atchar).toUpperCase();
                URI = URI.substring(atchar + 1);
-
+               
                boolean validKeyType = false;
                for(int i = 0; i < VALID_KEY_TYPES.length; i++) {
                        if (_keyType.equals(VALID_KEY_TYPES[i])) {

_______________________________________________
cvs mailing list
[email protected]
http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs

Reply via email to