From 288d573e50f20804c2b12d03b830d5248d368f9c Mon Sep 17 00:00:00 2001 From: hns Date: Tue, 4 Feb 2003 12:39:22 +0000 Subject: [PATCH] Made getNodeHref() approx 10% faster by replacing StringBuffer.insert(0) with StringBuffer.append(). --- src/helma/framework/core/Application.java | 33 +++++++++++------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/src/helma/framework/core/Application.java b/src/helma/framework/core/Application.java index 0e58364c..169e137c 100644 --- a/src/helma/framework/core/Application.java +++ b/src/helma/framework/core/Application.java @@ -840,34 +840,31 @@ public final class Application implements IPathElement, Runnable { */ public String getNodeHref (Object elem, String actionName) { // Object root = getDataRoot (); - // check optional root prototype from app.properties String rootProto = props.getProperty ("rootPrototype"); - String divider = "/"; - StringBuffer b = new StringBuffer (); - Object parent = null; - int loopWatch = 0; + StringBuffer b = new StringBuffer (baseURI); - while (elem != null && (parent = getParentElement (elem)) != null && elem != rootObject) { - - 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; - } + composeHref (elem, b, rootProto, 0); if (actionName != null) 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