Small performance change
David E Jones <[email protected]> Fri, 7 Mar 2003 01:57:22 -0800
| Newsgroups | gmane.comp.java.jpublish.devel |
|---|---|
| Organization | The Open For Business Project |
| Message-ID | <[email protected]> |
This method is called quite a few times, to the point where it is a noticeable amount. It doesn't look like the dynamic new instance is necessary, and a new is much faster, so attached is an alternative. Later, -David Jones
InternalURIParser.java
(text/x-java, 1.3 KB)
package org.jpublish.util;
import java.util.HashMap;
public class InternalURIParser{
private static final InternalURIParser INSTANCE = new InternalURIParser();
//private HashMap uriClasses;
protected InternalURIParser(){
//uriClasses = new HashMap();
//uriClasses.put("template", InternalURI.class);
//uriClasses.put("repository", RepositoryURI.class);
}
public static InternalURIParser getInstance(){
return INSTANCE;
}
public InternalURI parse(String uriString) throws Exception{
int protocolTerminatorIndex = uriString.indexOf(":");
if(protocolTerminatorIndex <= 0){
throw new IllegalArgumentException("URI string is not a valid URI");
}
String protocol = uriString.substring(0, protocolTerminatorIndex);
//Class uriClass = (Class)uriClasses.get(protocol);
//InternalURI uri = (InternalURI)uriClass.newInstance();
InternalURI uri = null;
if ("template".equals(protocol)) {
uri = new InternalURI();
} else if ("repository".equals(protocol)) {
uri = new RepositoryURI();
} else {
return null;
}
uri.setURI(uriString);
return uri;
}
}