Re: Implementing NodeList

At 07:25 PM 7/27/98 -0400, Stephen R. Savitzky wrote:
>You and Don Park need to get together on what ``liveness'' means, and when
>it's required by the spec. 
>
>Mike Champion <mcc@arbortext.com> writes:
>
>> Neither of these are consistent with the spec.  Sorry, but this *is* going
>> to be hard to implement efficiently.
>> 
>> I think the best implementation is to lazily evaluate the NodeList, i.e.,
>> make the NodeList be an interface that really has what we used to call a
>> NodeIterator under the covers.  That way, you only see nodes in the tree
>> when the user asks for them.  That puts the burden of capturing changes to
>> the tree on the call to item().
>
>This means that every call on item() involves a complete traversal of half
>the tree (on average) to make sure that a new node of the type selected by
>getElementsByTagName hasn't snuck in behind your back.  In the case of large
>documents, possibly containing references to external parsed entities, this
>could take a *very long time*.

Not in practice; I assure you that I screamed and yelled about this when
iterator were removed from the spec in favor of NodeLists.  I got a fair
amount of free advice to the effect that IN GENERAL people will traverse
node lists in order, so implementation tricks involving cacheing the
current location and validating that nothing has changed before accessing
the "next" index in the NodeList can mean that real performance is much
better than the worst case.

Nevertheless, the real answer -- as I think you said last time -- is to put
interators back in the spec for Level 2.

>
>ON THE OTHER HAND, "Don Park" <donpark@quake.net> writes
>
>> This confusion stems from the movement of words between different versions
>> of the spec.  If you read the latest spec more carefully, you will see that
>> the word "live" is used only in the description of the attribute
>> "childNodes".  This means that the NodeList itself is not always live and
>> that the NodeList returned by getElementsByTagName is not live.  Only the
>> NodeList returned by getChildNodes is "live".
>
>I think this suggests that the spec is ambiguous, and should be rewritten to
>clarify the situation, preferably in the direction of Don Park's commonsense
>interpretation.

I agree, and I'll push for this.  Thanks for the helpful input!

Mike Champion

Received on Monday, 27 July 1998 20:21:34 UTC