| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 // patch classes for Int8List ..... Float64List and ByteData implementations. | 5 // patch classes for Int8List ..... Float64List and ByteData implementations. |
| 6 | 6 |
| 7 import "dart:_internal"; | 7 import "dart:_internal"; |
| 8 import 'dart:math' show Random; | 8 import 'dart:math' show Random; |
| 9 | 9 |
| 10 patch class Int8List { | 10 patch class Int8List { |
| (...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 if (from is _TypedListBase) { | 554 if (from is _TypedListBase) { |
| 555 if (this.elementSizeInBytes == from.elementSizeInBytes) { | 555 if (this.elementSizeInBytes == from.elementSizeInBytes) { |
| 556 if ((count < 10) && (from.buffer != this.buffer)) { | 556 if ((count < 10) && (from.buffer != this.buffer)) { |
| 557 Lists.copy(from, skipCount, this, start, count); | 557 Lists.copy(from, skipCount, this, start, count); |
| 558 return; | 558 return; |
| 559 } else if (this.buffer._data._setRange( | 559 } else if (this.buffer._data._setRange( |
| 560 start * elementSizeInBytes + this.offsetInBytes, | 560 start * elementSizeInBytes + this.offsetInBytes, |
| 561 count * elementSizeInBytes, | 561 count * elementSizeInBytes, |
| 562 from.buffer._data, | 562 from.buffer._data, |
| 563 skipCount * elementSizeInBytes + from.offsetInBytes, | 563 skipCount * elementSizeInBytes + from.offsetInBytes, |
| 564 this._cid, from._cid)) { | 564 ClassID.getID(this), ClassID.getID(from))) { |
| 565 return; | 565 return; |
| 566 } | 566 } |
| 567 } else if (from.buffer == this.buffer) { | 567 } else if (from.buffer == this.buffer) { |
| 568 // Different element sizes, but same buffer means that we need | 568 // Different element sizes, but same buffer means that we need |
| 569 // an intermediate structure. | 569 // an intermediate structure. |
| 570 // TODO(srdjan): Optimize to skip copying if the range does not overlap. | 570 // TODO(srdjan): Optimize to skip copying if the range does not overlap. |
| 571 final temp_buffer = new List(count); | 571 final temp_buffer = new List(count); |
| 572 for (int i = 0; i < count; i++) { | 572 for (int i = 0; i < count; i++) { |
| 573 temp_buffer[i] = from[skipCount + i]; | 573 temp_buffer[i] = from[skipCount + i]; |
| 574 } | 574 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 601 | 601 |
| 602 // Returns true if operation succeeds. | 602 // Returns true if operation succeeds. |
| 603 // 'fromCid' and 'toCid' may be cid-s of the views and therefore may not | 603 // 'fromCid' and 'toCid' may be cid-s of the views and therefore may not |
| 604 // match the cids of 'this' and 'from'. | 604 // match the cids of 'this' and 'from'. |
| 605 // Uses toCid and fromCid to decide if clamping is necessary. | 605 // Uses toCid and fromCid to decide if clamping is necessary. |
| 606 // Element size of toCid and fromCid must match (test at caller). | 606 // Element size of toCid and fromCid must match (test at caller). |
| 607 bool _setRange(int startInBytes, int lengthInBytes, | 607 bool _setRange(int startInBytes, int lengthInBytes, |
| 608 _TypedListBase from, int startFromInBytes, | 608 _TypedListBase from, int startFromInBytes, |
| 609 int toCid, int fromCid) | 609 int toCid, int fromCid) |
| 610 native "TypedData_setRange"; | 610 native "TypedData_setRange"; |
| 611 | |
| 612 int get _cid native "Object_cid"; | |
| 613 } | 611 } |
| 614 | 612 |
| 615 | 613 |
| 616 class _ByteBuffer implements ByteBuffer { | 614 class _ByteBuffer implements ByteBuffer { |
| 617 final _TypedList _data; | 615 final _TypedList _data; |
| 618 | 616 |
| 619 _ByteBuffer(this._data); | 617 _ByteBuffer(this._data); |
| 620 | 618 |
| 621 // Forward calls to _data. | 619 // Forward calls to _data. |
| 622 int get lengthInBytes => _data.lengthInBytes; | 620 int get lengthInBytes => _data.lengthInBytes; |
| (...skipping 3023 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3646 return value; | 3644 return value; |
| 3647 } | 3645 } |
| 3648 return object; | 3646 return object; |
| 3649 } | 3647 } |
| 3650 | 3648 |
| 3651 | 3649 |
| 3652 void _throwRangeError(int index, int length) { | 3650 void _throwRangeError(int index, int length) { |
| 3653 String message = "$index must be in the range [0..$length)"; | 3651 String message = "$index must be in the range [0..$length)"; |
| 3654 throw new RangeError(message); | 3652 throw new RangeError(message); |
| 3655 } | 3653 } |
| OLD | NEW |