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

Unified Diff: src/js/typedarray.js

Issue 1767893002: Optimize new TypedArray(typedArray) constructor (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix asan issue Created 4 years, 9 months 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/js/typedarray.js
diff --git a/src/js/typedarray.js b/src/js/typedarray.js
index b16dab2237f869a0645b114a75e0aa3949fc68f1..e3c02252e7eb752799473414a51d8f50fb76ee9a 100644
--- a/src/js/typedarray.js
+++ b/src/js/typedarray.js
@@ -200,8 +200,7 @@ function NAMEConstructByLength(obj, length) {
}
}
-function NAMEConstructByArrayLike(obj, arrayLike) {
- var length = arrayLike.length;
+function NAMEConstructByArrayLike(obj, arrayLike, length) {
var l = ToPositiveInteger(length, kInvalidTypedArrayLength);
if (l > %_MaxSmi()) {
@@ -241,7 +240,7 @@ function NAMEConstructByIterable(obj, iterable, iteratorFn) {
for (var value of newIterable) {
list.push(value);
}
- NAMEConstructByArrayLike(obj, list);
+ NAMEConstructByArrayLike(obj, list, list.length);
}
// ES#sec-typedarray-typedarray TypedArray ( typedArray )
@@ -251,20 +250,12 @@ function NAMEConstructByTypedArray(obj, typedArray) {
var length = %_TypedArrayGetLength(typedArray);
var byteLength = %_ArrayBufferViewGetByteLength(typedArray);
var newByteLength = length * ELEMENT_SIZE;
+ NAMEConstructByArrayLike(obj, typedArray, length);
var bufferConstructor = SpeciesConstructor(srcData, GlobalArrayBuffer);
- var data = new GlobalArrayBuffer(newByteLength);
var prototype = bufferConstructor.prototype;
// TODO(littledan): Use the right prototype based on bufferConstructor's realm
if (IS_RECEIVER(prototype) && prototype !== GlobalArrayBufferPrototype) {
- %InternalSetPrototype(data, prototype);
- }
- %_TypedArrayInitialize(obj, ARRAY_ID, data, 0, newByteLength, true);
- // Note: The separate CloneArrayBuffer path in the spec ensures
- // that NaNs are not canonicalized, but because V8 does not
- // canonicalize NaNs, we do not have to do anything different.
- // TODO(littledan): Make a fastpath based on memcpy
- for (var i = 0; i < length; i++) {
- obj[i] = typedArray[i];
+ %InternalSetPrototype(%TypedArrayGetBuffer(obj), prototype);
}
}
@@ -279,8 +270,8 @@ function NAMEConstructor(arg1, arg2, arg3) {
NAMEConstructByTypedArray(this, arg1);
} else {
var iteratorFn = arg1[iteratorSymbol];
- if (IS_UNDEFINED(iteratorFn) || iteratorFn === ArrayValues) {
- NAMEConstructByArrayLike(this, arg1);
+ if (IS_UNDEFINED(iteratorFn)) {
+ NAMEConstructByArrayLike(this, arg1, arg1.length);
} else {
NAMEConstructByIterable(this, arg1, iteratorFn);
}
« 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