Revision: 17567
Author:   [email protected]
Date:     Thu Nov  7 14:56:40 2013 UTC
Log:      Speed up typed array constructors.
- Avoid calls into ToPositiveInteger for valid cases of 'undefined' arguments.
  (Otherwise it calls into runtime).
 - Reduce the checks performed in case offset for TypedArrayFromArrayBuffer
  constructor is called with no offset argument.

[email protected]

Review URL: https://codereview.chromium.org/59763010
http://code.google.com/p/v8/source/detail?r=17567

Modified:
 /branches/bleeding_edge/src/typedarray.js

=======================================
--- /branches/bleeding_edge/src/typedarray.js   Wed Nov  6 16:28:38 2013 UTC
+++ /branches/bleeding_edge/src/typedarray.js   Thu Nov  7 14:56:40 2013 UTC
@@ -49,15 +49,20 @@

 macro TYPED_ARRAY_CONSTRUCTOR(ARRAY_ID, NAME, ELEMENT_SIZE)
   function NAMEConstructByArrayBuffer(obj, buffer, byteOffset, length) {
- var offset = ToPositiveInteger(byteOffset, "invalid_typed_array_length")
+    var bufferByteLength = buffer.byteLength;
+    var offset;
+    if (IS_UNDEFINED(byteOffset)) {
+      offset = 0;
+    } else {
+      offset = ToPositiveInteger(byteOffset, "invalid_typed_array_length");

-    if (offset % ELEMENT_SIZE !== 0) {
-      throw MakeRangeError("invalid_typed_array_alignment",
-          "start offset", "NAME", ELEMENT_SIZE);
-    }
-    var bufferByteLength = buffer.byteLength;
-    if (offset > bufferByteLength) {
-      throw MakeRangeError("invalid_typed_array_offset");
+      if (offset % ELEMENT_SIZE !== 0) {
+        throw MakeRangeError("invalid_typed_array_alignment",
+            "start offset", "NAME", ELEMENT_SIZE);
+      }
+      if (offset > bufferByteLength) {
+        throw MakeRangeError("invalid_typed_array_offset");
+      }
     }

     var newByteLength;
@@ -80,7 +85,8 @@
   }

   function NAMEConstructByLength(obj, length) {
-    var l = ToPositiveInteger(length, "invalid_typed_array_length");
+    var l = IS_UNDEFINED(length) ?
+      0 : ToPositiveInteger(length, "invalid_typed_array_length");
     var byteLength = l * ELEMENT_SIZE;
     var buffer = new $ArrayBuffer(byteLength);
     %TypedArrayInitialize(obj, ARRAY_ID, buffer, 0, byteLength);
@@ -301,7 +307,8 @@
       throw MakeTypeError('data_view_not_array_buffer', []);
     }
     var bufferByteLength = %ArrayBufferGetByteLength(buffer);
-    var offset = ToPositiveInteger(byteOffset, 'invalid_data_view_offset');
+    var offset = IS_UNDEFINED(byteOffset) ?
+      0 : ToPositiveInteger(byteOffset, 'invalid_data_view_offset');
     if (offset > bufferByteLength) {
       throw MakeRangeError('invalid_data_view_offset');
     }

--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to