[jdom-interest] AttributeList performance

Victor Toni victor.toni at ebuconnect.de
Wed Apr 27 15:15:56 PDT 2005


The performance depends also very much on the use case.
I wonder if an iterator was used for accessing the attributes or e.g. 
Element.getAttribute(name) which would be a good example for "Shlemiel 
the painter's algorithm".

//IMHO the hashCode() of Attribute may be improved for different use 
cases by _really_ creating a hash.

Maybe something like this (which could be still optimized if called often):

    public final int hashCode() {
        return name.hashCode() * 29 + namespace.hashCode();
    }

By creating hashes in this manner one could use a HashMap for fast 
random access by name because binary search will work in a sane way.

Actually I would suggest an additional class for qualified names 
encapsulating name and namespace. (I would even step forward :-)
It could be used to represent the element's name and namespace, too and 
reduce code size as an additional benefit.
BTW, hashCode() for Element would also profit ;-)

Kindest regards,
Victor


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.jdom.org/pipermail/jdom-interest/attachments/20050428/ff79322e/attachment.htm


More information about the jdom-interest mailing list