hi michael

feel free to revert it. i decided to change it as i will heavily
use ReadOnlyTree#getPath and i am sure it will have a negative
impact on overall system performance as it's within the
permission evaluation... that was the reason behind... but of course
i can build my own ReadOnlyTree implementation that keeps track
of the path...

angela

On 1/31/13 11:41 AM, Michael Dürig wrote:

Hi,

Preemptively building and caching the path here is worrisome since this
will blow up memory usage quite a bit. This is the reason the path was
only build on access (i.e. getPath()) in the original design and in
TreeImpl.

Michael


On 30.1.13 17:33, [email protected] wrote:
+    /**
+     * Path of this tree
+     */
+    private final String path;
+
+    /**
+     * Underlying node state
+     */
       private final NodeState state;

-    public ReadOnlyTree(NodeState root) {
-        this(null, "", root);
+    public ReadOnlyTree(NodeState rootState) {
+        this(null, "", rootState);
       }

-    public ReadOnlyTree(ReadOnlyTree parent, String name, NodeState state) {
+    public ReadOnlyTree(@Nullable ReadOnlyTree parent, @Nonnull String name, 
@Nonnull NodeState state) {
           this.parent = parent;
           this.name = checkNotNull(name);
+        this.path = buildPath(parent, name);
           this.state = checkNotNull(state);
           checkArgument(!name.isEmpty() || parent == null);
       }

+    private static String buildPath(ReadOnlyTree parent, String name) {
+        if (parent == null) {
+            return "/";
+        } else if (parent.isRoot()) {
+            return parent.path + name;
+        } else {
+            StringBuilder sb = new StringBuilder();
+            sb.append(parent.path).append('/').append(name);
+            return sb.toString();
+        }
+    }

Reply via email to