Reviewers: Yang,

Message:
PTAL. That's the end of low-hanging fruit in typed array constructors +
preparations to more hydrogenizing.

Description:
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.

Please review this at https://codereview.chromium.org/59763010/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+17, -10 lines):
  M src/typedarray.js


Index: src/typedarray.js
diff --git a/src/typedarray.js b/src/typedarray.js
index 20a50c5c1bcfa43c747e1d9cb59bd4eca8f643be..d435803a5aa603793c5cce5ada2bd884979f0a24 100644
--- a/src/typedarray.js
+++ b/src/typedarray.js
@@ -49,15 +49,20 @@ endmacro

 macro TYPED_ARRAY_CONSTRUCTOR(ARRAY_ID, NAME, ELEMENT_SIZE)
   function NAMEConstructByArrayBuffer(obj, buffer, byteOffset, length) {
- var 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");
+    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);
+      }
+      if (offset > bufferByteLength) {
+        throw MakeRangeError("invalid_typed_array_offset");
+      }
     }

     var newByteLength;
@@ -80,7 +85,8 @@ macro TYPED_ARRAY_CONSTRUCTOR(ARRAY_ID, NAME, ELEMENT_SIZE)
   }

   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 @@ function DataViewConstructor(buffer, byteOffset, byteLength) { // length = 3
       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