right... but i don't see why we have to recalculate the path when the node states already know about them and we usually do know the path of an immutable tree because we have traversed to there using the TreeLocations.
IMO we should have NodeState#getPath but as long as we don't have that i will need sort of workaround to have an efficient way to handle ImmutableTree#getPath. kind regards angela On 3/19/13 3:00 PM, Marcel Reutegger wrote:
Hi, I'd rather avoid casting to an implementation specific class, even if it is conditional. This may introduce implementation dependent behavior, which makes debugging more difficult. If it is for performance reasons, we should look into finding another solution because the SegmentMK doesn't have KernelNodeStates! Regards Marcel--- jackrabbit/oak/trunk/oak- core/src/main/java/org/apache/jackrabbit/oak/core/ImmutableTree.java (original) +++ jackrabbit/oak/trunk/oak- core/src/main/java/org/apache/jackrabbit/oak/core/ImmutableTree.java Tue Mar 19 11:48:36 2013 @@ -26,6 +26,7 @@ import org.apache.jackrabbit.oak.api.Pro import org.apache.jackrabbit.oak.api.Root; import org.apache.jackrabbit.oak.api.Tree; import org.apache.jackrabbit.oak.commons.PathUtils; +import org.apache.jackrabbit.oak.kernel.KernelNodeState; import org.apache.jackrabbit.oak.plugins.version.VersionConstants; import org.apache.jackrabbit.oak.spi.security.Context; import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry; @@ -91,9 +92,14 @@ public final class ImmutableTree extends return "/"; } - StringBuilder sb = new StringBuilder(); - buildPath(sb); - return sb.toString(); + NodeState nodeState = getNodeState(); + if (nodeState instanceof KernelNodeState) { + return ((KernelNodeState) nodeState).getPath(); + } else { + StringBuilder sb = new StringBuilder(); + buildPath(sb); + return sb.toString(); + } } private void buildPath(StringBuilder sb) {
