Author: rhauch
Date: 2008-12-09 21:27:52 -0500 (Tue, 09 Dec 2008)
New Revision: 678
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/properties/basic/AbstractPath.java
Log:
DNA-250 - Creating a path from a parent path and a segment is not fast
Added an optimized check during the isAtOrBelow and isAtOrAbove methods, and removed the
caching of the string form of the path (which was cached based upon the first call to any
of the getString methods, regardless of the NamespaceRegistry instance used, meaning the
cached string might have used no namespace registry and was returned from a getString(...)
that took a namespace registry. Also, the extra overhead of the cached string was not
worth the memory.
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/properties/basic/AbstractPath.java
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/properties/basic/AbstractPath.java 2008-12-09
15:09:16 UTC (rev 677)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/properties/basic/AbstractPath.java 2008-12-10
02:27:52 UTC (rev 678)
@@ -51,7 +51,6 @@
public static final Path SELF_PATH = new
BasicPath(Collections.singletonList(Path.SELF_SEGMENT), false);
- private transient String cachedStringPath;
private transient int hc = 0;
protected boolean isNormalized( List<Segment> segments ) {
@@ -221,7 +220,6 @@
TextEncoder encoder,
TextEncoder delimiterEncoder ) {
if (encoder == null) encoder = DEFAULT_ENCODER;
- if (encoder == DEFAULT_ENCODER && cachedStringPath != null &&
delimiterEncoder == null) return cachedStringPath;
final String delimiter = delimiterEncoder != null ?
delimiterEncoder.encode(DELIMITER_STR) : DELIMITER_STR;
// Since the segments are immutable, this code need not be synchronized because
concurrent threads
@@ -241,7 +239,6 @@
String result = sb.toString();
// Save the result to the internal string if this the default encoder is used.
// This is not synchronized, but it's okay
- if (encoder == DEFAULT_ENCODER && cachedStringPath == null &&
delimiterEncoder == null) cachedStringPath = result;
return result;
}
@@ -287,6 +284,7 @@
CheckArg.isNotNull(other, "other");
if (this == other) return true;
if (other.isRoot()) return true;
+ if (other.size() > this.size()) return false;
Iterator<Segment> thisIter = iterator();
Iterator<Segment> thatIter = other.iterator();
while (thisIter.hasNext() && thatIter.hasNext()) {
@@ -304,6 +302,7 @@
public boolean isAtOrAbove( Path other ) {
CheckArg.isNotNull(other, "other");
if (this == other) return true;
+ if (this.size() > other.size()) return false;
Iterator<Segment> thisIter = iterator();
Iterator<Segment> thatIter = other.iterator();
while (thisIter.hasNext() && thatIter.hasNext()) {
Show replies by date