Re: Small performance change
Anthony Eden <[email protected]> Fri, 07 Mar 2003 09:50:25 -0500
| Newsgroups | gmane.comp.java.jpublish.devel |
|---|---|
| Message-ID | <[email protected]> |
The idea of having a map of classes was to support the addition of new URI types without having to change the code. However if you are showing a significant performance hit because of it I will modify the code to match your patch.
-Anthony
David E Jones wrote:
> 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
>
>
> ------------------------------------------------------------------------
>
> 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;
> }
>
> }
-------------------------------------------------------
This SF.net email is sponsored by: Etnus, makers of TotalView, The debugger
for complex code. Debugging C/C++ programs can leave you feeling lost and
disoriented. TotalView can help you find your way. Available on major UNIX
and Linux platforms. Try it free. www.etnus.com