[jdom-interest] HashMap/HashSet for attributes/childs

Jason Hunter jhunter at collab.net
Fri Aug 18 10:36:41 PDT 2000


> [ I'm new to this list, so apologize if I'm asking a FAQ; BTW, adding
> a search capability to the archive would be a great plus. ]

Yep, but for now we use what the ISP has.

> Inspecting the source code of Element.java, I've seen that both
> getChild() and getAttribute() iterate over the complete list of
> childs/attributes to find a particular element. Wouldn't it be faster
> to maintain a HashMap/HashSet for that purpose? This would also free
> from implementing the replacement logic in addAttribute() (marked as
> TODO there). Both Map and HashMap are imported but never used.

For getChild() it wouldn't work perfectly well because you'd need to
keep the list around so you could retain order for getMixedContent(),
and that means while you gain efficiency on a by-name lookup you slow
down every add becuase you have to add twice, plus you increase memory
consumption.  Bottom line there is optimizations like that can and
should be done later after performance analysis to make sure they're
beneficial.

For attributes this would make more sense.  I think it's done this way
because by using a List attribute order is preserved, not something
that's needed by XML but something that makes round-tripping possible. 
And considering most elements have 1 attrib and at most 3 it's not a
large performance penalty either.

Once the API is finalized we'll look at the impl and make sure we pick
all the low hanging fruit for performance.

-jh-



More information about the jdom-interest mailing list