From oak-commits-return-1132-apmail-jackrabbit-oak-commits-archive=jackrabbit.apache.org@jackrabbit.apache.org Mon Jul 9 15:25:48 2012 Return-Path: X-Original-To: apmail-jackrabbit-oak-commits-archive@minotaur.apache.org Delivered-To: apmail-jackrabbit-oak-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 5C876CF3D for ; Mon, 9 Jul 2012 15:25:48 +0000 (UTC) Received: (qmail 56583 invoked by uid 500); 9 Jul 2012 15:25:48 -0000 Delivered-To: apmail-jackrabbit-oak-commits-archive@jackrabbit.apache.org Received: (qmail 56510 invoked by uid 500); 9 Jul 2012 15:25:46 -0000 Mailing-List: contact oak-commits-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: oak-commits@jackrabbit.apache.org Delivered-To: mailing list oak-commits@jackrabbit.apache.org Received: (qmail 56452 invoked by uid 99); 9 Jul 2012 15:25:44 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 09 Jul 2012 15:25:44 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 09 Jul 2012 15:25:42 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id BAAAF23888EA; Mon, 9 Jul 2012 15:25:21 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1359216 - /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeState.java Date: Mon, 09 Jul 2012 15:25:21 -0000 To: oak-commits@jackrabbit.apache.org From: jukka@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120709152521.BAAAF23888EA@eris.apache.org> Author: jukka Date: Mon Jul 9 15:25:21 2012 New Revision: 1359216 URL: http://svn.apache.org/viewvc?rev=1359216&view=rev Log: OAK-172: Optimize KernelNodeState equality checks Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeState.java Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeState.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeState.java?rev=1359216&r1=1359215&r2=1359216&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeState.java (original) +++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeState.java Mon Jul 9 15:25:21 2012 @@ -43,7 +43,7 @@ import java.util.Map.Entry; * Basic {@link NodeState} implementation based on the {@link MicroKernel} * interface. This class makes an attempt to load data lazily. */ -class KernelNodeState extends AbstractNodeState { +final class KernelNodeState extends AbstractNodeState { /** * Maximum number of child nodes kept in memory. @@ -61,6 +61,8 @@ class KernelNodeState extends AbstractNo private long childNodeCount = -1; + private String hash = null; + // TODO: WeakReference? private Map childNodes; @@ -89,7 +91,8 @@ class KernelNodeState extends AbstractNo private synchronized void init() { if (properties == null) { String json = kernel.getNodes( - path, revision, 0, 0, MAX_CHILD_NODE_NAMES, null); + path, revision, 0, 0, MAX_CHILD_NODE_NAMES, + "{properties:[\"*\",\":hash\"]}"); JsopReader reader = new JsopTokenizer(json); reader.read('{'); @@ -101,6 +104,8 @@ class KernelNodeState extends AbstractNo if (":childNodeCount".equals(name)) { childNodeCount = Long.valueOf(reader.read(JsopReader.NUMBER)); + } else if (":hash".equals(name)) { + hash = reader.read(JsopReader.STRING); } else if (reader.matches('{')) { reader.read('}'); String childPath = path + '/' + name; @@ -173,6 +178,33 @@ class KernelNodeState extends AbstractNo }; } + //------------------------------------------------------------< Object >-- + + @Override + public boolean equals(Object object) { + if (this == object) { + return true; + } else if (object instanceof KernelNodeState) { + KernelNodeState that = (KernelNodeState) object; + // When both instances come from the same MicroKernel, we can + // use revision/path information or content hashes (when available) + // to avoid a full tree comparison in many cases. + if (kernel.equals(that.kernel)) { + if (revision.equals(that.revision) && path.equals(that.path)) { + return true; + } else { + this.init(); + that.init(); + if (hash != null && that.hash != null) { + return hash.equals(that.hash); + } + } + } + } + // fallback + return super.equals(object); + } + //------------------------------------------------------------< internal >--- @Nonnull @@ -251,12 +283,4 @@ class KernelNodeState extends AbstractNo } } - private List readArray(JsopReader reader) { - List values = new ArrayList(); - while (!reader.matches(']')) { - values.add(CoreValueMapper.fromJsopReader(reader, valueFactory)); - reader.matches(','); - } - return values; - } -} \ No newline at end of file +}