From 318964b518ae1f30589519bd763f2c3c56b24f89 Mon Sep 17 00:00:00 2001 From: hns Date: Thu, 17 Oct 2002 18:43:24 +0000 Subject: [PATCH] Use a proxy to java.net.URLEncoder which only encodes when there is actual work to do. This is necessary because URLEncoder is quite inefficient (e.g. it preallocates buffers and stuff), and we call it often with short string that don't need encoding. --- src/helma/framework/core/Application.java | 4 +-- src/helma/util/UrlEncoded.java | 37 +++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 src/helma/util/UrlEncoded.java diff --git a/src/helma/framework/core/Application.java b/src/helma/framework/core/Application.java index 8732a5d4..3148dd2b 100644 --- a/src/helma/framework/core/Application.java +++ b/src/helma/framework/core/Application.java @@ -844,7 +844,7 @@ public final class Application implements IPathElement, Runnable { if (rootproto != null && rootproto.equals (getPrototypeName (p))) break; b.insert (0, divider); - b.insert (0, URLEncoder.encode (getElementName (p))); + b.insert (0, UrlEncoded.encode (getElementName (p))); p = getParentElement (p); if (loopWatch++ > 20) @@ -852,7 +852,7 @@ public final class Application implements IPathElement, Runnable { } if (actionName != null) - b.append (URLEncoder.encode (actionName)); + b.append (UrlEncoded.encode (actionName)); return baseURI + b.toString (); } diff --git a/src/helma/util/UrlEncoded.java b/src/helma/util/UrlEncoded.java new file mode 100644 index 00000000..fda0d10f --- /dev/null +++ b/src/helma/util/UrlEncoded.java @@ -0,0 +1,37 @@ +// UrlEncoded.java +// (c) 2002 Hannes Wallnoefer + +package helma.util; + +import java.net.URLEncoder; + + +/** + * A proxy to java.net.URLEncoder which only encodes when + * there is actual work to do. This is necessary because + * URLEncoder is quite inefficient (e.g. it preallocates + * buffers and stuff), and we call it often with + * short string that don't need encoding. + */ +public final class UrlEncoded { + + + public static String encode (String str) { + int l = str.length(); + boolean needsSpaceEncoding = false; + for (int i=0; i='a' && c<='z' || + c>='A' && c<='Z' || + c>='0' && c<='9')) { + return URLEncoder.encode (str); + } + } + if (needsSpaceEncoding) + return str.replace (' ', '+'); + return str; + } + +} \ No newline at end of file