Merge change 20706
* changes: Improve Browser performance by 1-2%. To address domain sanity bug, http://b/issue?id=1022797, we decoded/encoded the url for each request. As the url can be long, getBytes() and String.init are taking 1.5% in nytimes.com and 2.4% in cnn.com. By doing a simple URL encoding test, we can shave 1-2 secs thread time during loading.
This commit is contained in:
@@ -95,17 +95,6 @@ class FrameLoader {
|
||||
public boolean executeLoad() {
|
||||
String url = mListener.url();
|
||||
|
||||
// Attempt to decode the percent-encoded url.
|
||||
try {
|
||||
url = new String(URLUtil.decode(url.getBytes()));
|
||||
} catch (IllegalArgumentException e) {
|
||||
// Fail with a bad url error if the decode fails.
|
||||
mListener.error(EventHandler.ERROR_BAD_URL,
|
||||
mListener.getContext().getString(
|
||||
com.android.internal.R.string.httpErrorBadUrl));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (URLUtil.isNetworkUrl(url)){
|
||||
if (mSettings.getBlockNetworkLoads()) {
|
||||
mListener.error(EventHandler.ERROR_BAD_URL,
|
||||
@@ -113,6 +102,13 @@ class FrameLoader {
|
||||
com.android.internal.R.string.httpErrorBadUrl));
|
||||
return false;
|
||||
}
|
||||
// Make sure it is correctly URL encoded before sending the request
|
||||
if (!URLUtil.verifyURLEncoding(url)) {
|
||||
mListener.error(EventHandler.ERROR_BAD_URL,
|
||||
mListener.getContext().getString(
|
||||
com.android.internal.R.string.httpErrorBadUrl));
|
||||
return false;
|
||||
}
|
||||
mNetwork = Network.getInstance(mListener.getContext());
|
||||
return handleHTTPLoad();
|
||||
} else if (handleLocalFile(url, mListener, mSettings)) {
|
||||
|
||||
@@ -126,6 +126,32 @@ public final class URLUtil {
|
||||
return retData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return True iff the url is correctly URL encoded
|
||||
*/
|
||||
static boolean verifyURLEncoding(String url) {
|
||||
int count = url.length();
|
||||
if (count == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int index = url.indexOf('%');
|
||||
while (index >= 0 && index < count) {
|
||||
if (index < count - 2) {
|
||||
try {
|
||||
parseHex((byte) url.charAt(++index));
|
||||
parseHex((byte) url.charAt(++index));
|
||||
} catch (IllegalArgumentException e) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
index = url.indexOf('%', index + 1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static int parseHex(byte b) {
|
||||
if (b >= '0' && b <= '9') return (b - '0');
|
||||
if (b >= 'A' && b <= 'F') return (b - 'A' + 10);
|
||||
|
||||
Reference in New Issue
Block a user