Unneeded hashtable in LazyHTMLDocument

Mark Leverentz <[email protected]> 19 Nov 2003 10:15:22 -0600
Newsgroups gmane.comp.java.enhydra.xmlc
Message-ID <[email protected]>
Currently in LazyHTMLDocument, which is currently using a Hashtable, the createElement method will
block on the _elementConstHTML.get() call, since hashtables are synchronized.

Since the map is read-only after it is created, it should be slightly faster to use a HashMap,
as long as you are careful not to access the map before it is finished being created.

The following diff should accomplish this, and offer at least a slight performance boost in
multithreaded situations.

This diff corrects a problem in my previous submission to this list, in that the map now can't be 
accessed until it is completely initialized.

Mark Leverentz


Index: LazyHTMLDocument.java
===================================================================
RCS file: /cvsroot/xmlc/xmlc/xmlc/modules/xmlc/src/org/enhydra/xml/lazydom/html/LazyHTMLDocument.java,v
retrieving revision 1.2
diff -b -r1.2 LazyHTMLDocument.java
92c92
< 
---
> import org.enhydra.apache.html.dom.*;
180,181c180,181
<     private static Hashtable        _elementConstHTML;
< 
---
>     private static HashMap        _elementConstHTML;
>     private static HashMap        _tmpElementConstHTML;
612c612
<         _elementConstHTML = new Hashtable( 63 );
---
>         _tmpElementConstHTML = new HashMap( 63 );
675a676
>         _elementConstHTML = _tmpElementConstHTML;
679c680
<     private static void populateElementType( String tagName, String className )
---
>     private static void populateElementType(String tagName, String className )
683c684
< 	    _elementConstHTML.put( tagName, cl.getConstructor( _elemClassSigHTML ));
---
> 	    _tmpElementConstHTML.put( tagName, cl.getConstructor( _elemClassSigHTML ));