Re: Tree construction: Coalescing text nodes

On Nov 19, 2009, at 10:59, Jonas Sicking wrote:

> I think this adds unnecessary complexity and performance cost to the
> parser.

In the common case (append), the complexity would be: 1) Ask the parent for its last child. 2) Check the return value for null. 3) Ask the return value if it is a text node.

The foster-parenting case wouldn't be materially different.

> The intuitive (to me) implementation is for the parser to keep
> a reference to the last textnode it has inserted. Whenever more text
> data is parsed, append the text to that textnode. Whenever non-text
> data is parsed, drop the reference to the textnode.

This scheme requires operations other than text append to touch bookkeeping that exists for text append, which, arguably, is more complex than performing additional 2 additional operations (a null check would happen in any case) that are confined to the lines of code that deal with text appending.

-- 
Henri Sivonen
hsivonen@iki.fi
http://hsivonen.iki.fi/

Received on Thursday, 19 November 2009 09:52:36 UTC