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

Side by Side Diff: src/js/typedarray.js

Issue 2761673003: [typedarrays] Use internal byteOffset in TypedArray.prototype.set (Closed)
Patch Set: path Created 3 years, 8 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 | test/test262/local-tests/test/built-ins/TypedArray/prototype/set/typedarray-arg-src-byteoffset-internal.js » ('j') | 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 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 } 275 }
276 276
277 function TypedArraySetFromOverlappingTypedArray(target, source, offset) { 277 function TypedArraySetFromOverlappingTypedArray(target, source, offset) {
278 var sourceElementSize = source.BYTES_PER_ELEMENT; 278 var sourceElementSize = source.BYTES_PER_ELEMENT;
279 var targetElementSize = target.BYTES_PER_ELEMENT; 279 var targetElementSize = target.BYTES_PER_ELEMENT;
280 var sourceLength = %_TypedArrayGetLength(source); 280 var sourceLength = %_TypedArrayGetLength(source);
281 281
282 // Copy left part. 282 // Copy left part.
283 function CopyLeftPart() { 283 function CopyLeftPart() {
284 // First un-mutated byte after the next write 284 // First un-mutated byte after the next write
285 var targetPtr = target.byteOffset + (offset + 1) * targetElementSize; 285 var targetPtr = %_ArrayBufferViewGetByteOffset(target) +
286 (offset + 1) * targetElementSize;
286 // Next read at sourcePtr. We do not care for memory changing before 287 // Next read at sourcePtr. We do not care for memory changing before
287 // sourcePtr - we have already copied it. 288 // sourcePtr - we have already copied it.
288 var sourcePtr = source.byteOffset; 289 var sourcePtr = %_ArrayBufferViewGetByteOffset(source);
289 for (var leftIndex = 0; 290 for (var leftIndex = 0;
290 leftIndex < sourceLength && targetPtr <= sourcePtr; 291 leftIndex < sourceLength && targetPtr <= sourcePtr;
291 leftIndex++) { 292 leftIndex++) {
292 target[offset + leftIndex] = source[leftIndex]; 293 target[offset + leftIndex] = source[leftIndex];
293 targetPtr += targetElementSize; 294 targetPtr += targetElementSize;
294 sourcePtr += sourceElementSize; 295 sourcePtr += sourceElementSize;
295 } 296 }
296 return leftIndex; 297 return leftIndex;
297 } 298 }
298 var leftIndex = CopyLeftPart(); 299 var leftIndex = CopyLeftPart();
299 300
300 // Copy right part; 301 // Copy right part;
301 function CopyRightPart() { 302 function CopyRightPart() {
302 // First unmutated byte before the next write 303 // First unmutated byte before the next write
303 var targetPtr = 304 var targetPtr = %_ArrayBufferViewGetByteOffset(target) +
304 target.byteOffset + (offset + sourceLength - 1) * targetElementSize; 305 (offset + sourceLength - 1) * targetElementSize;
305 // Next read before sourcePtr. We do not care for memory changing after 306 // Next read before sourcePtr. We do not care for memory changing after
306 // sourcePtr - we have already copied it. 307 // sourcePtr - we have already copied it.
307 var sourcePtr = 308 var sourcePtr = %_ArrayBufferViewGetByteOffset(source) +
308 source.byteOffset + sourceLength * sourceElementSize; 309 sourceLength * sourceElementSize;
309 for(var rightIndex = sourceLength - 1; 310 for(var rightIndex = sourceLength - 1;
310 rightIndex >= leftIndex && targetPtr >= sourcePtr; 311 rightIndex >= leftIndex && targetPtr >= sourcePtr;
311 rightIndex--) { 312 rightIndex--) {
312 target[offset + rightIndex] = source[rightIndex]; 313 target[offset + rightIndex] = source[rightIndex];
313 targetPtr -= targetElementSize; 314 targetPtr -= targetElementSize;
314 sourcePtr -= sourceElementSize; 315 sourcePtr -= sourceElementSize;
315 } 316 }
316 return rightIndex; 317 return rightIndex;
317 } 318 }
318 var rightIndex = CopyRightPart(); 319 var rightIndex = CopyRightPart();
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 %AddNamedProperty(GlobalNAME.prototype, 691 %AddNamedProperty(GlobalNAME.prototype,
691 "constructor", global.NAME, DONT_ENUM); 692 "constructor", global.NAME, DONT_ENUM);
692 %AddNamedProperty(GlobalNAME.prototype, 693 %AddNamedProperty(GlobalNAME.prototype,
693 "BYTES_PER_ELEMENT", ELEMENT_SIZE, 694 "BYTES_PER_ELEMENT", ELEMENT_SIZE,
694 READ_ONLY | DONT_ENUM | DONT_DELETE); 695 READ_ONLY | DONT_ENUM | DONT_DELETE);
695 endmacro 696 endmacro
696 697
697 TYPED_ARRAYS(SETUP_TYPED_ARRAY) 698 TYPED_ARRAYS(SETUP_TYPED_ARRAY)
698 699
699 }) 700 })
OLDNEW
« no previous file with comments | « no previous file | test/test262/local-tests/test/built-ins/TypedArray/prototype/set/typedarray-arg-src-byteoffset-internal.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698