Hi,

On 8/14/07, Marcel Reutegger <[EMAIL PROTECTED]> wrote:
> Brian Thompson wrote:
> > Why not do something like
> >
> >     Node node = ...
> >     NodeIterator iterator = node.getParent().getNodes();
> >     long numSibs = iterator.getSize();
> >     iterator.skip(numSibs-1);
> >     if (node.isSame(iterator.nextNode())) {
> >         return /* this is the last sibling */;
> >     } else {
> >         return /* this is not the last sibling */;
> >     }
> >
> > Even if iterator.skip(n) is no more efficient than n calls of 
> > iterator.next(),
> > it saves a few operations in the body of the while loop.
>
> I'd also say the above code is considerably more efficient than actually
> iterating over the nodes because skipping in jackrabbit does not load the node
> instances but works on the list of child node entries.

Could we make the loading of the underlying node states lazy? We could
considerably speed up traversal operations that only need to invoke
methods like getName() or isSame() as we already have the names and
identifiers of the child nodes.

> please note that getSize() may also return -1 if the size cannot be 
> determined.

That's a big reason why I typically avoid using getSize(). A failsafe
implementation that uses getSize() and skip() would still need to
include the next() iteration as a fallback to remain independent of
the underlying implementation.

BR,

Jukka Zitting

Reply via email to