[jdom-interest] non-deterministic behaviour [eg]

Jason Hunter jhunter at collab.net
Wed Apr 11 14:10:47 PDT 2001

Jools wrote:
> > In this specific example, since setMixedContent() does a full content
> > replacement, it'd be just as efficient code-wise to keep the original
> > list data and restore it in event of an illegal add.  It seems a worthy
> > thing to do.
> In this instance I'd have to agree.

Are you surprised?  We almost always agree.  :-)

> > Maybe you could even be smart and do a clone() if the existing list is
> > short and do a scan-for-valid-first if the list being added is short.
> Sure, nice idea. But how short is short ? 

Well, let me avoid the word "short" and say, if you're adding just 1 to
a list of 1000, it's faster to scan.  If you're adding 1000 to a list of
1, it's faster to clone.  There's some ratio where it's equal, depending
on the relative costs of each action which really depends a lot on JVM
and object type.  I suspect scans are pretty fast in the general case
because we check for instanceof Element first, and that's the common
type in a long list.

Again, this only matters for an add(list) call and not a set(list) call.

> > Note that a Node interface wouldn't help here because someone could
> > still create a class Foo implements Node that makes no sense being added
> > to a document.
> Not sure I follow.... Other than trying to stop another 'lets use
> interfaces thread' :-)

Yes, just keeping the "Node would solve everything" contingent in
check.  :-)


More information about the jdom-interest mailing list