jackrabbit-oak-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jukka Zitting <jukka.zitt...@gmail.com>
Subject Re: Tree.hasChild() / Tree.getChild()
Date Tue, 01 Oct 2013 13:02:45 GMT
Hi,

On Mon, Sep 30, 2013 at 11:08 PM, Tobias Bocanegra <tripod@apache.org> wrote:
> On Mon, Sep 30, 2013 at 6:56 PM, Jukka Zitting <jukka.zitting@gmail.com> wrote:
>> The only difference is between "child.exists()" and "child != null",
>> and AFAICT any optimizations done in such an extra getChild() method
>> could also be used to optimize the exists() method.
>
> right. but depending on the persistence implementation and caching, it
> could result in fetching the child twice if using just the exists()
> check.

The current MutableTree.exists() method just calls enter(), which contains:

    private boolean enter() {
        root.checkLive();
        if (isHidden(name)) {
            return false;
        } else if (applyPendingMoves()) {
            return reconnect();
        } else {
            return nodeBuilder.exists();
        }
    }

In the normal case when there have been no intermediate changes, none
of those calls (except reconnect) should require the creation of any
extra objects or doing anything else that could be expensive. If
needed, the method could be further optimized by memorizing the return
value, but I'd be surprised if this was a bottleneck for anything.

BR,

Jukka Zitting

Mime
View raw message