When manipulating the serverside DOM in a mixin etc, the only public API for
accessing a node's children is via Element.getChildren().

The getChildren() method creates a new ArrayList, adds all the children and
returns it which I think is inneficcient.  I would have expected
getChildren() to return a List implementation that was able to iterate from
firstChild to lastChild without copying all children to an array.
Element.isEmpty() calls getChildren() under the hood.

Here is the code from org.apache.tapestry5.dom.Element:


   public List<Node> getChildren()
   {
       List<Node> result = CollectionFactory.newList();
       Node cursor = firstChild;
   
       while (cursor != null)
       {
           result.add(cursor);
           cursor = cursor.nextSibling;
       }
   
       return result;
   }

    public boolean isEmpty()
    {
        List<Node> children = getChildren();

        if (children.isEmpty())
            return true;

        for (Node n : children)
        {
            if (n instanceof Text)
            {
                Text t = (Text) n;

                if (t.isEmpty())
                    continue;
            }

            // Not a text node, or a non-empty text node, then the element
isn't empty.
            return false;
        }

        return true;
    }


--
View this message in context: 
http://tapestry.1045711.n5.nabble.com/Element-getChildren-returns-ArrayList-tp5713921.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to