Speedup decodeURI/decodeURIComponent by switching from charAt(i) to charCodeAt(i) in Decode.

Original patch by Alexander Karpinsky.

Review URL: http://codereview.chromium.org/6440001

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@6676 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
vegorov@chromium.org 2011-02-08 13:01:34 +00:00
parent 81787f986b
commit a2c9ca7464
2 changed files with 9 additions and 20 deletions

View File

@ -9,6 +9,7 @@ ARM Ltd.
Hewlett-Packard Development Company, LP
Alexander Botero-Lowry <alexbl@FreeBSD.org>
Alexander Karpinsky <homm86@gmail.com>
Alexandre Vassalotti <avassalotti@gmail.com>
Andreas Anyuru <andreas.anyuru@gmail.com>
Bert Belder <bertbelder@gmail.com>

View File

@ -90,11 +90,13 @@ function URIEncodePair(cc1 , cc2, result, index) {
}
function URIHexCharsToCharCode(ch1, ch2) {
if (HexValueOf(ch1) == -1 || HexValueOf(ch2) == -1) {
function URIHexCharsToCharCode(highChar, lowChar) {
var highCode = HexValueOf(highChar);
var lowCode = HexValueOf(lowChar);
if (highCode == -1 || lowCode == -1) {
throw new $URIError("URI malformed");
}
return HexStrToCharCode(ch1 + ch2);
return (highCode << 4) | lowCode;
}
@ -196,7 +198,7 @@ function Decode(uri, reserved) {
var ch = uri.charAt(k);
if (ch == '%') {
if (k + 2 >= uriLength) throw new $URIError("URI malformed");
var cc = URIHexCharsToCharCode(uri.charAt(++k), uri.charAt(++k));
var cc = URIHexCharsToCharCode(uri.charCodeAt(++k), uri.charCodeAt(++k));
if (cc >> 7) {
var n = 0;
while (((cc << ++n) & 0x80) != 0) ;
@ -206,7 +208,7 @@ function Decode(uri, reserved) {
if (k + 3 * (n - 1) >= uriLength) throw new $URIError("URI malformed");
for (var i = 1; i < n; i++) {
if (uri.charAt(++k) != '%') throw new $URIError("URI malformed");
octets[i] = URIHexCharsToCharCode(uri.charAt(++k), uri.charAt(++k));
octets[i] = URIHexCharsToCharCode(uri.charCodeAt(++k), uri.charCodeAt(++k));
}
index = URIDecodeOctets(octets, result, index);
} else {
@ -325,9 +327,7 @@ function URIEncodeComponent(component) {
}
function HexValueOf(c) {
var code = c.charCodeAt(0);
function HexValueOf(code) {
// 0-9
if (code >= 48 && code <= 57) return code - 48;
// A-F
@ -356,18 +356,6 @@ function CharCodeToHex4Str(cc) {
}
// Converts hex string to char code. Not efficient.
function HexStrToCharCode(s) {
var m = 0;
var r = 0;
for (var i = s.length - 1; i >= 0; --i) {
r = r + (HexValueOf(s.charAt(i)) << m);
m = m + 4;
}
return r;
}
// Returns true if all digits in string s are valid hex numbers
function IsValidHex(s) {
for (var i = 0; i < s.length; ++i) {