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.
This commit is contained in:
parent
933a0ef7a3
commit
318964b518
2 changed files with 39 additions and 2 deletions
|
@ -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 ();
|
||||
}
|
||||
|
|
37
src/helma/util/UrlEncoded.java
Normal file
37
src/helma/util/UrlEncoded.java
Normal file
|
@ -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<l; i++) {
|
||||
char c = str.charAt(i);
|
||||
if (c == ' ') {
|
||||
needsSpaceEncoding = true;
|
||||
} else if (!(c>='a' && c<='z' ||
|
||||
c>='A' && c<='Z' ||
|
||||
c>='0' && c<='9')) {
|
||||
return URLEncoder.encode (str);
|
||||
}
|
||||
}
|
||||
if (needsSpaceEncoding)
|
||||
return str.replace (' ', '+');
|
||||
return str;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue