Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(733)

Unified Diff: src/typedarray.js

Issue 59763010: Speed up typed array constructors. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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');
Yang 2013/11/07 10:14:11 I think we use 4 space indent after linebreak. I s
if (offset > bufferByteLength) {
throw MakeRangeError('invalid_data_view_offset');
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698