jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1468435 - /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/SecureNodeState.java
Date Tue, 16 Apr 2013 14:29:00 GMT
Author: jukka
Date: Tue Apr 16 14:28:59 2013
New Revision: 1468435

URL: http://svn.apache.org/r1468435
Log:
OAK-709: Consider moving permission evaluation to the node state level

Fix semantics of SecureNodeState.equals(), using a basic optimization to avoid most of the
performance cost.

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/SecureNodeState.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/SecureNodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/SecureNodeState.java?rev=1468435&r1=1468434&r2=1468435&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/SecureNodeState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/SecureNodeState.java
Tue Apr 16 14:28:59 2013
@@ -47,6 +47,12 @@ import static com.google.common.base.Pre
 public class SecureNodeState extends AbstractNodeState {
 
     /**
+     * Underlying root state, used to optimize a common case
+     * in {@link #equals(Object)}.
+     */
+    private final NodeState root;
+
+    /**
      * Underlying node state.
      */
     private final NodeState state;
@@ -123,7 +129,8 @@ public class SecureNodeState extends Abs
     public SecureNodeState(@Nonnull NodeState rootState,
                            @Nonnull PermissionProvider permissionProvider,
                            @Nonnull TreeTypeProvider typeProvider) {
-        this.state = checkNotNull(rootState);
+        this.root = checkNotNull(rootState);
+        this.state = rootState;
         this.base = new ImmutableTree(rootState, typeProvider);
         this.permissionProvider = permissionProvider;
         // calculate the readstatus for the root
@@ -133,6 +140,7 @@ public class SecureNodeState extends Abs
     private SecureNodeState(
             @Nonnull SecureNodeState parent,
             @Nonnull String name, @Nonnull NodeState nodeState) {
+        this.root = checkNotNull(parent).root;
         this.state = checkNotNull(nodeState);
         this.base = new ImmutableTree(parent.base, name, nodeState);
         this.permissionProvider = parent.permissionProvider;
@@ -246,10 +254,23 @@ public class SecureNodeState extends Abs
     }
 
     //-------------------------------------------------------------< Object >---
-    // FIXME: add proper equals/hashcode implementation (see OAK-709)
+
     @Override
-    public boolean equals(Object obj) {
-        return state.equals(obj);
+    public boolean equals(Object object) {
+        if (object == this) {
+            return true;
+        } else if (object instanceof SecureNodeState) {
+            SecureNodeState that = (SecureNodeState) object;
+            // TODO: We should be able to do this optimization also across
+            // different revisions (root states) as long as the path,
+            // the subtree, and any security-related areas like the
+            // permission store are equal for both states.
+            if (root.equals(that.root)
+                    && base.getPath().equals(that.base.getPath())) {
+                return true;
+            }
+        }
+        return super.equals(object);
     }
 
     //------------------------------------------------------------< private >---



Mime
View raw message