Commit f3acd446 authored by dslomov@chromium.org's avatar dslomov@chromium.org

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.

R=yangguo@chromium.org

Review URL: https://codereview.chromium.org/59763010

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17567 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 233b8b4f
......@@ -49,16 +49,21 @@ endmacro
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");
}
}
var newByteLength;
var newLength;
......@@ -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');
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment