Revision: 6676
Author: [email protected]
Date: Tue Feb  8 05:01:34 2011
Log: 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
http://code.google.com/p/v8/source/detail?r=6676

Modified:
 /branches/bleeding_edge/AUTHORS
 /branches/bleeding_edge/src/uri.js

=======================================
--- /branches/bleeding_edge/AUTHORS     Fri Feb  4 05:43:38 2011
+++ /branches/bleeding_edge/AUTHORS     Tue Feb  8 05:01:34 2011
@@ -9,6 +9,7 @@
 Hewlett-Packard Development Company, LP

 Alexander Botero-Lowry <[email protected]>
+Alexander Karpinsky <[email protected]>
 Alexandre Vassalotti <[email protected]>
 Andreas Anyuru <[email protected]>
 Bert Belder <[email protected]>
=======================================
--- /branches/bleeding_edge/src/uri.js  Fri Feb  4 02:38:49 2011
+++ /branches/bleeding_edge/src/uri.js  Tue Feb  8 05:01:34 2011
@@ -90,11 +90,13 @@
 }


-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 @@
     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 @@
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 HexValueOf(c) {
-  var code = c.charCodeAt(0);
-
+function HexValueOf(code) {
   // 0-9
   if (code >= 48 && code <= 57) return code - 48;
   // A-F
@@ -354,18 +354,6 @@
   }
   return r;
 }
-
-
-// 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

--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to