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

Side by Side 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 test262 failures and remove regression 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 (function(global, utils) { 5 (function(global, utils) {
6 6
7 "use strict"; 7 "use strict";
8 8
9 %CheckIsBootstrapping(); 9 %CheckIsBootstrapping();
10 10
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 if (byteLength > %_TypedArrayMaxSizeInHeap()) { 195 if (byteLength > %_TypedArrayMaxSizeInHeap()) {
196 var buffer = new GlobalArrayBuffer(byteLength); 196 var buffer = new GlobalArrayBuffer(byteLength);
197 %_TypedArrayInitialize(obj, ARRAY_ID, buffer, 0, byteLength, true); 197 %_TypedArrayInitialize(obj, ARRAY_ID, buffer, 0, byteLength, true);
198 } else { 198 } else {
199 %_TypedArrayInitialize(obj, ARRAY_ID, null, 0, byteLength, true); 199 %_TypedArrayInitialize(obj, ARRAY_ID, null, 0, byteLength, true);
200 } 200 }
201 } 201 }
202 202
203 function NAMEConstructByArrayLike(obj, arrayLike) { 203 function NAMEConstructByArrayLike(obj, arrayLike) {
204 var length = arrayLike.length; 204 var length = arrayLike.length;
205
205 var l = ToPositiveInteger(length, kInvalidTypedArrayLength); 206 var l = ToPositiveInteger(length, kInvalidTypedArrayLength);
206 207
207 if (l > %_MaxSmi()) { 208 if (l > %_MaxSmi()) {
208 throw MakeRangeError(kInvalidTypedArrayLength); 209 throw MakeRangeError(kInvalidTypedArrayLength);
209 } 210 }
210 var initialized = false;
211 var byteLength = l * ELEMENT_SIZE; 211 var byteLength = l * ELEMENT_SIZE;
212 if (byteLength <= %_TypedArrayMaxSizeInHeap()) { 212 %_TypedArrayInitialize(obj, ARRAY_ID, null, 0, byteLength, false);
adamk 2016/03/08 19:32:10 What's up with this if statement? Why is it OK to
Dan Ehrenberg 2016/03/08 19:55:55 Apparently it wasn't, and this was found by the te
213 %_TypedArrayInitialize(obj, ARRAY_ID, null, 0, byteLength, false); 213 for (var i = 0; i < l; i++) {
214 } else { 214 // It is crucial that we let any exceptions from arrayLike[i]
adamk 2016/03/08 19:32:10 Not sure this comment is worth keeping around.
Dan Ehrenberg 2016/03/08 19:55:54 How about I leave all this as is for now, since I'
adamk 2016/03/08 20:05:39 Fine to leave for now since you're not touching it
215 initialized = 215 // propagate outside the function.
216 %TypedArrayInitializeFromArrayLike(obj, ARRAY_ID, arrayLike, l); 216 obj[i] = arrayLike[i];
217 }
218 if (!initialized) {
219 for (var i = 0; i < l; i++) {
220 // It is crucial that we let any execptions from arrayLike[i]
221 // propagate outside the function.
222 obj[i] = arrayLike[i];
223 }
224 } 217 }
225 } 218 }
226 219
227 function NAMEConstructByIterable(obj, iterable, iteratorFn) { 220 function NAMEConstructByIterable(obj, iterable, iteratorFn) {
228 var list = new InternalArray(); 221 var list = new InternalArray();
229 // Reading the Symbol.iterator property of iterable twice would be 222 // Reading the Symbol.iterator property of iterable twice would be
230 // observable with getters, so instead, we call the function which 223 // observable with getters, so instead, we call the function which
231 // was already looked up, and wrap it in another iterable. The 224 // was already looked up, and wrap it in another iterable. The
232 // __proto__ of the new iterable is set to null to avoid any chance 225 // __proto__ of the new iterable is set to null to avoid any chance
233 // of modifications to Object.prototype being observable here. 226 // of modifications to Object.prototype being observable here.
(...skipping 10 matching lines...) Expand all
244 NAMEConstructByArrayLike(obj, list); 237 NAMEConstructByArrayLike(obj, list);
245 } 238 }
246 239
247 // ES#sec-typedarray-typedarray TypedArray ( typedArray ) 240 // ES#sec-typedarray-typedarray TypedArray ( typedArray )
248 function NAMEConstructByTypedArray(obj, typedArray) { 241 function NAMEConstructByTypedArray(obj, typedArray) {
249 // TODO(littledan): Throw on detached typedArray 242 // TODO(littledan): Throw on detached typedArray
250 var srcData = %TypedArrayGetBuffer(typedArray); 243 var srcData = %TypedArrayGetBuffer(typedArray);
251 var length = %_TypedArrayGetLength(typedArray); 244 var length = %_TypedArrayGetLength(typedArray);
252 var byteLength = %_ArrayBufferViewGetByteLength(typedArray); 245 var byteLength = %_ArrayBufferViewGetByteLength(typedArray);
253 var newByteLength = length * ELEMENT_SIZE; 246 var newByteLength = length * ELEMENT_SIZE;
247 var initialized = %TypedArrayInitializeFromArrayLike(obj, ARRAY_ID, typedArray , length);
adamk 2016/03/08 19:32:10 Will this ever return false? If not, and this is t
Dan Ehrenberg 2016/03/08 19:55:54 I played around with a bunch of alternatives here,
254 var bufferConstructor = SpeciesConstructor(srcData, GlobalArrayBuffer); 248 var bufferConstructor = SpeciesConstructor(srcData, GlobalArrayBuffer);
255 var data = new GlobalArrayBuffer(newByteLength);
256 var prototype = bufferConstructor.prototype; 249 var prototype = bufferConstructor.prototype;
257 // TODO(littledan): Use the right prototype based on bufferConstructor's realm 250 // TODO(littledan): Use the right prototype based on bufferConstructor's realm
258 if (IS_RECEIVER(prototype) && prototype !== GlobalArrayBufferPrototype) { 251 if (IS_RECEIVER(prototype) && prototype !== GlobalArrayBufferPrototype) {
259 %InternalSetPrototype(data, prototype); 252 %InternalSetPrototype(%TypedArrayGetBuffer(obj), prototype);
260 } 253 }
261 %_TypedArrayInitialize(obj, ARRAY_ID, data, 0, newByteLength, true); 254 if (!initialized) {
262 // Note: The separate CloneArrayBuffer path in the spec ensures 255 for (var i = 0; i < length; i++) {
263 // that NaNs are not canonicalized, but because V8 does not 256 obj[i] = typedArray[i];
264 // canonicalize NaNs, we do not have to do anything different. 257 }
265 // TODO(littledan): Make a fastpath based on memcpy
266 for (var i = 0; i < length; i++) {
267 obj[i] = typedArray[i];
268 } 258 }
269 } 259 }
270 260
271 function NAMEConstructor(arg1, arg2, arg3) { 261 function NAMEConstructor(arg1, arg2, arg3) {
272 if (!IS_UNDEFINED(new.target)) { 262 if (!IS_UNDEFINED(new.target)) {
273 if (IS_ARRAYBUFFER(arg1) || IS_SHAREDARRAYBUFFER(arg1)) { 263 if (IS_ARRAYBUFFER(arg1) || IS_SHAREDARRAYBUFFER(arg1)) {
274 NAMEConstructByArrayBuffer(this, arg1, arg2, arg3); 264 NAMEConstructByArrayBuffer(this, arg1, arg2, arg3);
275 } else if (IS_NUMBER(arg1) || IS_STRING(arg1) || 265 } else if (IS_NUMBER(arg1) || IS_STRING(arg1) ||
276 IS_BOOLEAN(arg1) || IS_UNDEFINED(arg1)) { 266 IS_BOOLEAN(arg1) || IS_UNDEFINED(arg1)) {
277 NAMEConstructByLength(this, arg1); 267 NAMEConstructByLength(this, arg1);
(...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after
1006 "setUint32", DataViewSetUint32JS, 996 "setUint32", DataViewSetUint32JS,
1007 997
1008 "getFloat32", DataViewGetFloat32JS, 998 "getFloat32", DataViewGetFloat32JS,
1009 "setFloat32", DataViewSetFloat32JS, 999 "setFloat32", DataViewSetFloat32JS,
1010 1000
1011 "getFloat64", DataViewGetFloat64JS, 1001 "getFloat64", DataViewGetFloat64JS,
1012 "setFloat64", DataViewSetFloat64JS 1002 "setFloat64", DataViewSetFloat64JS
1013 ]); 1003 ]);
1014 1004
1015 }) 1005 })
OLDNEW
« 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