| 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 811 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 822 void _setFloat32x4(int offsetInBytes, Float32x4 value) | 822 void _setFloat32x4(int offsetInBytes, Float32x4 value) |
| 823 native "TypedData_SetFloat32x4"; | 823 native "TypedData_SetFloat32x4"; |
| 824 | 824 |
| 825 Int32x4 _getInt32x4(int offsetInBytes) native "TypedData_GetInt32x4"; | 825 Int32x4 _getInt32x4(int offsetInBytes) native "TypedData_GetInt32x4"; |
| 826 void _setInt32x4(int offsetInBytes, Int32x4 value) | 826 void _setInt32x4(int offsetInBytes, Int32x4 value) |
| 827 native "TypedData_SetInt32x4"; | 827 native "TypedData_SetInt32x4"; |
| 828 | 828 |
| 829 Float64x2 _getFloat64x2(int offsetInBytes) native "TypedData_GetFloat64x2"; | 829 Float64x2 _getFloat64x2(int offsetInBytes) native "TypedData_GetFloat64x2"; |
| 830 void _setFloat64x2(int offsetInBytes, Float64x2 value) | 830 void _setFloat64x2(int offsetInBytes, Float64x2 value) |
| 831 native "TypedData_SetFloat64x2"; | 831 native "TypedData_SetFloat64x2"; |
| 832 |
| 833 /** |
| 834 * Stores the [CodeUnits] as UTF-16 units into this TypedData at |
| 835 * positions [start]..[end] (uint16 indices). |
| 836 */ |
| 837 void _setCodeUnits(CodeUnits units, |
| 838 int byteStart, int length, int skipCount) { |
| 839 assert(byteStart + length * Uint16List.BYTES_PER_ELEMENT <= lengthInBytes); |
| 840 String string = CodeUnits.stringOf(units); |
| 841 int sliceEnd = skipCount + length; |
| 842 RangeError.checkValidRange(skipCount, sliceEnd, |
| 843 string.length, |
| 844 "skipCount", "skipCount + length"); |
| 845 for (int i = 0; i < length; i++) { |
| 846 _setUint16(byteStart + i * Uint16List.BYTES_PER_ELEMENT, |
| 847 string.codeUnitAt(skipCount + i)); |
| 848 } |
| 849 } |
| 832 } | 850 } |
| 833 | 851 |
| 834 | 852 |
| 835 class _Int8Array extends _TypedList with _IntListMixin implements Int8List { | 853 class _Int8Array extends _TypedList with _IntListMixin implements Int8List { |
| 836 // Factory constructors. | 854 // Factory constructors. |
| 837 | 855 |
| 838 factory _Int8Array(int length) { | 856 factory _Int8Array(int length) { |
| 839 return _new(length); | 857 return _new(length); |
| 840 } | 858 } |
| 841 | 859 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 972 return _getIndexedInt16(index); | 990 return _getIndexedInt16(index); |
| 973 } | 991 } |
| 974 | 992 |
| 975 void operator[]=(int index, int value) { | 993 void operator[]=(int index, int value) { |
| 976 if (index < 0 || index >= length) { | 994 if (index < 0 || index >= length) { |
| 977 throw _newRangeError(index, length); | 995 throw _newRangeError(index, length); |
| 978 } | 996 } |
| 979 _setIndexedInt16(index, _toInt16(value)); | 997 _setIndexedInt16(index, _toInt16(value)); |
| 980 } | 998 } |
| 981 | 999 |
| 1000 void setRange(int start, int end, Iterable iterable, [int skipCount = 0]) { |
| 1001 if (ClassID.getID(iterable) == CodeUnits.cid) { |
| 1002 end = RangeError.checkValidRange(start, end, this.length); |
| 1003 int length = end - start; |
| 1004 int byteStart = this.offsetInBytes + start * Int16List.BYTES_PER_ELEMENT; |
| 1005 _setCodeUnits(iterable, byteStart, length, skipCount); |
| 1006 } else { |
| 1007 super.setRange(start, end, iterable, skipCount); |
| 1008 } |
| 1009 } |
| 982 | 1010 |
| 983 // Method(s) implementing TypedData interface. | 1011 // Method(s) implementing TypedData interface. |
| 984 | 1012 |
| 985 int get elementSizeInBytes { | 1013 int get elementSizeInBytes { |
| 986 return Int16List.BYTES_PER_ELEMENT; | 1014 return Int16List.BYTES_PER_ELEMENT; |
| 987 } | 1015 } |
| 988 | 1016 |
| 989 | 1017 |
| 990 // Internal utility methods. | 1018 // Internal utility methods. |
| 991 | 1019 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1022 return _getIndexedUint16(index); | 1050 return _getIndexedUint16(index); |
| 1023 } | 1051 } |
| 1024 | 1052 |
| 1025 void operator[]=(int index, int value) { | 1053 void operator[]=(int index, int value) { |
| 1026 if (index < 0 || index >= length) { | 1054 if (index < 0 || index >= length) { |
| 1027 throw _newRangeError(index, length); | 1055 throw _newRangeError(index, length); |
| 1028 } | 1056 } |
| 1029 _setIndexedUint16(index, _toUint16(value)); | 1057 _setIndexedUint16(index, _toUint16(value)); |
| 1030 } | 1058 } |
| 1031 | 1059 |
| 1060 void setRange(int start, int end, Iterable iterable, [int skipCount = 0]) { |
| 1061 if (ClassID.getID(iterable) == CodeUnits.cid) { |
| 1062 end = RangeError.checkValidRange(start, end, this.length); |
| 1063 int length = end - start; |
| 1064 int byteStart = this.offsetInBytes + start * Uint16List.BYTES_PER_ELEMENT; |
| 1065 _setCodeUnits(iterable, byteStart, length, skipCount); |
| 1066 } else { |
| 1067 super.setRange(start, end, iterable, skipCount); |
| 1068 } |
| 1069 } |
| 1032 | 1070 |
| 1033 // Method(s) implementing the TypedData interface. | 1071 // Method(s) implementing the TypedData interface. |
| 1034 | 1072 |
| 1035 int get elementSizeInBytes { | 1073 int get elementSizeInBytes { |
| 1036 return Uint16List.BYTES_PER_ELEMENT; | 1074 return Uint16List.BYTES_PER_ELEMENT; |
| 1037 } | 1075 } |
| 1038 | 1076 |
| 1039 | 1077 |
| 1040 // Internal utility methods. | 1078 // Internal utility methods. |
| 1041 | 1079 |
| (...skipping 1404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2446 // Method(s) implementing the TypedData interface. | 2484 // Method(s) implementing the TypedData interface. |
| 2447 | 2485 |
| 2448 int get lengthInBytes { | 2486 int get lengthInBytes { |
| 2449 return length * elementSizeInBytes; | 2487 return length * elementSizeInBytes; |
| 2450 } | 2488 } |
| 2451 | 2489 |
| 2452 ByteBuffer get buffer { | 2490 ByteBuffer get buffer { |
| 2453 return _typedData.buffer; | 2491 return _typedData.buffer; |
| 2454 } | 2492 } |
| 2455 | 2493 |
| 2456 final TypedData _typedData; | 2494 final _TypedList _typedData; |
| 2457 final int offsetInBytes; | 2495 final int offsetInBytes; |
| 2458 final int length; | 2496 final int length; |
| 2459 } | 2497 } |
| 2460 | 2498 |
| 2461 | 2499 |
| 2462 class _Int8ArrayView extends _TypedListView with _IntListMixin implements Int8Li
st { | 2500 class _Int8ArrayView extends _TypedListView with _IntListMixin implements Int8Li
st { |
| 2463 // Constructor. | 2501 // Constructor. |
| 2464 _Int8ArrayView(ByteBuffer buffer, [int _offsetInBytes = 0, int _length]) | 2502 _Int8ArrayView(ByteBuffer buffer, [int _offsetInBytes = 0, int _length]) |
| 2465 : super(buffer, _offsetInBytes, | 2503 : super(buffer, _offsetInBytes, |
| 2466 _defaultIfNull(_length, | 2504 _defaultIfNull(_length, |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2626 } | 2664 } |
| 2627 | 2665 |
| 2628 void operator[]=(int index, int value) { | 2666 void operator[]=(int index, int value) { |
| 2629 if (index < 0 || index >= length) { | 2667 if (index < 0 || index >= length) { |
| 2630 throw _newRangeError(index, length); | 2668 throw _newRangeError(index, length); |
| 2631 } | 2669 } |
| 2632 _typedData._setInt16(offsetInBytes + (index * Int16List.BYTES_PER_ELEMENT), | 2670 _typedData._setInt16(offsetInBytes + (index * Int16List.BYTES_PER_ELEMENT), |
| 2633 _toInt16(value)); | 2671 _toInt16(value)); |
| 2634 } | 2672 } |
| 2635 | 2673 |
| 2674 void setRange(int start, int end, Iterable iterable, [int skipCount = 0]) { |
| 2675 if (ClassID.getID(iterable) == CodeUnits.cid) { |
| 2676 end = RangeError.checkValidRange(start, end, this.length); |
| 2677 int length = end - start; |
| 2678 int byteStart = this.offsetInBytes + start * Int16List.BYTES_PER_ELEMENT; |
| 2679 _typedData._setCodeUnits(iterable, byteStart, length, skipCount); |
| 2680 } else { |
| 2681 super.setRange(start, end, iterable, skipCount); |
| 2682 } |
| 2683 } |
| 2636 | 2684 |
| 2637 // Method(s) implementing TypedData interface. | 2685 // Method(s) implementing TypedData interface. |
| 2638 | 2686 |
| 2639 int get elementSizeInBytes { | 2687 int get elementSizeInBytes { |
| 2640 return Int16List.BYTES_PER_ELEMENT; | 2688 return Int16List.BYTES_PER_ELEMENT; |
| 2641 } | 2689 } |
| 2642 | 2690 |
| 2643 | 2691 |
| 2644 // Internal utility methods. | 2692 // Internal utility methods. |
| 2645 | 2693 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 2674 } | 2722 } |
| 2675 | 2723 |
| 2676 void operator[]=(int index, int value) { | 2724 void operator[]=(int index, int value) { |
| 2677 if (index < 0 || index >= length) { | 2725 if (index < 0 || index >= length) { |
| 2678 throw _newRangeError(index, length); | 2726 throw _newRangeError(index, length); |
| 2679 } | 2727 } |
| 2680 _typedData._setUint16(offsetInBytes + (index * Uint16List.BYTES_PER_ELEMENT)
, | 2728 _typedData._setUint16(offsetInBytes + (index * Uint16List.BYTES_PER_ELEMENT)
, |
| 2681 _toUint16(value)); | 2729 _toUint16(value)); |
| 2682 } | 2730 } |
| 2683 | 2731 |
| 2732 void setRange(int start, int end, Iterable iterable, [int skipCount = 0]) { |
| 2733 if (ClassID.getID(iterable) == CodeUnits.cid) { |
| 2734 end = RangeError.checkValidRange(start, end, this.length); |
| 2735 int length = end - start; |
| 2736 int byteStart = this.offsetInBytes + start * Uint16List.BYTES_PER_ELEMENT; |
| 2737 _typedData._setCodeUnits(iterable, byteStart, length, skipCount); |
| 2738 } else { |
| 2739 super.setRange(start, end, iterable, skipCount); |
| 2740 } |
| 2741 } |
| 2684 | 2742 |
| 2685 // Method(s) implementing TypedData interface. | 2743 // Method(s) implementing TypedData interface. |
| 2686 | 2744 |
| 2687 int get elementSizeInBytes { | 2745 int get elementSizeInBytes { |
| 2688 return Uint16List.BYTES_PER_ELEMENT; | 2746 return Uint16List.BYTES_PER_ELEMENT; |
| 2689 } | 2747 } |
| 2690 | 2748 |
| 2691 | |
| 2692 // Internal utility methods. | 2749 // Internal utility methods. |
| 2693 | 2750 |
| 2694 Uint16List _createList(int length) { | 2751 Uint16List _createList(int length) { |
| 2695 return new Uint16List(length); | 2752 return new Uint16List(length); |
| 2696 } | 2753 } |
| 2697 } | 2754 } |
| 2698 | 2755 |
| 2699 | 2756 |
| 2700 class _Int32ArrayView extends _TypedListView with _IntListMixin implements Int32
List { | 2757 class _Int32ArrayView extends _TypedListView with _IntListMixin implements Int32
List { |
| 2701 // Constructor. | 2758 // Constructor. |
| (...skipping 784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3486 return value; | 3543 return value; |
| 3487 } | 3544 } |
| 3488 return object; | 3545 return object; |
| 3489 } | 3546 } |
| 3490 | 3547 |
| 3491 | 3548 |
| 3492 _newRangeError(int index, int length) { | 3549 _newRangeError(int index, int length) { |
| 3493 String message = "$index must be in the range [0..$length)"; | 3550 String message = "$index must be in the range [0..$length)"; |
| 3494 return new RangeError(message); | 3551 return new RangeError(message); |
| 3495 } | 3552 } |
| OLD | NEW |