Made getNodeHref() approx 10% faster by replacing StringBuffer.insert(0)
with StringBuffer.append().
This commit is contained in:
parent
e2c6d1903b
commit
288d573e50
1 changed files with 15 additions and 18 deletions
|
@ -840,34 +840,31 @@ public final class Application implements IPathElement, Runnable {
|
||||||
*/
|
*/
|
||||||
public String getNodeHref (Object elem, String actionName) {
|
public String getNodeHref (Object elem, String actionName) {
|
||||||
// Object root = getDataRoot ();
|
// Object root = getDataRoot ();
|
||||||
|
|
||||||
// check optional root prototype from app.properties
|
// check optional root prototype from app.properties
|
||||||
String rootProto = props.getProperty ("rootPrototype");
|
String rootProto = props.getProperty ("rootPrototype");
|
||||||
|
|
||||||
String divider = "/";
|
StringBuffer b = new StringBuffer (baseURI);
|
||||||
StringBuffer b = new StringBuffer ();
|
|
||||||
Object parent = null;
|
|
||||||
int loopWatch = 0;
|
|
||||||
|
|
||||||
while (elem != null && (parent = getParentElement (elem)) != null && elem != rootObject) {
|
composeHref (elem, b, rootProto, 0);
|
||||||
|
|
||||||
if (rootProto != null && rootProto.equals (getPrototypeName (elem)))
|
|
||||||
break;
|
|
||||||
b.insert (0, divider);
|
|
||||||
b.insert (0, UrlEncoded.encode (getElementName (elem)));
|
|
||||||
// move down to the element's parent
|
|
||||||
elem = parent;
|
|
||||||
|
|
||||||
if (loopWatch++ > 20)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (actionName != null)
|
if (actionName != null)
|
||||||
b.append (UrlEncoded.encode (actionName));
|
b.append (UrlEncoded.encode (actionName));
|
||||||
|
|
||||||
return baseURI + b.toString ();
|
return b.toString ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final void composeHref (Object elem, StringBuffer b, String rootProto, int pathCount) {
|
||||||
|
if (elem == null || pathCount > 20)
|
||||||
|
return;
|
||||||
|
if (rootProto != null && rootProto.equals (getPrototypeName (elem)))
|
||||||
|
return;
|
||||||
|
Object parent = getParentElement (elem);
|
||||||
|
if (parent == null)
|
||||||
|
return;
|
||||||
|
composeHref (getParentElement (elem), b, rootProto, pathCount++);
|
||||||
|
b.append (UrlEncoded.encode (getElementName (elem)));
|
||||||
|
b.append ("/");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method sets the base URL of this application which will be prepended to
|
* This method sets the base URL of this application which will be prepended to
|
||||||
|
|
Loading…
Add table
Reference in a new issue