On Fri, 15 Jun 2012 04:57:57 -0300, Lance Java <lance.j...@googlemail.com>
wrote:
When manipulating the serverside DOM in a mixin etc, the only public API
for accessing a node's children is via Element.getChildren().
Have you checked http://tapestryxpath.sourceforge.net/? I haven't yet, but
I should. :)
The getChildren() method creates a new ArrayList, adds all the children
and returns it which I think is inneficcient.
Well, have you done any benchmarks to know how much resources (CPU time,
memory) it actually uses to know whether it's really a bottleneck?
Otherwise, we could have a case of premature optimization.
Anyway, thanks for the tip. It look like a good improvement, specially in
isEmpty(), which doesn't seem to need to use getChildren(). :)
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
--
Thiago H. de Paula Figueiredo
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org