OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 /** | 5 /** |
6 * A random-access sequence of bytes that also provides random access to | 6 * A random-access sequence of bytes that also provides random access to |
7 * the fixed-width integers and floating point numbers represented by | 7 * the fixed-width integers and floating point numbers represented by |
8 * those bytes. Byte arrays may be used to pack and unpack data from | 8 * those bytes. Byte arrays may be used to pack and unpack data from |
9 * external sources (such as networks or files systems), and to process | 9 * external sources (such as networks or files systems), and to process |
10 * large quantities of numerical data more efficiently than would be possible | 10 * large quantities of numerical data more efficiently than would be possible |
(...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
678 */ | 678 */ |
679 Float64List.view(ByteArray array, [int start, int length]); | 679 Float64List.view(ByteArray array, [int start, int length]); |
680 } | 680 } |
681 | 681 |
682 | 682 |
683 class _Int8ArrayFactory { | 683 class _Int8ArrayFactory { |
684 factory Int8List(int length) { | 684 factory Int8List(int length) { |
685 return new _Int8Array(length); | 685 return new _Int8Array(length); |
686 } | 686 } |
687 | 687 |
688 factory Int8List.view(ByteArray array, [int start, int length]) { | 688 factory Int8List.view(ByteArray array, [int start = 0, int length]) { |
689 return new _Int8ArrayView(array, start, length); | 689 return new _Int8ArrayView(array, start, length); |
690 } | 690 } |
691 } | 691 } |
692 | 692 |
693 | 693 |
694 class _Uint8ArrayFactory { | 694 class _Uint8ArrayFactory { |
695 factory Uint8List(int length) { | 695 factory Uint8List(int length) { |
696 return new _Uint8Array(length); | 696 return new _Uint8Array(length); |
697 } | 697 } |
698 | 698 |
699 factory Uint8List.view(ByteArray array, [int start, int length]) { | 699 factory Uint8List.view(ByteArray array, [int start = 0, int length]) { |
700 return new _Uint8ArrayView(array, start, length); | 700 return new _Uint8ArrayView(array, start, length); |
701 } | 701 } |
702 } | 702 } |
703 | 703 |
704 | 704 |
705 class _Int16ArrayFactory { | 705 class _Int16ArrayFactory { |
706 factory Int16List(int length) { | 706 factory Int16List(int length) { |
707 return new _Int16Array(length); | 707 return new _Int16Array(length); |
708 } | 708 } |
709 | 709 |
710 factory Int16List.view(ByteArray array, [int start, int length]) { | 710 factory Int16List.view(ByteArray array, [int start = 0, int length]) { |
711 return new _Int16ArrayView(array, start, length); | 711 return new _Int16ArrayView(array, start, length); |
712 } | 712 } |
713 } | 713 } |
714 | 714 |
715 | 715 |
716 class _Uint16ArrayFactory { | 716 class _Uint16ArrayFactory { |
717 factory Uint16List(int length) { | 717 factory Uint16List(int length) { |
718 return new _Uint16Array(length); | 718 return new _Uint16Array(length); |
719 } | 719 } |
720 | 720 |
721 factory Uint16List.view(ByteArray array, [int start, int length]) { | 721 factory Uint16List.view(ByteArray array, [int start = 0, int length]) { |
722 return new _Uint16ArrayView(array, start, length); | 722 return new _Uint16ArrayView(array, start, length); |
723 } | 723 } |
724 } | 724 } |
725 | 725 |
726 | 726 |
727 class _Int32ArrayFactory { | 727 class _Int32ArrayFactory { |
728 factory Int32List(int length) { | 728 factory Int32List(int length) { |
729 return new _Int32Array(length); | 729 return new _Int32Array(length); |
730 } | 730 } |
731 | 731 |
732 factory Int32List.view(ByteArray array, [int start, int length]) { | 732 factory Int32List.view(ByteArray array, [int start = 0, int length]) { |
733 return new _Int32ArrayView(array, start, length); | 733 return new _Int32ArrayView(array, start, length); |
734 } | 734 } |
735 } | 735 } |
736 | 736 |
737 | 737 |
738 class _Uint32ArrayFactory { | 738 class _Uint32ArrayFactory { |
739 factory Uint32List(int length) { | 739 factory Uint32List(int length) { |
740 return new _Uint32Array(length); | 740 return new _Uint32Array(length); |
741 } | 741 } |
742 | 742 |
743 factory Uint32List.view(ByteArray array, [int start, int length]) { | 743 factory Uint32List.view(ByteArray array, [int start = 0, int length]) { |
744 return new _Uint32ArrayView(array, start, length); | 744 return new _Uint32ArrayView(array, start, length); |
745 } | 745 } |
746 } | 746 } |
747 | 747 |
748 | 748 |
749 class _Int64ArrayFactory { | 749 class _Int64ArrayFactory { |
750 factory Int64List(int length) { | 750 factory Int64List(int length) { |
751 return new _Int64Array(length); | 751 return new _Int64Array(length); |
752 } | 752 } |
753 | 753 |
754 factory Int64List.view(ByteArray array, [int start, int length]) { | 754 factory Int64List.view(ByteArray array, [int start = 0, int length]) { |
755 return new _Int64ArrayView(array, start, length); | 755 return new _Int64ArrayView(array, start, length); |
756 } | 756 } |
757 } | 757 } |
758 | 758 |
759 | 759 |
760 class _Uint64ArrayFactory { | 760 class _Uint64ArrayFactory { |
761 factory Uint64List(int length) { | 761 factory Uint64List(int length) { |
762 return new _Uint64Array(length); | 762 return new _Uint64Array(length); |
763 } | 763 } |
764 | 764 |
765 factory Uint64List.view(ByteArray array, [int start, int length]) { | 765 factory Uint64List.view(ByteArray array, [int start = 0, int length]) { |
766 return new _Uint64ArrayView(array, start, length); | 766 return new _Uint64ArrayView(array, start, length); |
767 } | 767 } |
768 } | 768 } |
769 | 769 |
770 | 770 |
771 class _Float32ArrayFactory { | 771 class _Float32ArrayFactory { |
772 factory Float32List(int length) { | 772 factory Float32List(int length) { |
773 return new _Float32Array(length); | 773 return new _Float32Array(length); |
774 } | 774 } |
775 | 775 |
776 factory Float32List.view(ByteArray array, [int start, int length]) { | 776 factory Float32List.view(ByteArray array, [int start = 0, int length]) { |
777 return new _Float32ArrayView(array, start, length); | 777 return new _Float32ArrayView(array, start, length); |
778 } | 778 } |
779 } | 779 } |
780 | 780 |
781 | 781 |
782 class _Float64ArrayFactory { | 782 class _Float64ArrayFactory { |
783 factory Float64List(int length) { | 783 factory Float64List(int length) { |
784 return new _Float64Array(length); | 784 return new _Float64Array(length); |
785 } | 785 } |
786 | 786 |
787 factory Float64List.view(ByteArray array, [int start, int length]) { | 787 factory Float64List.view(ByteArray array, [int start = 0, int length]) { |
788 return new _Float64ArrayView(array, start, length); | 788 return new _Float64ArrayView(array, start, length); |
789 } | 789 } |
790 } | 790 } |
791 | 791 |
792 | 792 |
793 abstract class _ByteArrayBase { | 793 abstract class _ByteArrayBase { |
794 abstract int lengthInBytes(); | |
795 | |
796 abstract int bytesPerElement(); | |
797 | |
798 abstract operator[](int index); | |
794 | 799 |
795 // Methods implementing the Collection interface. | 800 // Methods implementing the Collection interface. |
796 | 801 |
797 void forEach(void f(element)) { | 802 void forEach(void f(element)) { |
798 var len = this.length; | 803 var len = this.length; |
799 for (var i = 0; i < len; i++) { | 804 for (var i = 0; i < len; i++) { |
800 f(this[i]); | 805 f(this[i]); |
801 } | 806 } |
802 } | 807 } |
803 | 808 |
804 Collection map(f(element)) { | 809 Collection map(f(element)) { |
805 return Collections.map(this, | 810 return Collections.map(this, |
806 new GrowableObjectArray.withCapacity(length), | 811 new GrowableObjectArray.withCapacity(length), |
807 f); | 812 f); |
808 } | 813 } |
809 | 814 |
810 Collection filter(bool f(element)) { | 815 Collection filter(bool f(element)) { |
811 return Collections.filter(this, new GrowableObjectArray(), f); | 816 return Collections.filter(this, new GrowableObjectArray(), f); |
812 } | 817 } |
813 | 818 |
814 bool every(bool f(element)) { | 819 bool every(bool f(element)) { |
815 return Collections.every(this, f); | 820 return Collections.every(this, f); |
816 } | 821 } |
817 | 822 |
818 bool some(bool f(element)) { | 823 bool some(bool f(element)) { |
819 return Collections.some(this, f);; | 824 return Collections.some(this, f); |
820 } | 825 } |
821 | 826 |
822 bool isEmpty() { | 827 bool isEmpty() { |
823 return this.length === 0; | 828 return this.length === 0; |
824 } | 829 } |
825 | 830 |
826 int get length() { | 831 int get length() { |
827 return _length(); | 832 return _length(); |
828 } | 833 } |
829 | 834 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
881 "Cannot remove from a non-extendable array"); | 886 "Cannot remove from a non-extendable array"); |
882 } | 887 } |
883 | 888 |
884 void insertRange(int start, int length, [initialValue]) { | 889 void insertRange(int start, int length, [initialValue]) { |
885 throw const UnsupportedOperationException( | 890 throw const UnsupportedOperationException( |
886 "Cannot add to a non-extendable array"); | 891 "Cannot add to a non-extendable array"); |
887 } | 892 } |
888 | 893 |
889 ByteArray asByteArray([int start = 0, int length]) { | 894 ByteArray asByteArray([int start = 0, int length]) { |
890 if (length === null) { | 895 if (length === null) { |
891 length = this.lengthInBytes(); | 896 length = this.length; |
892 } | 897 } |
893 return new _ByteArrayView(this, start, length); | 898 _rangeCheck(this.length, start, length); |
899 return new _ByteArrayView(this, | |
900 start * this.bytesPerElement(), | |
901 length * this.bytesPerElement()); | |
siva
2012/06/21 23:33:08
why not
assert(this.bytesPerElement() === 1);
and
cshapiro
2012/06/22 04:27:00
Good question. Keeping the code exactly the same
| |
894 } | 902 } |
895 | 903 |
896 int _length() native "ByteArray_getLength"; | 904 int _length() native "ByteArray_getLength"; |
897 | 905 |
898 void _setRange(int startInBytes, int lengthInBytes, | 906 void _setRange(int startInBytes, int lengthInBytes, |
899 _ByteArrayBase from, int startFromInBytes) | 907 _ByteArrayBase from, int startFromInBytes) |
900 native "ByteArray_setRange"; | 908 native "ByteArray_setRange"; |
901 | 909 |
902 int _getInt8(int byteOffset) native "ByteArray_getInt8"; | 910 int _getInt8(int byteOffset) native "ByteArray_getInt8"; |
903 int _setInt8(int byteOffset, int value) native "ByteArray_setInt8"; | 911 int _setInt8(int byteOffset, int value) native "ByteArray_setInt8"; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
962 | 970 |
963 | 971 |
964 int _toInt64(int value) { | 972 int _toInt64(int value) { |
965 return _toInt(value, 0xFFFFFFFFFFFFFFFF); | 973 return _toInt(value, 0xFFFFFFFFFFFFFFFF); |
966 } | 974 } |
967 int _toUint64(int value) { | 975 int _toUint64(int value) { |
968 return value & 0xFFFFFFFFFFFFFFFF; | 976 return value & 0xFFFFFFFFFFFFFFFF; |
969 } | 977 } |
970 | 978 |
971 | 979 |
972 void _rangeCheck(List a, int start, int length) { | 980 void _rangeCheck(int listLength, int start, int length) { |
973 if (length < 0) { | 981 if (length < 0) { |
974 throw new IllegalArgumentException("negative length $length"); | 982 throw new IllegalArgumentException("negative length $length"); |
975 } | 983 } |
976 if (start < 0) { | 984 if (start < 0) { |
977 throw new IndexOutOfRangeException("negative start $start"); | 985 throw new IllegalArgumentException("negative start $start"); |
978 } | 986 } |
979 if (start + length > a.length) { | 987 if (start + length > listLength) { |
980 throw new IndexOutOfRangeException(start + length); | 988 throw new IndexOutOfRangeException(start + length); |
981 } | 989 } |
982 } | 990 } |
983 | 991 |
984 | 992 |
993 int _requireInteger(object) { | |
994 if (object is int) { | |
995 return object; | |
996 } | |
997 throw new IllegalArgumentException("$object is not an integer"); | |
998 } | |
999 | |
1000 | |
1001 int _requireIntegerOrNull(object, value) { | |
1002 if (object is int) { | |
1003 return object; | |
1004 } | |
1005 if (object === null) { | |
1006 return _requireInteger(value); | |
1007 } | |
1008 throw new IllegalArgumentException("$object is not an integer or null"); | |
1009 } | |
1010 | |
1011 | |
985 class _Int8Array extends _ByteArrayBase implements Int8List { | 1012 class _Int8Array extends _ByteArrayBase implements Int8List { |
986 factory _Int8Array(int length) { | 1013 factory _Int8Array(int length) { |
987 return _new(length); | 1014 return _new(length); |
988 } | 1015 } |
989 | 1016 |
990 factory _Int8Array.view(ByteArray array, [int start = 0, int length]) { | 1017 factory _Int8Array.view(ByteArray array, [int start = 0, int length]) { |
991 if (length === null) { | 1018 if (length === null) { |
992 length = array.lengthInBytes(); | 1019 length = array.lengthInBytes(); |
993 } | 1020 } |
994 return new _Int8ArrayView(array, start, length); | 1021 return new _Int8ArrayView(array, start, length); |
995 } | 1022 } |
996 | 1023 |
997 int operator[](int index) { | 1024 int operator[](int index) { |
998 return _getIndexed(index); | 1025 return _getIndexed(index); |
999 } | 1026 } |
1000 | 1027 |
1001 void operator[]=(int index, int value) { | 1028 void operator[]=(int index, int value) { |
1002 _setIndexed(index, _toInt8(value)); | 1029 _setIndexed(index, _toInt8(value)); |
1003 } | 1030 } |
1004 | 1031 |
1005 Iterator<int> iterator() { | 1032 Iterator<int> iterator() { |
1006 return new _ByteArrayIterator<int>(this); | 1033 return new _ByteArrayIterator<int>(this); |
1007 } | 1034 } |
1008 | 1035 |
1009 List<int> getRange(int start, int length) { | 1036 List<int> getRange(int start, int length) { |
1010 _rangeCheck(this, start, length); | 1037 _rangeCheck(this.length, start, length); |
1011 List<int> result = _new(length); | 1038 List<int> result = _new(length); |
1012 result.setRange(0, length, this, start); | 1039 result.setRange(0, length, this, start); |
1013 return result; | 1040 return result; |
1014 } | 1041 } |
1015 | 1042 |
1016 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | 1043 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
1017 if (from is _Int8Array) { | 1044 if (from is _Int8Array) { |
1018 int startInBytes = start * _BYTES_PER_ELEMENT; | 1045 _setRange(start * _BYTES_PER_ELEMENT, |
1019 int lengthInBytes = length * _BYTES_PER_ELEMENT; | 1046 length * _BYTES_PER_ELEMENT, |
1020 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; | 1047 from, |
1021 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); | 1048 startFrom * _BYTES_PER_ELEMENT); |
1022 } else { | 1049 } else { |
1023 Arrays.copy(from, startFrom, this, start, length); | 1050 Arrays.copy(from, startFrom, this, start, length); |
1024 } | 1051 } |
1025 } | 1052 } |
1026 | 1053 |
1027 String toString() { | 1054 String toString() { |
1028 return Collections.collectionToString(this); | 1055 return Collections.collectionToString(this); |
1029 } | 1056 } |
1030 | 1057 |
1031 int bytesPerElement() { | 1058 int bytesPerElement() { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1063 | 1090 |
1064 void operator[]=(int index, int value) { | 1091 void operator[]=(int index, int value) { |
1065 _setIndexed(index, _toUint8(value)); | 1092 _setIndexed(index, _toUint8(value)); |
1066 } | 1093 } |
1067 | 1094 |
1068 Iterator<int> iterator() { | 1095 Iterator<int> iterator() { |
1069 return new _ByteArrayIterator<int>(this); | 1096 return new _ByteArrayIterator<int>(this); |
1070 } | 1097 } |
1071 | 1098 |
1072 List<int> getRange(int start, int length) { | 1099 List<int> getRange(int start, int length) { |
1073 _rangeCheck(this, start, length); | 1100 _rangeCheck(this.length, start, length); |
1074 List<int> result = _new(length); | 1101 List<int> result = _new(length); |
1075 result.setRange(0, length, this, start); | 1102 result.setRange(0, length, this, start); |
1076 return result; | 1103 return result; |
1077 } | 1104 } |
1078 | 1105 |
1079 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | 1106 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
1080 if (from is _Uint8Array) { | 1107 if (from is _Uint8Array) { |
1081 int startInBytes = start * _BYTES_PER_ELEMENT; | 1108 _setRange(start * _BYTES_PER_ELEMENT, |
1082 int lengthInBytes = length * _BYTES_PER_ELEMENT; | 1109 length * _BYTES_PER_ELEMENT, |
1083 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; | 1110 from, |
1084 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); | 1111 startFrom * _BYTES_PER_ELEMENT); |
1085 } else { | 1112 } else { |
1086 Arrays.copy(from, startFrom, this, start, length); | 1113 Arrays.copy(from, startFrom, this, start, length); |
1087 } | 1114 } |
1088 } | 1115 } |
1089 | 1116 |
1090 String toString() { | 1117 String toString() { |
1091 return Collections.collectionToString(this); | 1118 return Collections.collectionToString(this); |
1092 } | 1119 } |
1093 | 1120 |
1094 int bytesPerElement() { | 1121 int bytesPerElement() { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1126 | 1153 |
1127 void operator[]=(int index, int value) { | 1154 void operator[]=(int index, int value) { |
1128 _setIndexed(index, _toInt16(value)); | 1155 _setIndexed(index, _toInt16(value)); |
1129 } | 1156 } |
1130 | 1157 |
1131 Iterator<int> iterator() { | 1158 Iterator<int> iterator() { |
1132 return new _ByteArrayIterator<int>(this); | 1159 return new _ByteArrayIterator<int>(this); |
1133 } | 1160 } |
1134 | 1161 |
1135 List<int> getRange(int start, int length) { | 1162 List<int> getRange(int start, int length) { |
1136 _rangeCheck(this, start, length); | 1163 _rangeCheck(this.length, start, length); |
1137 List<int> result = _new(length); | 1164 List<int> result = _new(length); |
1138 result.setRange(0, length, this, start); | 1165 result.setRange(0, length, this, start); |
1139 return result; | 1166 return result; |
1140 } | 1167 } |
1141 | 1168 |
1142 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | 1169 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
1143 if (from is _Int16Array) { | 1170 if (from is _Int16Array) { |
1144 int startInBytes = start * _BYTES_PER_ELEMENT; | 1171 _setRange(start * _BYTES_PER_ELEMENT, |
1145 int lengthInBytes = length * _BYTES_PER_ELEMENT; | 1172 length * _BYTES_PER_ELEMENT, |
1146 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; | 1173 from, |
1147 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); | 1174 startFrom * _BYTES_PER_ELEMENT); |
1148 } else { | 1175 } else { |
1149 Arrays.copy(from, startFrom, this, start, length); | 1176 Arrays.copy(from, startFrom, this, start, length); |
1150 } | 1177 } |
1151 } | 1178 } |
1152 | 1179 |
1153 String toString() { | 1180 String toString() { |
1154 return Collections.collectionToString(this); | 1181 return Collections.collectionToString(this); |
1155 } | 1182 } |
1156 | 1183 |
1157 int bytesPerElement() { | 1184 int bytesPerElement() { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1189 | 1216 |
1190 void operator[]=(int index, int value) { | 1217 void operator[]=(int index, int value) { |
1191 _setIndexed(index, _toUint16(value)); | 1218 _setIndexed(index, _toUint16(value)); |
1192 } | 1219 } |
1193 | 1220 |
1194 Iterator<int> iterator() { | 1221 Iterator<int> iterator() { |
1195 return new _ByteArrayIterator<int>(this); | 1222 return new _ByteArrayIterator<int>(this); |
1196 } | 1223 } |
1197 | 1224 |
1198 List<int> getRange(int start, int length) { | 1225 List<int> getRange(int start, int length) { |
1199 _rangeCheck(this, start, length); | 1226 _rangeCheck(this.length, start, length); |
1200 List<int> result = _new(length); | 1227 List<int> result = _new(length); |
1201 result.setRange(0, length, this, start); | 1228 result.setRange(0, length, this, start); |
1202 return result; | 1229 return result; |
1203 } | 1230 } |
1204 | 1231 |
1205 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | 1232 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
1206 if (from is _Uint16Array) { | 1233 if (from is _Uint16Array) { |
1207 int startInBytes = start * _BYTES_PER_ELEMENT; | 1234 _setRange(start * _BYTES_PER_ELEMENT, |
1208 int lengthInBytes = length * _BYTES_PER_ELEMENT; | 1235 length * _BYTES_PER_ELEMENT, |
1209 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; | 1236 from, |
1210 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); | 1237 startFrom * _BYTES_PER_ELEMENT); |
1211 } else { | 1238 } else { |
1212 Arrays.copy(from, startFrom, this, start, length); | 1239 Arrays.copy(from, startFrom, this, start, length); |
1213 } | 1240 } |
1214 } | 1241 } |
1215 | 1242 |
1216 String toString() { | 1243 String toString() { |
1217 return Collections.collectionToString(this); | 1244 return Collections.collectionToString(this); |
1218 } | 1245 } |
1219 | 1246 |
1220 int bytesPerElement() { | 1247 int bytesPerElement() { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1252 | 1279 |
1253 void operator[]=(int index, int value) { | 1280 void operator[]=(int index, int value) { |
1254 _setIndexed(index, _toInt32(value)); | 1281 _setIndexed(index, _toInt32(value)); |
1255 } | 1282 } |
1256 | 1283 |
1257 Iterator<int> iterator() { | 1284 Iterator<int> iterator() { |
1258 return new _ByteArrayIterator<int>(this); | 1285 return new _ByteArrayIterator<int>(this); |
1259 } | 1286 } |
1260 | 1287 |
1261 List<int> getRange(int start, int length) { | 1288 List<int> getRange(int start, int length) { |
1262 _rangeCheck(this, start, length); | 1289 _rangeCheck(this.length, start, length); |
1263 List<int> result = _new(length); | 1290 List<int> result = _new(length); |
1264 result.setRange(0, length, this, start); | 1291 result.setRange(0, length, this, start); |
1265 return result; | 1292 return result; |
1266 } | 1293 } |
1267 | 1294 |
1268 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | 1295 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
1269 if (from is _Int32Array) { | 1296 if (from is _Int32Array) { |
1270 int startInBytes = start * _BYTES_PER_ELEMENT; | 1297 _setRange(start * _BYTES_PER_ELEMENT, |
1271 int lengthInBytes = length * _BYTES_PER_ELEMENT; | 1298 length * _BYTES_PER_ELEMENT, |
1272 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; | 1299 from, |
1273 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); | 1300 startFrom * _BYTES_PER_ELEMENT); |
1274 } else { | 1301 } else { |
1275 Arrays.copy(from, startFrom, this, start, length); | 1302 Arrays.copy(from, startFrom, this, start, length); |
1276 } | 1303 } |
1277 } | 1304 } |
1278 | 1305 |
1279 String toString() { | 1306 String toString() { |
1280 return Collections.collectionToString(this); | 1307 return Collections.collectionToString(this); |
1281 } | 1308 } |
1282 | 1309 |
1283 int bytesPerElement() { | 1310 int bytesPerElement() { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1315 | 1342 |
1316 void operator[]=(int index, int value) { | 1343 void operator[]=(int index, int value) { |
1317 _setIndexed(index, _toUint32(value)); | 1344 _setIndexed(index, _toUint32(value)); |
1318 } | 1345 } |
1319 | 1346 |
1320 Iterator<int> iterator() { | 1347 Iterator<int> iterator() { |
1321 return new _ByteArrayIterator<int>(this); | 1348 return new _ByteArrayIterator<int>(this); |
1322 } | 1349 } |
1323 | 1350 |
1324 List<int> getRange(int start, int length) { | 1351 List<int> getRange(int start, int length) { |
1325 _rangeCheck(this, start, length); | 1352 _rangeCheck(this.length, start, length); |
1326 List<int> result = _new(length); | 1353 List<int> result = _new(length); |
1327 result.setRange(0, length, this, start); | 1354 result.setRange(0, length, this, start); |
1328 return result; | 1355 return result; |
1329 } | 1356 } |
1330 | 1357 |
1331 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | 1358 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
1332 if (from is _Uint32Array) { | 1359 if (from is _Uint32Array) { |
1333 int startInBytes = start * _BYTES_PER_ELEMENT; | 1360 _setRange(start * _BYTES_PER_ELEMENT, |
1334 int lengthInBytes = length * _BYTES_PER_ELEMENT; | 1361 length * _BYTES_PER_ELEMENT, |
1335 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; | 1362 from, |
1336 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); | 1363 startFrom * _BYTES_PER_ELEMENT); |
1337 } else { | 1364 } else { |
1338 Arrays.copy(from, startFrom, this, start, length); | 1365 Arrays.copy(from, startFrom, this, start, length); |
1339 } | 1366 } |
1340 } | 1367 } |
1341 | 1368 |
1342 String toString() { | 1369 String toString() { |
1343 return Collections.collectionToString(this); | 1370 return Collections.collectionToString(this); |
1344 } | 1371 } |
1345 | 1372 |
1346 int bytesPerElement() { | 1373 int bytesPerElement() { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1378 | 1405 |
1379 void operator[]=(int index, int value) { | 1406 void operator[]=(int index, int value) { |
1380 _setIndexed(index, _toInt64(value)); | 1407 _setIndexed(index, _toInt64(value)); |
1381 } | 1408 } |
1382 | 1409 |
1383 Iterator<int> iterator() { | 1410 Iterator<int> iterator() { |
1384 return new _ByteArrayIterator<int>(this); | 1411 return new _ByteArrayIterator<int>(this); |
1385 } | 1412 } |
1386 | 1413 |
1387 List<int> getRange(int start, int length) { | 1414 List<int> getRange(int start, int length) { |
1388 _rangeCheck(this, start, length); | 1415 _rangeCheck(this.length, start, length); |
1389 List<int> result = _new(length); | 1416 List<int> result = _new(length); |
1390 result.setRange(0, length, this, start); | 1417 result.setRange(0, length, this, start); |
1391 return result; | 1418 return result; |
1392 } | 1419 } |
1393 | 1420 |
1394 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | 1421 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
1395 if (from is _Int64Array) { | 1422 if (from is _Int64Array) { |
1396 int startInBytes = start * _BYTES_PER_ELEMENT; | 1423 _setRange(start * _BYTES_PER_ELEMENT, |
1397 int lengthInBytes = length * _BYTES_PER_ELEMENT; | 1424 length * _BYTES_PER_ELEMENT, |
1398 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; | 1425 from, |
1399 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); | 1426 startFrom * _BYTES_PER_ELEMENT); |
1400 } else { | 1427 } else { |
1401 Arrays.copy(from, startFrom, this, start, length); | 1428 Arrays.copy(from, startFrom, this, start, length); |
1402 } | 1429 } |
1403 } | 1430 } |
1404 | 1431 |
1405 String toString() { | 1432 String toString() { |
1406 return Collections.collectionToString(this); | 1433 return Collections.collectionToString(this); |
1407 } | 1434 } |
1408 | 1435 |
1409 int bytesPerElement() { | 1436 int bytesPerElement() { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1441 | 1468 |
1442 void operator[]=(int index, int value) { | 1469 void operator[]=(int index, int value) { |
1443 _setIndexed(index, _toUint64(value)); | 1470 _setIndexed(index, _toUint64(value)); |
1444 } | 1471 } |
1445 | 1472 |
1446 Iterator<int> iterator() { | 1473 Iterator<int> iterator() { |
1447 return new _ByteArrayIterator<int>(this); | 1474 return new _ByteArrayIterator<int>(this); |
1448 } | 1475 } |
1449 | 1476 |
1450 List<int> getRange(int start, int length) { | 1477 List<int> getRange(int start, int length) { |
1451 _rangeCheck(this, start, length); | 1478 _rangeCheck(this.length, start, length); |
1452 List<int> result = _new(length); | 1479 List<int> result = _new(length); |
1453 result.setRange(0, length, this, start); | 1480 result.setRange(0, length, this, start); |
1454 return result; | 1481 return result; |
1455 } | 1482 } |
1456 | 1483 |
1457 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | 1484 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
1458 if (from is _Uint64Array) { | 1485 if (from is _Uint64Array) { |
1459 int startInBytes = start * _BYTES_PER_ELEMENT; | 1486 _setRange(start * _BYTES_PER_ELEMENT, |
1460 int lengthInBytes = length * _BYTES_PER_ELEMENT; | 1487 length * _BYTES_PER_ELEMENT, |
1461 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; | 1488 from, |
1462 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); | 1489 startFrom * _BYTES_PER_ELEMENT); |
1463 } else { | 1490 } else { |
1464 Arrays.copy(from, startFrom, this, start, length); | 1491 Arrays.copy(from, startFrom, this, start, length); |
1465 } | 1492 } |
1466 } | 1493 } |
1467 | 1494 |
1468 String toString() { | 1495 String toString() { |
1469 return Collections.collectionToString(this); | 1496 return Collections.collectionToString(this); |
1470 } | 1497 } |
1471 | 1498 |
1472 int bytesPerElement() { | 1499 int bytesPerElement() { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1504 | 1531 |
1505 void operator[]=(int index, double value) { | 1532 void operator[]=(int index, double value) { |
1506 _setIndexed(index, value); | 1533 _setIndexed(index, value); |
1507 } | 1534 } |
1508 | 1535 |
1509 Iterator<double> iterator() { | 1536 Iterator<double> iterator() { |
1510 return new _ByteArrayIterator<double>(this); | 1537 return new _ByteArrayIterator<double>(this); |
1511 } | 1538 } |
1512 | 1539 |
1513 List<double> getRange(int start, int length) { | 1540 List<double> getRange(int start, int length) { |
1514 _rangeCheck(this, start, length); | 1541 _rangeCheck(this.length, start, length); |
1515 List<double> result = _new(length); | 1542 List<double> result = _new(length); |
1516 result.setRange(0, length, this, start); | 1543 result.setRange(0, length, this, start); |
1517 return result; | 1544 return result; |
1518 } | 1545 } |
1519 | 1546 |
1520 void setRange(int start, int length, List<double> from, [int startFrom = 0]) { | 1547 void setRange(int start, int length, List<double> from, [int startFrom = 0]) { |
1521 if (from is _Float32Array) { | 1548 if (from is _Float32Array) { |
1522 int startInBytes = start * _BYTES_PER_ELEMENT; | 1549 _setRange(start * _BYTES_PER_ELEMENT, |
1523 int lengthInBytes = length * _BYTES_PER_ELEMENT; | 1550 length * _BYTES_PER_ELEMENT, |
1524 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; | 1551 from, |
1525 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); | 1552 startFrom * _BYTES_PER_ELEMENT); |
1526 } else { | 1553 } else { |
1527 Arrays.copy(from, startFrom, this, start, length); | 1554 Arrays.copy(from, startFrom, this, start, length); |
1528 } | 1555 } |
1529 } | 1556 } |
1530 | 1557 |
1531 String toString() { | 1558 String toString() { |
1532 return Collections.collectionToString(this); | 1559 return Collections.collectionToString(this); |
1533 } | 1560 } |
1534 | 1561 |
1535 int bytesPerElement() { | 1562 int bytesPerElement() { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1567 | 1594 |
1568 void operator[]=(int index, double value) { | 1595 void operator[]=(int index, double value) { |
1569 _setIndexed(index, value); | 1596 _setIndexed(index, value); |
1570 } | 1597 } |
1571 | 1598 |
1572 Iterator<double> iterator() { | 1599 Iterator<double> iterator() { |
1573 return new _ByteArrayIterator<double>(this); | 1600 return new _ByteArrayIterator<double>(this); |
1574 } | 1601 } |
1575 | 1602 |
1576 List<double> getRange(int start, int length) { | 1603 List<double> getRange(int start, int length) { |
1577 _rangeCheck(this, start, length); | 1604 _rangeCheck(this.length, start, length); |
1578 List<double> result = _new(length); | 1605 List<double> result = _new(length); |
1579 result.setRange(0, length, this, start); | 1606 result.setRange(0, length, this, start); |
1580 return result; | 1607 return result; |
1581 } | 1608 } |
1582 | 1609 |
1583 void setRange(int start, int length, List<double> from, [int startFrom = 0]) { | 1610 void setRange(int start, int length, List<double> from, [int startFrom = 0]) { |
1584 if (from is _Float64Array) { | 1611 if (from is _Float64Array) { |
1585 int startInBytes = start * _BYTES_PER_ELEMENT; | 1612 _setRange(start * _BYTES_PER_ELEMENT, |
1586 int lengthInBytes = length * _BYTES_PER_ELEMENT; | 1613 length * _BYTES_PER_ELEMENT, |
1587 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; | 1614 from, |
1588 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); | 1615 startFrom * _BYTES_PER_ELEMENT); |
1589 } else { | 1616 } else { |
1590 Arrays.copy(from, startFrom, this, start, length); | 1617 Arrays.copy(from, startFrom, this, start, length); |
1591 } | 1618 } |
1592 } | 1619 } |
1593 | 1620 |
1594 String toString() { | 1621 String toString() { |
1595 return Collections.collectionToString(this); | 1622 return Collections.collectionToString(this); |
1596 } | 1623 } |
1597 | 1624 |
1598 int bytesPerElement() { | 1625 int bytesPerElement() { |
(...skipping 11 matching lines...) Expand all Loading... | |
1610 double _getIndexed(int index) native "Float64Array_getIndexed"; | 1637 double _getIndexed(int index) native "Float64Array_getIndexed"; |
1611 void _setIndexed(int index, double value) native "Float64Array_setIndexed"; | 1638 void _setIndexed(int index, double value) native "Float64Array_setIndexed"; |
1612 } | 1639 } |
1613 | 1640 |
1614 | 1641 |
1615 class _ExternalInt8Array extends _ByteArrayBase implements Int8List { | 1642 class _ExternalInt8Array extends _ByteArrayBase implements Int8List { |
1616 int operator[](int index) { | 1643 int operator[](int index) { |
1617 return _getIndexed(index); | 1644 return _getIndexed(index); |
1618 } | 1645 } |
1619 | 1646 |
1620 int operator[]=(int index, int value) { | 1647 void operator[]=(int index, int value) { |
1621 _setIndexed(index, _toInt8(value)); | 1648 _setIndexed(index, _toInt8(value)); |
1622 } | 1649 } |
1623 | 1650 |
1624 Iterator<int> iterator() { | 1651 Iterator<int> iterator() { |
1625 return new _ByteArrayIterator<int>(this); | 1652 return new _ByteArrayIterator<int>(this); |
1626 } | 1653 } |
1627 | 1654 |
1628 List<int> getRange(int start, int length) { | 1655 List<int> getRange(int start, int length) { |
1629 _rangeCheck(this, start, length); | 1656 _rangeCheck(this.length, start, length); |
1630 List<int> result = new Int8List(length); | 1657 List<int> result = new Int8List(length); |
1631 result.setRange(0, length, this, start); | 1658 result.setRange(0, length, this, start); |
1632 return result; | 1659 return result; |
1633 } | 1660 } |
1634 | 1661 |
1635 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | 1662 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
1636 if (from is _ExternalInt8Array) { | 1663 if (from is _ExternalInt8Array) { |
1637 int startInBytes = start * _BYTES_PER_ELEMENT; | 1664 _setRange(start * _BYTES_PER_ELEMENT, |
1638 int lengthInBytes = length * _BYTES_PER_ELEMENT; | 1665 length * _BYTES_PER_ELEMENT, |
1639 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; | 1666 from, |
1640 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); | 1667 startFrom * _BYTES_PER_ELEMENT); |
1641 } else { | 1668 } else { |
1642 Arrays.copy(from, startFrom, this, start, length); | 1669 Arrays.copy(from, startFrom, this, start, length); |
1643 } | 1670 } |
1644 } | 1671 } |
1645 | 1672 |
1646 String toString() { | 1673 String toString() { |
1647 return Collections.collectionToString(this); | 1674 return Collections.collectionToString(this); |
1648 } | 1675 } |
1649 | 1676 |
1650 int bytesPerElement() { | 1677 int bytesPerElement() { |
1651 return _BYTES_PER_ELEMENT; | 1678 return _BYTES_PER_ELEMENT; |
1652 } | 1679 } |
1653 | 1680 |
1654 int lengthInBytes() { | 1681 int lengthInBytes() { |
1655 return _length() * _BYTES_PER_ELEMENT; | 1682 return _length() * _BYTES_PER_ELEMENT; |
1656 } | 1683 } |
1657 | 1684 |
1658 static final int _BYTES_PER_ELEMENT = 1; | 1685 static final int _BYTES_PER_ELEMENT = 1; |
1659 | 1686 |
1660 int _getIndexed(int index) native "ExternalInt8Array_getIndexed"; | 1687 int _getIndexed(int index) native "ExternalInt8Array_getIndexed"; |
1661 void _setIndexed(int index, int value) native "ExternalInt8Array_setIndexed"; | 1688 void _setIndexed(int index, int value) native "ExternalInt8Array_setIndexed"; |
1662 } | 1689 } |
1663 | 1690 |
1664 | 1691 |
1665 class _ExternalUint8Array extends _ByteArrayBase implements Uint8List { | 1692 class _ExternalUint8Array extends _ByteArrayBase implements Uint8List { |
1666 int operator[](int index) { | 1693 int operator[](int index) { |
1667 return _getIndexed(index); | 1694 return _getIndexed(index); |
1668 } | 1695 } |
1669 | 1696 |
1670 int operator[]=(int index, int value) { | 1697 void operator[]=(int index, int value) { |
1671 _setIndexed(index, _toUint8(value)); | 1698 _setIndexed(index, _toUint8(value)); |
1672 } | 1699 } |
1673 | 1700 |
1674 Iterator<int> iterator() { | 1701 Iterator<int> iterator() { |
1675 return new _ByteArrayIterator<int>(this); | 1702 return new _ByteArrayIterator<int>(this); |
1676 } | 1703 } |
1677 | 1704 |
1678 List<int> getRange(int start, int length) { | 1705 List<int> getRange(int start, int length) { |
1679 _rangeCheck(this, start, length); | 1706 _rangeCheck(this.length, start, length); |
1680 List<int> result = new Uint8List(length); | 1707 List<int> result = new Uint8List(length); |
1681 result.setRange(0, length, this, start); | 1708 result.setRange(0, length, this, start); |
1682 return result; | 1709 return result; |
1683 } | 1710 } |
1684 | 1711 |
1685 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | 1712 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
1686 if (from is _ExternalUint8Array) { | 1713 if (from is _ExternalUint8Array) { |
1687 int startInBytes = start * _BYTES_PER_ELEMENT; | 1714 _setRange(start * _BYTES_PER_ELEMENT, |
1688 int lengthInBytes = length * _BYTES_PER_ELEMENT; | 1715 length * _BYTES_PER_ELEMENT, |
1689 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; | 1716 from, |
1690 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); | 1717 startFrom * _BYTES_PER_ELEMENT); |
1691 } else { | 1718 } else { |
1692 Arrays.copy(from, startFrom, this, start, length); | 1719 Arrays.copy(from, startFrom, this, start, length); |
1693 } | 1720 } |
1694 } | 1721 } |
1695 | 1722 |
1696 String toString() { | 1723 String toString() { |
1697 return Collections.collectionToString(this); | 1724 return Collections.collectionToString(this); |
1698 } | 1725 } |
1699 | 1726 |
1700 int bytesPerElement() { | 1727 int bytesPerElement() { |
1701 return _BYTES_PER_ELEMENT; | 1728 return _BYTES_PER_ELEMENT; |
1702 } | 1729 } |
1703 | 1730 |
1704 int lengthInBytes() { | 1731 int lengthInBytes() { |
1705 return _length() * _BYTES_PER_ELEMENT; | 1732 return _length() * _BYTES_PER_ELEMENT; |
1706 } | 1733 } |
1707 | 1734 |
1708 static final int _BYTES_PER_ELEMENT = 1; | 1735 static final int _BYTES_PER_ELEMENT = 1; |
1709 | 1736 |
1710 int _getIndexed(int index) native "ExternalUint8Array_getIndexed"; | 1737 int _getIndexed(int index) native "ExternalUint8Array_getIndexed"; |
1711 void _setIndexed(int index, int value) native "ExternalUint8Array_setIndexed"; | 1738 void _setIndexed(int index, int value) native "ExternalUint8Array_setIndexed"; |
1712 } | 1739 } |
1713 | 1740 |
1714 | 1741 |
1715 class _ExternalInt16Array extends _ByteArrayBase implements Int16List { | 1742 class _ExternalInt16Array extends _ByteArrayBase implements Int16List { |
1716 int operator[](int index) { | 1743 int operator[](int index) { |
1717 return _getIndexed(index); | 1744 return _getIndexed(index); |
1718 } | 1745 } |
1719 | 1746 |
1720 int operator[]=(int index, int value) { | 1747 void operator[]=(int index, int value) { |
1721 _setIndexed(index, _toInt16(value)); | 1748 _setIndexed(index, _toInt16(value)); |
1722 } | 1749 } |
1723 | 1750 |
1724 Iterator<int> iterator() { | 1751 Iterator<int> iterator() { |
1725 return new _ByteArrayIterator<int>(this); | 1752 return new _ByteArrayIterator<int>(this); |
1726 } | 1753 } |
1727 | 1754 |
1728 List<int> getRange(int start, int length) { | 1755 List<int> getRange(int start, int length) { |
1729 _rangeCheck(this, start, length); | 1756 _rangeCheck(this.length, start, length); |
1730 List<int> result = new Int16List(length); | 1757 List<int> result = new Int16List(length); |
1731 result.setRange(0, length, this, start); | 1758 result.setRange(0, length, this, start); |
1732 return result; | 1759 return result; |
1733 } | 1760 } |
1734 | 1761 |
1735 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | 1762 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
1736 if (from is _ExternalInt16Array) { | 1763 if (from is _ExternalInt16Array) { |
1737 int startInBytes = start * _BYTES_PER_ELEMENT; | 1764 _setRange(start * _BYTES_PER_ELEMENT, |
1738 int lengthInBytes = length * _BYTES_PER_ELEMENT; | 1765 length * _BYTES_PER_ELEMENT, |
1739 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; | 1766 from, |
1740 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); | 1767 startFrom * _BYTES_PER_ELEMENT); |
1741 } else { | 1768 } else { |
1742 Arrays.copy(from, startFrom, this, start, length); | 1769 Arrays.copy(from, startFrom, this, start, length); |
1743 } | 1770 } |
1744 } | 1771 } |
1745 | 1772 |
1746 String toString() { | 1773 String toString() { |
1747 return Collections.collectionToString(this); | 1774 return Collections.collectionToString(this); |
1748 } | 1775 } |
1749 | 1776 |
1750 int bytesPerElement() { | 1777 int bytesPerElement() { |
1751 return _BYTES_PER_ELEMENT; | 1778 return _BYTES_PER_ELEMENT; |
1752 } | 1779 } |
1753 | 1780 |
1754 int lengthInBytes() { | 1781 int lengthInBytes() { |
1755 return _length() * _BYTES_PER_ELEMENT; | 1782 return _length() * _BYTES_PER_ELEMENT; |
1756 } | 1783 } |
1757 | 1784 |
1758 static final int _BYTES_PER_ELEMENT = 2; | 1785 static final int _BYTES_PER_ELEMENT = 2; |
1759 | 1786 |
1760 int _getIndexed(int index) native "ExternalInt16Array_getIndexed"; | 1787 int _getIndexed(int index) native "ExternalInt16Array_getIndexed"; |
1761 void _setIndexed(int index, int value) native "ExternalInt16Array_setIndexed"; | 1788 void _setIndexed(int index, int value) native "ExternalInt16Array_setIndexed"; |
1762 } | 1789 } |
1763 | 1790 |
1764 | 1791 |
1765 class _ExternalUint16Array extends _ByteArrayBase implements Uint16List { | 1792 class _ExternalUint16Array extends _ByteArrayBase implements Uint16List { |
1766 int operator[](int index) { | 1793 int operator[](int index) { |
1767 return _getIndexed(index); | 1794 return _getIndexed(index); |
1768 } | 1795 } |
1769 | 1796 |
1770 int operator[]=(int index, int value) { | 1797 void operator[]=(int index, int value) { |
1771 _setIndexed(index, _toUint16(value)); | 1798 _setIndexed(index, _toUint16(value)); |
1772 } | 1799 } |
1773 | 1800 |
1774 Iterator<int> iterator() { | 1801 Iterator<int> iterator() { |
1775 return new _ByteArrayIterator<int>(this); | 1802 return new _ByteArrayIterator<int>(this); |
1776 } | 1803 } |
1777 | 1804 |
1778 List<int> getRange(int start, int length) { | 1805 List<int> getRange(int start, int length) { |
1779 _rangeCheck(this, start, length); | 1806 _rangeCheck(this.length, start, length); |
1780 List<int> result = new Uint16List(length); | 1807 List<int> result = new Uint16List(length); |
1781 result.setRange(0, length, this, start); | 1808 result.setRange(0, length, this, start); |
1782 return result; | 1809 return result; |
1783 } | 1810 } |
1784 | 1811 |
1785 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | 1812 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
1786 if (from is _ExternalUint16Array) { | 1813 if (from is _ExternalUint16Array) { |
1787 int startInBytes = start * _BYTES_PER_ELEMENT; | 1814 _setRange(start * _BYTES_PER_ELEMENT, |
1788 int lengthInBytes = length * _BYTES_PER_ELEMENT; | 1815 length * _BYTES_PER_ELEMENT, |
1789 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; | 1816 from, |
1790 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); | 1817 startFrom * _BYTES_PER_ELEMENT); |
1791 } else { | 1818 } else { |
1792 Arrays.copy(from, startFrom, this, start, length); | 1819 Arrays.copy(from, startFrom, this, start, length); |
1793 } | 1820 } |
1794 } | 1821 } |
1795 | 1822 |
1796 String toString() { | 1823 String toString() { |
1797 return Collections.collectionToString(this); | 1824 return Collections.collectionToString(this); |
1798 } | 1825 } |
1799 | 1826 |
1800 int bytesPerElement() { | 1827 int bytesPerElement() { |
(...skipping 11 matching lines...) Expand all Loading... | |
1812 void _setIndexed(int index, int value) | 1839 void _setIndexed(int index, int value) |
1813 native "ExternalUint16Array_setIndexed"; | 1840 native "ExternalUint16Array_setIndexed"; |
1814 } | 1841 } |
1815 | 1842 |
1816 | 1843 |
1817 class _ExternalInt32Array extends _ByteArrayBase implements Int32List { | 1844 class _ExternalInt32Array extends _ByteArrayBase implements Int32List { |
1818 int operator[](int index) { | 1845 int operator[](int index) { |
1819 return _getIndexed(index); | 1846 return _getIndexed(index); |
1820 } | 1847 } |
1821 | 1848 |
1822 int operator[]=(int index, int value) { | 1849 void operator[]=(int index, int value) { |
1823 _setIndexed(index, _toInt32(value)); | 1850 _setIndexed(index, _toInt32(value)); |
1824 } | 1851 } |
1825 | 1852 |
1826 Iterator<int> iterator() { | 1853 Iterator<int> iterator() { |
1827 return new _ByteArrayIterator<int>(this); | 1854 return new _ByteArrayIterator<int>(this); |
1828 } | 1855 } |
1829 | 1856 |
1830 List<int> getRange(int start, int length) { | 1857 List<int> getRange(int start, int length) { |
1831 _rangeCheck(this, start, length); | 1858 _rangeCheck(this.length, start, length); |
1832 List<int> result = new Int32List(length); | 1859 List<int> result = new Int32List(length); |
1833 result.setRange(0, length, this, start); | 1860 result.setRange(0, length, this, start); |
1834 return result; | 1861 return result; |
1835 } | 1862 } |
1836 | 1863 |
1837 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | 1864 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
1838 if (from is _ExternalInt32Array) { | 1865 if (from is _ExternalInt32Array) { |
1839 int startInBytes = start * _BYTES_PER_ELEMENT; | 1866 _setRange(start * _BYTES_PER_ELEMENT, |
1840 int lengthInBytes = length * _BYTES_PER_ELEMENT; | 1867 length * _BYTES_PER_ELEMENT, |
1841 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; | 1868 from, |
1842 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); | 1869 startFrom * _BYTES_PER_ELEMENT); |
1843 } else { | 1870 } else { |
1844 Arrays.copy(from, startFrom, this, start, length); | 1871 Arrays.copy(from, startFrom, this, start, length); |
1845 } | 1872 } |
1846 } | 1873 } |
1847 | 1874 |
1848 String toString() { | 1875 String toString() { |
1849 return Collections.collectionToString(this); | 1876 return Collections.collectionToString(this); |
1850 } | 1877 } |
1851 | 1878 |
1852 int bytesPerElement() { | 1879 int bytesPerElement() { |
(...skipping 11 matching lines...) Expand all Loading... | |
1864 void _setIndexed(int index, int value) | 1891 void _setIndexed(int index, int value) |
1865 native "ExternalInt32Array_setIndexed"; | 1892 native "ExternalInt32Array_setIndexed"; |
1866 } | 1893 } |
1867 | 1894 |
1868 | 1895 |
1869 class _ExternalUint32Array extends _ByteArrayBase implements Uint32List { | 1896 class _ExternalUint32Array extends _ByteArrayBase implements Uint32List { |
1870 int operator[](int index) { | 1897 int operator[](int index) { |
1871 return _getIndexed(index); | 1898 return _getIndexed(index); |
1872 } | 1899 } |
1873 | 1900 |
1874 int operator[]=(int index, int value) { | 1901 void operator[]=(int index, int value) { |
1875 _setIndexed(index, _toUint32(value)); | 1902 _setIndexed(index, _toUint32(value)); |
1876 } | 1903 } |
1877 | 1904 |
1878 Iterator<int> iterator() { | 1905 Iterator<int> iterator() { |
1879 return new _ByteArrayIterator<int>(this); | 1906 return new _ByteArrayIterator<int>(this); |
1880 } | 1907 } |
1881 | 1908 |
1882 List<int> getRange(int start, int length) { | 1909 List<int> getRange(int start, int length) { |
1883 _rangeCheck(this, start, length); | 1910 _rangeCheck(this.length, start, length); |
1884 List<int> result = new Uint32List(length); | 1911 List<int> result = new Uint32List(length); |
1885 result.setRange(0, length, this, start); | 1912 result.setRange(0, length, this, start); |
1886 return result; | 1913 return result; |
1887 } | 1914 } |
1888 | 1915 |
1889 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | 1916 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
1890 if (from is _ExternalUint32Array) { | 1917 if (from is _ExternalUint32Array) { |
1891 int startInBytes = start * _BYTES_PER_ELEMENT; | 1918 _setRange(start * _BYTES_PER_ELEMENT, |
1892 int lengthInBytes = length * _BYTES_PER_ELEMENT; | 1919 length * _BYTES_PER_ELEMENT, |
1893 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; | 1920 from, |
1894 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); | 1921 startFrom * _BYTES_PER_ELEMENT); |
1895 } else { | 1922 } else { |
1896 Arrays.copy(from, startFrom, this, start, length); | 1923 Arrays.copy(from, startFrom, this, start, length); |
1897 } | 1924 } |
1898 } | 1925 } |
1899 | 1926 |
1900 String toString() { | 1927 String toString() { |
1901 return Collections.collectionToString(this); | 1928 return Collections.collectionToString(this); |
1902 } | 1929 } |
1903 | 1930 |
1904 int bytesPerElement() { | 1931 int bytesPerElement() { |
(...skipping 11 matching lines...) Expand all Loading... | |
1916 void _setIndexed(int index, int value) | 1943 void _setIndexed(int index, int value) |
1917 native "ExternalUint32Array_setIndexed"; | 1944 native "ExternalUint32Array_setIndexed"; |
1918 } | 1945 } |
1919 | 1946 |
1920 | 1947 |
1921 class _ExternalInt64Array extends _ByteArrayBase implements Int64List { | 1948 class _ExternalInt64Array extends _ByteArrayBase implements Int64List { |
1922 int operator[](int index) { | 1949 int operator[](int index) { |
1923 return _getIndexed(index); | 1950 return _getIndexed(index); |
1924 } | 1951 } |
1925 | 1952 |
1926 int operator[]=(int index, int value) { | 1953 void operator[]=(int index, int value) { |
1927 _setIndexed(index, _toInt64(value)); | 1954 _setIndexed(index, _toInt64(value)); |
1928 } | 1955 } |
1929 | 1956 |
1930 Iterator<int> iterator() { | 1957 Iterator<int> iterator() { |
1931 return new _ByteArrayIterator<int>(this); | 1958 return new _ByteArrayIterator<int>(this); |
1932 } | 1959 } |
1933 | 1960 |
1934 List<int> getRange(int start, int length) { | 1961 List<int> getRange(int start, int length) { |
1935 _rangeCheck(this, start, length); | 1962 _rangeCheck(this.length, start, length); |
1936 List<int> result = new Int64List(length); | 1963 List<int> result = new Int64List(length); |
1937 result.setRange(0, length, this, start); | 1964 result.setRange(0, length, this, start); |
1938 return result; | 1965 return result; |
1939 } | 1966 } |
1940 | 1967 |
1941 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | 1968 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
1942 if (from is _ExternalInt64Array) { | 1969 if (from is _ExternalInt64Array) { |
1943 int startInBytes = start * _BYTES_PER_ELEMENT; | 1970 _setRange(start * _BYTES_PER_ELEMENT, |
1944 int lengthInBytes = length * _BYTES_PER_ELEMENT; | 1971 length * _BYTES_PER_ELEMENT, |
1945 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; | 1972 from, |
1946 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); | 1973 startFrom * _BYTES_PER_ELEMENT); |
1947 } else { | 1974 } else { |
1948 Arrays.copy(from, startFrom, this, start, length); | 1975 Arrays.copy(from, startFrom, this, start, length); |
1949 } | 1976 } |
1950 } | 1977 } |
1951 | 1978 |
1952 String toString() { | 1979 String toString() { |
1953 return Collections.collectionToString(this); | 1980 return Collections.collectionToString(this); |
1954 } | 1981 } |
1955 | 1982 |
1956 int bytesPerElement() { | 1983 int bytesPerElement() { |
(...skipping 11 matching lines...) Expand all Loading... | |
1968 void _setIndexed(int index, int value) | 1995 void _setIndexed(int index, int value) |
1969 native "ExternalInt64Array_setIndexed"; | 1996 native "ExternalInt64Array_setIndexed"; |
1970 } | 1997 } |
1971 | 1998 |
1972 | 1999 |
1973 class _ExternalUint64Array extends _ByteArrayBase implements Uint64List { | 2000 class _ExternalUint64Array extends _ByteArrayBase implements Uint64List { |
1974 int operator[](int index) { | 2001 int operator[](int index) { |
1975 return _getIndexed(index); | 2002 return _getIndexed(index); |
1976 } | 2003 } |
1977 | 2004 |
1978 int operator[]=(int index, int value) { | 2005 void operator[]=(int index, int value) { |
1979 _setIndexed(index, _toUint64(value)); | 2006 _setIndexed(index, _toUint64(value)); |
1980 } | 2007 } |
1981 | 2008 |
1982 Iterator<int> iterator() { | 2009 Iterator<int> iterator() { |
1983 return new _ByteArrayIterator<int>(this); | 2010 return new _ByteArrayIterator<int>(this); |
1984 } | 2011 } |
1985 | 2012 |
1986 List<int> getRange(int start, int length) { | 2013 List<int> getRange(int start, int length) { |
1987 _rangeCheck(this, start, length); | 2014 _rangeCheck(this.length, start, length); |
1988 List<int> result = new Uint64List(length); | 2015 List<int> result = new Uint64List(length); |
1989 result.setRange(0, length, this, start); | 2016 result.setRange(0, length, this, start); |
1990 return result; | 2017 return result; |
1991 } | 2018 } |
1992 | 2019 |
1993 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | 2020 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
1994 if (from is _ExternalUint64Array) { | 2021 if (from is _ExternalUint64Array) { |
1995 int startInBytes = start * _BYTES_PER_ELEMENT; | 2022 _setRange(start * _BYTES_PER_ELEMENT, |
1996 int lengthInBytes = length * _BYTES_PER_ELEMENT; | 2023 length * _BYTES_PER_ELEMENT, |
1997 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; | 2024 from, |
1998 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); | 2025 startFrom * _BYTES_PER_ELEMENT); |
1999 } else { | 2026 } else { |
2000 Arrays.copy(from, startFrom, this, start, length); | 2027 Arrays.copy(from, startFrom, this, start, length); |
2001 } | 2028 } |
2002 } | 2029 } |
2003 | 2030 |
2004 String toString() { | 2031 String toString() { |
2005 return Collections.collectionToString(this); | 2032 return Collections.collectionToString(this); |
2006 } | 2033 } |
2007 | 2034 |
2008 int bytesPerElement() { | 2035 int bytesPerElement() { |
2009 return _BYTES_PER_ELEMENT; | 2036 return _BYTES_PER_ELEMENT; |
2010 } | 2037 } |
2011 | 2038 |
2012 int lengthInBytes() { | 2039 int lengthInBytes() { |
2013 return _length() * _BYTES_PER_ELEMENT; | 2040 return _length() * _BYTES_PER_ELEMENT; |
2014 } | 2041 } |
2015 | 2042 |
2016 static final int _BYTES_PER_ELEMENT = 8; | 2043 static final int _BYTES_PER_ELEMENT = 8; |
2017 | 2044 |
2018 int _getIndexed(int index) | 2045 int _getIndexed(int index) |
2019 native "ExternalUint64Array_getIndexed"; | 2046 native "ExternalUint64Array_getIndexed"; |
2020 void _setIndexed(int index, int value) | 2047 void _setIndexed(int index, int value) |
2021 native "ExternalUint64Array_setIndexed"; | 2048 native "ExternalUint64Array_setIndexed"; |
2022 } | 2049 } |
2023 | 2050 |
2024 | 2051 |
2025 class _ExternalFloat32Array extends _ByteArrayBase implements Float32List { | 2052 class _ExternalFloat32Array extends _ByteArrayBase implements Float32List { |
2026 int operator[](int index) { | 2053 double operator[](int index) { |
2027 return _getIndexed(index); | 2054 return _getIndexed(index); |
2028 } | 2055 } |
2029 | 2056 |
2030 int operator[]=(int index, double value) { | 2057 void operator[]=(int index, double value) { |
2031 _setIndexed(index, value); | 2058 _setIndexed(index, value); |
2032 } | 2059 } |
2033 | 2060 |
2034 Iterator<double> iterator() { | 2061 Iterator<double> iterator() { |
2035 return new _ByteArrayIterator<double>(this); | 2062 return new _ByteArrayIterator<double>(this); |
2036 } | 2063 } |
2037 | 2064 |
2038 List<double> getRange(int start, int length) { | 2065 List<double> getRange(int start, int length) { |
2039 _rangeCheck(this, start, length); | 2066 _rangeCheck(this.length, start, length); |
2040 List<double> result = new Float32List(length); | 2067 List<double> result = new Float32List(length); |
2041 result.setRange(0, length, this, start); | 2068 result.setRange(0, length, this, start); |
2042 return result; | 2069 return result; |
2043 } | 2070 } |
2044 | 2071 |
2045 void setRange(int start, int length, List<double> from, [int startFrom = 0]) { | 2072 void setRange(int start, int length, List<double> from, [int startFrom = 0]) { |
2046 if (from is _ExternalFloat32Array) { | 2073 if (from is _ExternalFloat32Array) { |
2047 int startInBytes = start * _BYTES_PER_ELEMENT; | 2074 _setRange(start * _BYTES_PER_ELEMENT, |
2048 int lengthInBytes = length * _BYTES_PER_ELEMENT; | 2075 length * _BYTES_PER_ELEMENT, |
2049 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; | 2076 from, |
2050 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); | 2077 startFrom * _BYTES_PER_ELEMENT); |
2051 } else { | 2078 } else { |
2052 Arrays.copy(from, startFrom, this, start, length); | 2079 Arrays.copy(from, startFrom, this, start, length); |
2053 } | 2080 } |
2054 } | 2081 } |
2055 | 2082 |
2056 String toString() { | 2083 String toString() { |
2057 return Collections.collectionToString(this); | 2084 return Collections.collectionToString(this); |
2058 } | 2085 } |
2059 | 2086 |
2060 int bytesPerElement() { | 2087 int bytesPerElement() { |
2061 return _BYTES_PER_ELEMENT; | 2088 return _BYTES_PER_ELEMENT; |
2062 } | 2089 } |
2063 | 2090 |
2064 int lengthInBytes() { | 2091 int lengthInBytes() { |
2065 return _length() * _BYTES_PER_ELEMENT; | 2092 return _length() * _BYTES_PER_ELEMENT; |
2066 } | 2093 } |
2067 | 2094 |
2068 static final int _BYTES_PER_ELEMENT = 4; | 2095 static final int _BYTES_PER_ELEMENT = 4; |
2069 | 2096 |
2070 double _getIndexed(int index) | 2097 double _getIndexed(int index) |
2071 native "ExternalFloat32Array_getIndexed"; | 2098 native "ExternalFloat32Array_getIndexed"; |
2072 void _setIndexed(int index, double value) | 2099 void _setIndexed(int index, double value) |
2073 native "ExternalFloat32Array_setIndexed"; | 2100 native "ExternalFloat32Array_setIndexed"; |
2074 } | 2101 } |
2075 | 2102 |
2076 | 2103 |
2077 class _ExternalFloat64Array extends _ByteArrayBase implements Float64List { | 2104 class _ExternalFloat64Array extends _ByteArrayBase implements Float64List { |
2078 int operator[](int index) { | 2105 double operator[](int index) { |
2079 return _getIndexed(index); | 2106 return _getIndexed(index); |
2080 } | 2107 } |
2081 | 2108 |
2082 int operator[]=(int index, double value) { | 2109 void operator[]=(int index, double value) { |
2083 _setIndexed(index, value); | 2110 _setIndexed(index, value); |
2084 } | 2111 } |
2085 | 2112 |
2086 Iterator<double> iterator() { | 2113 Iterator<double> iterator() { |
2087 return new _ByteArrayIterator<double>(this); | 2114 return new _ByteArrayIterator<double>(this); |
2088 } | 2115 } |
2089 | 2116 |
2090 List<double> getRange(int start, int length) { | 2117 List<double> getRange(int start, int length) { |
2091 _rangeCheck(this, start, length); | 2118 _rangeCheck(this.length, start, length); |
2092 List<double> result = new Float64List(length); | 2119 List<double> result = new Float64List(length); |
2093 result.setRange(0, length, this, start); | 2120 result.setRange(0, length, this, start); |
2094 return result; | 2121 return result; |
2095 } | 2122 } |
2096 | 2123 |
2097 void setRange(int start, int length, List<double> from, [int startFrom = 0]) { | 2124 void setRange(int start, int length, List<double> from, [int startFrom = 0]) { |
2098 if (from is _ExternalFloat64Array) { | 2125 if (from is _ExternalFloat64Array) { |
2099 int startInBytes = start * _BYTES_PER_ELEMENT; | 2126 _setRange(start * _BYTES_PER_ELEMENT, |
2100 int lengthInBytes = length * _BYTES_PER_ELEMENT; | 2127 length * _BYTES_PER_ELEMENT, |
2101 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; | 2128 from, |
2102 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); | 2129 startFrom * _BYTES_PER_ELEMENT); |
2103 } else { | 2130 } else { |
2104 Arrays.copy(from, startFrom, this, start, length); | 2131 Arrays.copy(from, startFrom, this, start, length); |
2105 } | 2132 } |
2106 } | 2133 } |
2107 | 2134 |
2108 String toString() { | 2135 String toString() { |
2109 return Collections.collectionToString(this); | 2136 return Collections.collectionToString(this); |
2110 } | 2137 } |
2111 | 2138 |
2112 int bytesPerElement() { | 2139 int bytesPerElement() { |
2113 return _BYTES_PER_ELEMENT; | 2140 return _BYTES_PER_ELEMENT; |
2114 } | 2141 } |
2115 | 2142 |
2116 int lengthInBytes() { | 2143 int lengthInBytes() { |
2117 return _length() * _BYTES_PER_ELEMENT; | 2144 return _length() * _BYTES_PER_ELEMENT; |
2118 } | 2145 } |
2119 | 2146 |
2120 static final int _BYTES_PER_ELEMENT = 8; | 2147 static final int _BYTES_PER_ELEMENT = 8; |
2121 | 2148 |
2122 double _getIndexed(int index) | 2149 double _getIndexed(int index) |
2123 native "ExternalFloat64Array_getIndexed"; | 2150 native "ExternalFloat64Array_getIndexed"; |
2124 void _setIndexed(int index, double value) | 2151 void _setIndexed(int index, double value) |
2125 native "ExternalFloat64Array_setIndexed"; | 2152 native "ExternalFloat64Array_setIndexed"; |
2126 } | 2153 } |
2127 | 2154 |
2128 | 2155 |
2129 class _ByteArrayIterator<E> implements Iterator<E> { | 2156 class _ByteArrayIterator<E> implements Iterator<E> { |
2130 _ByteArrayIterator(_ByteArrayBase array) | 2157 _ByteArrayIterator(List array) |
2131 : _array = array, _length = array.length, _pos = 0; | 2158 : _array = array, _length = array.length, _pos = 0 { |
2159 assert(array is _ByteArrayBase || array is _ByteArrayViewBase); | |
2160 } | |
2132 | 2161 |
2133 bool hasNext() { | 2162 bool hasNext() { |
2134 return _length > _pos; | 2163 return _length > _pos; |
2135 } | 2164 } |
2136 | 2165 |
2137 E next() { | 2166 E next() { |
2138 if (!hasNext()) { | 2167 if (!hasNext()) { |
2139 throw const NoMoreElementsException(); | 2168 throw const NoMoreElementsException(); |
2140 } | 2169 } |
2141 return _array[_pos++]; | 2170 return _array[_pos++]; |
2142 } | 2171 } |
2143 | 2172 |
2144 final List<E> _array; | 2173 final List<E> _array; |
2145 | |
2146 final int _length; | 2174 final int _length; |
2147 | |
2148 int _pos; | 2175 int _pos; |
2149 } | 2176 } |
2150 | 2177 |
2151 | 2178 |
2152 class _ByteArrayView implements ByteArray { | 2179 class _ByteArrayView implements ByteArray { |
2153 _ByteArrayView(this._array, this._offset, this._length) { | 2180 _ByteArrayView(this._array, this._offset, this._length) { |
2181 _rangeCheck(_array.lengthInBytes(), _offset, _length); | |
2154 } | 2182 } |
2155 | 2183 |
2156 int lengthInBytes() { | 2184 int lengthInBytes() { |
2157 return _length; | 2185 return _length; |
2158 } | 2186 } |
2159 | 2187 |
2160 ByteArray subByteArray([int start = 0, int length]) { | 2188 ByteArray subByteArray([int start = 0, int length]) { |
2161 if (length === null) { | 2189 if (length === null) { |
2162 length = this.lengthInBytes(); | 2190 length = this.lengthInBytes(); |
2163 } | 2191 } |
2164 _rangeCheck(start, length); | |
2165 return new _ByteArrayView(_array, _offset + start, length); | 2192 return new _ByteArrayView(_array, _offset + start, length); |
2166 } | 2193 } |
2167 | 2194 |
2168 int getInt8(int byteOffset) { | 2195 int getInt8(int byteOffset) { |
2169 return _array._getInt8(_offset + byteOffset); | 2196 return _array._getInt8(_offset + byteOffset); |
2170 } | 2197 } |
2171 void setInt8(int byteOffset, int value) { | 2198 int setInt8(int byteOffset, int value) { |
siva
2012/06/21 23:33:08
Why do these set methods not return void like the
cshapiro
2012/06/22 04:27:00
Another good question! This is actually documente
siva
2012/06/22 18:12:30
dst.setInt8(pos, x); is equivalent to dst[pos] = x
| |
2172 _array._setInt8(_offset + byteOffset, value); | 2199 return _array._setInt8(_offset + byteOffset, value); |
2173 } | 2200 } |
2174 | 2201 |
2175 int getUint8(int byteOffset) { | 2202 int getUint8(int byteOffset) { |
2176 return _array._getUint8(_offset + byteOffset); | 2203 return _array._getUint8(_offset + byteOffset); |
2177 } | 2204 } |
2178 void setUint8(int byteOffset, int value) { | 2205 int setUint8(int byteOffset, int value) { |
2179 _array._setUint8(_offset + byteOffset, value); | 2206 return _array._setUint8(_offset + byteOffset, value); |
2180 } | 2207 } |
2181 | 2208 |
2182 int getInt16(int byteOffset) { | 2209 int getInt16(int byteOffset) { |
2183 return _array._getInt16(_offset + byteOffset); | 2210 return _array._getInt16(_offset + byteOffset); |
2184 } | 2211 } |
2185 void setInt16(int byteOffset, int value) { | 2212 int setInt16(int byteOffset, int value) { |
2186 _array._setInt16(_offset + byteOffset, value); | 2213 return _array._setInt16(_offset + byteOffset, value); |
2187 } | 2214 } |
2188 | 2215 |
2189 int getUint16(int byteOffset) { | 2216 int getUint16(int byteOffset) { |
2190 return _array._getUint16(_offset + byteOffset); | 2217 return _array._getUint16(_offset + byteOffset); |
2191 } | 2218 } |
2192 void setUint16(int byteOffset, int value) { | 2219 int setUint16(int byteOffset, int value) { |
2193 _array._setUint16(_offset + byteOffset, value); | 2220 return _array._setUint16(_offset + byteOffset, value); |
2194 } | 2221 } |
2195 | 2222 |
2196 int getInt32(int byteOffset) { | 2223 int getInt32(int byteOffset) { |
2197 return _array._getInt32(_offset + byteOffset); | 2224 return _array._getInt32(_offset + byteOffset); |
2198 } | 2225 } |
2199 void setInt32(int byteOffset, int value) { | 2226 int setInt32(int byteOffset, int value) { |
2200 _array._setInt32(_offset + byteOffset, value); | 2227 return _array._setInt32(_offset + byteOffset, value); |
2201 } | 2228 } |
2202 | 2229 |
2203 int getUint32(int byteOffset) { | 2230 int getUint32(int byteOffset) { |
2204 return _array._getUint32(_offset + byteOffset); | 2231 return _array._getUint32(_offset + byteOffset); |
2205 } | 2232 } |
2206 void setUint32(int byteOffset, int value) { | 2233 int setUint32(int byteOffset, int value) { |
2207 _array._setUint32(_offset + byteOffset, value); | 2234 return _array._setUint32(_offset + byteOffset, value); |
2208 } | 2235 } |
2209 | 2236 |
2210 int getInt64(int byteOffset) { | 2237 int getInt64(int byteOffset) { |
2211 return _array._getInt64(_offset + byteOffset); | 2238 return _array._getInt64(_offset + byteOffset); |
2212 } | 2239 } |
2213 void setInt64(int byteOffset, int value) { | 2240 int setInt64(int byteOffset, int value) { |
2214 _array._setInt64(_offset + byteOffset, value); | 2241 return _array._setInt64(_offset + byteOffset, value); |
2215 } | 2242 } |
2216 | 2243 |
2217 int getUint64(int byteOffset) { | 2244 int getUint64(int byteOffset) { |
2218 return _array._getUint64(_offset + byteOffset); | 2245 return _array._getUint64(_offset + byteOffset); |
2219 } | 2246 } |
2220 void setUint64(int byteOffset, int value) { | 2247 int setUint64(int byteOffset, int value) { |
2221 _array._setUint64(_offset + byteOffset, value); | 2248 return _array._setUint64(_offset + byteOffset, value); |
2222 } | 2249 } |
2223 | 2250 |
2224 double getFloat32(int byteOffset) { | 2251 double getFloat32(int byteOffset) { |
2225 return _array._getFloat32(_offset + byteOffset); | 2252 return _array._getFloat32(_offset + byteOffset); |
2226 } | 2253 } |
2227 void setFloat32(int byteOffset, double value) { | 2254 int setFloat32(int byteOffset, double value) { |
2228 _array._setFloat32(_offset + byteOffset, value); | 2255 return _array._setFloat32(_offset + byteOffset, value); |
2229 } | 2256 } |
2230 | 2257 |
2231 double getFloat64(int byteOffset) { | 2258 double getFloat64(int byteOffset) { |
2232 return _array._getFloat64(_offset + byteOffset); | 2259 return _array._getFloat64(_offset + byteOffset); |
2233 } | 2260 } |
2234 void setFloat64(int byteOffset, double value) { | 2261 int setFloat64(int byteOffset, double value) { |
2235 _array._setFloat64(_offset + byteOffset, value); | 2262 return _array._setFloat64(_offset + byteOffset, value); |
2236 } | 2263 } |
2237 | 2264 |
2238 final _ByteArrayBase _array; | 2265 final _ByteArrayBase _array; |
2239 final int _offset; | 2266 final int _offset; |
2240 final int _length; | 2267 final int _length; |
2241 } | 2268 } |
2242 | 2269 |
2243 | 2270 |
2244 class _ByteArrayViewBase { | 2271 class _ByteArrayViewBase { |
2272 abstract num operator[](int index); | |
2245 | 2273 |
2246 // Methods implementing the Collection interface. | 2274 // Methods implementing the Collection interface. |
2247 | 2275 |
2248 void forEach(void f(element)) { | 2276 void forEach(void f(element)) { |
2249 var len = this.length; | 2277 var len = this.length; |
2250 for (var i = 0; i < len; i++) { | 2278 for (var i = 0; i < len; i++) { |
2251 f(this[i]); | 2279 f(this[i]); |
2252 } | 2280 } |
2253 } | 2281 } |
2254 | 2282 |
(...skipping 12 matching lines...) Expand all Loading... | |
2267 } | 2295 } |
2268 | 2296 |
2269 bool some(bool f(element)) { | 2297 bool some(bool f(element)) { |
2270 return Collections.some(this, f);; | 2298 return Collections.some(this, f);; |
2271 } | 2299 } |
2272 | 2300 |
2273 bool isEmpty() { | 2301 bool isEmpty() { |
2274 return this.length === 0; | 2302 return this.length === 0; |
2275 } | 2303 } |
2276 | 2304 |
2277 int get length() { | 2305 abstract int get length(); |
2278 return _length(); | |
2279 } | |
2280 | 2306 |
2281 // Methods implementing the List interface. | 2307 // Methods implementing the List interface. |
2282 | 2308 |
2283 set length(newLength) { | 2309 set length(newLength) { |
2284 throw const UnsupportedOperationException( | 2310 throw const UnsupportedOperationException( |
2285 "Cannot resize a non-extendable array"); | 2311 "Cannot resize a non-extendable array"); |
2286 } | 2312 } |
2287 | 2313 |
2288 void add(value) { | 2314 void add(value) { |
2289 throw const UnsupportedOperationException( | 2315 throw const UnsupportedOperationException( |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2335 void insertRange(int start, int length, [initialValue]) { | 2361 void insertRange(int start, int length, [initialValue]) { |
2336 throw const UnsupportedOperationException( | 2362 throw const UnsupportedOperationException( |
2337 "Cannot add to a non-extendable array"); | 2363 "Cannot add to a non-extendable array"); |
2338 } | 2364 } |
2339 } | 2365 } |
2340 | 2366 |
2341 | 2367 |
2342 class _Int8ArrayView extends _ByteArrayViewBase implements Int8List { | 2368 class _Int8ArrayView extends _ByteArrayViewBase implements Int8List { |
2343 _Int8ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) | 2369 _Int8ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) |
2344 : _array = array, | 2370 : _array = array, |
2345 _offset = offsetInBytes, | 2371 _offset = _requireInteger(offsetInBytes), |
2346 _length = (length === null) ? (array.lengthInBytes() - offsetInBytes) | 2372 _length = _requireIntegerOrNull( |
2347 : length { | 2373 length, |
2374 ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT)) { | |
2348 if (offsetInBytes < 0 || offsetInBytes >= array.lengthInBytes()) { | 2375 if (offsetInBytes < 0 || offsetInBytes >= array.lengthInBytes()) { |
2349 throw new IndexOutOfRangeException(offsetInBytes); | 2376 throw new IndexOutOfRangeException(offsetInBytes); |
2350 } | 2377 } |
2351 int lengthInBytes = length * _BYTES_PER_ELEMENT; | 2378 int lengthInBytes = _length * _BYTES_PER_ELEMENT; |
2352 if (length < 0 || (lengthInBytes + _offset) > array.lengthInBytes()) { | 2379 if (_length < 0 || (lengthInBytes + _offset) > array.lengthInBytes()) { |
2353 throw new IndexOutOfRangeException(length); | 2380 throw new IndexOutOfRangeException(_length); |
2354 } | 2381 } |
2355 } | 2382 } |
2356 | 2383 |
2357 get length() { | 2384 get length() { |
2358 return _length; | 2385 return _length; |
2359 } | 2386 } |
2360 | 2387 |
2361 int operator[](int index) { | 2388 int operator[](int index) { |
2362 if (index < 0 || index >= _length) { | 2389 if (index < 0 || index >= _length) { |
2363 throw new IndexOutOfRangeException(index); | 2390 throw new IndexOutOfRangeException(index); |
2364 } | 2391 } |
2365 return _array.getInt8(_offset + (index * _BYTES_PER_ELEMENT)); | 2392 return _array.getInt8(_offset + (index * _BYTES_PER_ELEMENT)); |
2366 } | 2393 } |
2367 | 2394 |
2368 void operator[]=(int index, int value) { | 2395 void operator[]=(int index, int value) { |
2369 if (index < 0 || index >= _length) { | 2396 if (index < 0 || index >= _length) { |
2370 throw new IndexOutOfRangeException(index); | 2397 throw new IndexOutOfRangeException(index); |
2371 } | 2398 } |
2372 _array.setInt8(_offset + (index * _BYTES_PER_ELEMENT), _toInt8(value)); | 2399 _array.setInt8(_offset + (index * _BYTES_PER_ELEMENT), _toInt8(value)); |
2373 } | 2400 } |
2374 | 2401 |
2375 Iterator<int> iterator() { | 2402 Iterator<int> iterator() { |
2376 return new _ByteArrayIterator<int>(this); | 2403 return new _ByteArrayIterator<int>(this); |
2377 } | 2404 } |
2378 | 2405 |
2379 List<int> getRange(int start, int length) { | 2406 List<int> getRange(int start, int length) { |
2380 _rangeCheck(this, start, length); | 2407 _rangeCheck(this.length, start, length); |
2381 List<int> result = new Int8List(length); | 2408 List<int> result = new Int8List(length); |
2382 result.setRange(0, length, this, start); | 2409 result.setRange(0, length, this, start); |
2383 return result; | 2410 return result; |
2384 } | 2411 } |
2385 | 2412 |
2386 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | 2413 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
2387 Arrays.copy(from, startFrom, this, start, length); | 2414 Arrays.copy(from, startFrom, this, start, length); |
2388 } | 2415 } |
2389 | 2416 |
2390 String toString() { | 2417 String toString() { |
2391 return Collections.collectionToString(this); | 2418 return Collections.collectionToString(this); |
2392 } | 2419 } |
2393 | 2420 |
2394 int bytesPerElement() { | 2421 int bytesPerElement() { |
2395 return _BYTES_PER_ELEMENT; | 2422 return _BYTES_PER_ELEMENT; |
2396 } | 2423 } |
2397 | 2424 |
2398 int lengthInBytes() { | 2425 int lengthInBytes() { |
2399 return _length * _BYTES_PER_ELEMENT; | 2426 return _length * _BYTES_PER_ELEMENT; |
2400 } | 2427 } |
2401 | 2428 |
2402 ByteArray asByteArray([int start = 0, int length]) { | 2429 ByteArray asByteArray([int start = 0, int length]) { |
2403 if (length == null) { | 2430 if (length == null) { |
2404 length = this.lengthInBytes(); | 2431 length = this.lengthInBytes(); |
2405 } | 2432 } |
2406 _rangeCheck(start, length); | 2433 _rangeCheck(this.length, start, length); |
2407 return _array.subByteArray(_offset + start, length); | 2434 return _array.subByteArray(_offset + start, length); |
2408 } | 2435 } |
2409 | 2436 |
2410 static final int _BYTES_PER_ELEMENT = 1; | 2437 static final int _BYTES_PER_ELEMENT = 1; |
2411 final ByteArray _array; | 2438 final ByteArray _array; |
2412 final int _offset; | 2439 final int _offset; |
2413 final int _length; | 2440 final int _length; |
2414 } | 2441 } |
2415 | 2442 |
2416 | 2443 |
2417 class _Uint8ArrayView extends _ByteArrayViewBase implements Uint8List { | 2444 class _Uint8ArrayView extends _ByteArrayViewBase implements Uint8List { |
2418 _Uint8ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) | 2445 _Uint8ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) |
2419 : _array = array, | 2446 : _array = array, |
2420 _offset = offsetInBytes, | 2447 _offset = _requireInteger(offsetInBytes), |
2421 _length = (length === null) ? (array.lengthInBytes() - offsetInBytes) | 2448 _length = _requireIntegerOrNull( |
2422 : length { | 2449 length, |
2450 ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT)) { | |
2423 if (offsetInBytes < 0 || offsetInBytes >= array.lengthInBytes()) { | 2451 if (offsetInBytes < 0 || offsetInBytes >= array.lengthInBytes()) { |
2424 throw new IndexOutOfRangeException(offsetInBytes); | 2452 throw new IndexOutOfRangeException(offsetInBytes); |
2425 } | 2453 } |
2426 int lengthInBytes = length * _BYTES_PER_ELEMENT; | 2454 int lengthInBytes = _length * _BYTES_PER_ELEMENT; |
2427 if (length < 0 || (lengthInBytes + _offset) > array.lengthInBytes()) { | 2455 if (_length < 0 || (lengthInBytes + _offset) > array.lengthInBytes()) { |
2428 throw new IndexOutOfRangeException(length); | 2456 throw new IndexOutOfRangeException(_length); |
2429 } | 2457 } |
2430 } | 2458 } |
2431 | 2459 |
2432 get length() { | 2460 get length() { |
2433 return _length; | 2461 return _length; |
2434 } | 2462 } |
2435 | 2463 |
2436 int operator[](int index) { | 2464 int operator[](int index) { |
2437 if (index < 0 || index >= _length) { | 2465 if (index < 0 || index >= _length) { |
2438 throw new IndexOutOfRangeException(index); | 2466 throw new IndexOutOfRangeException(index); |
2439 } | 2467 } |
2440 return _array.getUint8(_offset + (index * _BYTES_PER_ELEMENT)); | 2468 return _array.getUint8(_offset + (index * _BYTES_PER_ELEMENT)); |
2441 } | 2469 } |
2442 | 2470 |
2443 void operator[]=(int index, int value) { | 2471 void operator[]=(int index, int value) { |
2444 if (index < 0 || index >= _length) { | 2472 if (index < 0 || index >= _length) { |
2445 throw new IndexOutOfRangeException(index); | 2473 throw new IndexOutOfRangeException(index); |
2446 } | 2474 } |
2447 _array.setUint8(_offset + (index * _BYTES_PER_ELEMENT), _toUint8(value)); | 2475 _array.setUint8(_offset + (index * _BYTES_PER_ELEMENT), _toUint8(value)); |
2448 } | 2476 } |
2449 | 2477 |
2450 Iterator<int> iterator() { | 2478 Iterator<int> iterator() { |
2451 return new _ByteArrayIterator<int>(this); | 2479 return new _ByteArrayIterator<int>(this); |
2452 } | 2480 } |
2453 | 2481 |
2454 List<int> getRange(int start, int length) { | 2482 List<int> getRange(int start, int length) { |
2455 _rangeCheck(this, start, length); | 2483 _rangeCheck(this.length, start, length); |
2456 List<int> result = new Uint8List(length); | 2484 List<int> result = new Uint8List(length); |
2457 result.setRange(0, length, this, start); | 2485 result.setRange(0, length, this, start); |
2458 return result; | 2486 return result; |
2459 } | 2487 } |
2460 | 2488 |
2461 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | 2489 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
2462 Arrays.copy(from, startFrom, this, start, length); | 2490 Arrays.copy(from, startFrom, this, start, length); |
2463 } | 2491 } |
2464 | 2492 |
2465 String toString() { | 2493 String toString() { |
2466 return Collections.collectionToString(this); | 2494 return Collections.collectionToString(this); |
2467 } | 2495 } |
2468 | 2496 |
2469 int bytesPerElement() { | 2497 int bytesPerElement() { |
2470 return _BYTES_PER_ELEMENT; | 2498 return _BYTES_PER_ELEMENT; |
2471 } | 2499 } |
2472 | 2500 |
2473 int lengthInBytes() { | 2501 int lengthInBytes() { |
2474 return _length * _BYTES_PER_ELEMENT; | 2502 return _length * _BYTES_PER_ELEMENT; |
2475 } | 2503 } |
2476 | 2504 |
2477 ByteArray asByteArray([int start = 0, int length]) { | 2505 ByteArray asByteArray([int start = 0, int length]) { |
2478 if (length == null) { | 2506 if (length == null) { |
2479 length = this.lengthInBytes(); | 2507 length = this.lengthInBytes(); |
2480 } | 2508 } |
2481 _rangeCheck(start, length); | 2509 _rangeCheck(this.length, start, length); |
2482 return _array.subByteArray(_offset + start, length); | 2510 return _array.subByteArray(_offset + start, length); |
2483 } | 2511 } |
2484 | 2512 |
2485 static final int _BYTES_PER_ELEMENT = 1; | 2513 static final int _BYTES_PER_ELEMENT = 1; |
2486 final ByteArray _array; | 2514 final ByteArray _array; |
2487 final int _offset; | 2515 final int _offset; |
2488 final int _length; | 2516 final int _length; |
2489 } | 2517 } |
2490 | 2518 |
2491 | 2519 |
2492 class _Int16ArrayView extends _ByteArrayViewBase implements Int16List { | 2520 class _Int16ArrayView extends _ByteArrayViewBase implements Int16List { |
2493 _Int16ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) | 2521 _Int16ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) |
2494 : _array = array, | 2522 : _array = array, |
2495 _offset = offsetInBytes, | 2523 _offset = _requireInteger(offsetInBytes), |
2496 _length = (length === null) ? (array.lengthInBytes() - offsetInBytes) | 2524 _length = _requireIntegerOrNull( |
2497 : length { | 2525 length, |
2526 ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT)) { | |
2498 if (offsetInBytes < 0 || offsetInBytes >= array.lengthInBytes()) { | 2527 if (offsetInBytes < 0 || offsetInBytes >= array.lengthInBytes()) { |
2499 throw new IndexOutOfRangeException(offsetInBytes); | 2528 throw new IndexOutOfRangeException(offsetInBytes); |
2500 } | 2529 } |
2501 int lengthInBytes = length * _BYTES_PER_ELEMENT; | 2530 int lengthInBytes = _length * _BYTES_PER_ELEMENT; |
2502 if (length < 0 || (lengthInBytes + _offset) > array.lengthInBytes()) { | 2531 if (_length < 0 || (lengthInBytes + _offset) > array.lengthInBytes()) { |
2503 throw new IndexOutOfRangeException(length); | 2532 throw new IndexOutOfRangeException(_length); |
2504 } | 2533 } |
2505 } | 2534 } |
2506 | 2535 |
2507 get length() { | 2536 get length() { |
2508 return _length; | 2537 return _length; |
2509 } | 2538 } |
2510 | 2539 |
2511 int operator[](int index) { | 2540 int operator[](int index) { |
2512 if (index < 0 || index >= _length) { | 2541 if (index < 0 || index >= _length) { |
2513 throw new IndexOutOfRangeException(index); | 2542 throw new IndexOutOfRangeException(index); |
2514 } | 2543 } |
2515 return _array.getInt16(_offset + (index * _BYTES_PER_ELEMENT)); | 2544 return _array.getInt16(_offset + (index * _BYTES_PER_ELEMENT)); |
2516 } | 2545 } |
2517 | 2546 |
2518 void operator[]=(int index, int value) { | 2547 void operator[]=(int index, int value) { |
2519 if (index < 0 || index >= _length) { | 2548 if (index < 0 || index >= _length) { |
2520 throw new IndexOutOfRangeException(index); | 2549 throw new IndexOutOfRangeException(index); |
2521 } | 2550 } |
2522 _array.setInt16(_offset + (index * _BYTES_PER_ELEMENT), _toInt16(value)); | 2551 _array.setInt16(_offset + (index * _BYTES_PER_ELEMENT), _toInt16(value)); |
2523 } | 2552 } |
2524 | 2553 |
2525 Iterator<int> iterator() { | 2554 Iterator<int> iterator() { |
2526 return new _ByteArrayIterator<int>(this); | 2555 return new _ByteArrayIterator<int>(this); |
2527 } | 2556 } |
2528 | 2557 |
2529 List<int> getRange(int start, int length) { | 2558 List<int> getRange(int start, int length) { |
2530 _rangeCheck(this, start, length); | 2559 _rangeCheck(this.length, start, length); |
2531 List<int> result = new Int16List(length); | 2560 List<int> result = new Int16List(length); |
2532 result.setRange(0, length, this, start); | 2561 result.setRange(0, length, this, start); |
2533 return result; | 2562 return result; |
2534 } | 2563 } |
2535 | 2564 |
2536 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | 2565 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
2537 Arrays.copy(from, startFrom, this, start, length); | 2566 Arrays.copy(from, startFrom, this, start, length); |
2538 } | 2567 } |
2539 | 2568 |
2540 String toString() { | 2569 String toString() { |
2541 return Collections.collectionToString(this); | 2570 return Collections.collectionToString(this); |
2542 } | 2571 } |
2543 | 2572 |
2544 int bytesPerElement() { | 2573 int bytesPerElement() { |
2545 return _BYTES_PER_ELEMENT; | 2574 return _BYTES_PER_ELEMENT; |
2546 } | 2575 } |
2547 | 2576 |
2548 int lengthInBytes() { | 2577 int lengthInBytes() { |
2549 return _length * _BYTES_PER_ELEMENT; | 2578 return _length * _BYTES_PER_ELEMENT; |
2550 } | 2579 } |
2551 | 2580 |
2552 ByteArray asByteArray([int start = 0, int length]) { | 2581 ByteArray asByteArray([int start = 0, int length]) { |
2553 if (length == null) { | 2582 if (length == null) { |
2554 length = this.lengthInBytes(); | 2583 length = this.lengthInBytes(); |
2555 } | 2584 } |
2556 _rangeCheck(start, length); | 2585 _rangeCheck(this.length, start, length); |
2557 return _array.subByteArray(_offset + start, length); | 2586 return _array.subByteArray(_offset + start, length); |
2558 } | 2587 } |
2559 | 2588 |
2560 static final int _BYTES_PER_ELEMENT = 2; | 2589 static final int _BYTES_PER_ELEMENT = 2; |
2561 final ByteArray _array; | 2590 final ByteArray _array; |
2562 final int _offset; | 2591 final int _offset; |
2563 final int _length; | 2592 final int _length; |
2564 } | 2593 } |
2565 | 2594 |
2566 | 2595 |
2567 class _Uint16ArrayView extends _ByteArrayViewBase implements Uint16List { | 2596 class _Uint16ArrayView extends _ByteArrayViewBase implements Uint16List { |
2568 _Uint16ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) | 2597 _Uint16ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) |
2569 : _array = array, | 2598 : _array = array, |
2570 _offset = offsetInBytes, | 2599 _offset = _requireInteger(offsetInBytes), |
2571 _length = (length === null) ? (array.lengthInBytes() - offsetInBytes) | 2600 _length = _requireIntegerOrNull( |
2572 : length { | 2601 length, |
2602 ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT)) { | |
2573 if (offsetInBytes < 0 || offsetInBytes >= array.lengthInBytes()) { | 2603 if (offsetInBytes < 0 || offsetInBytes >= array.lengthInBytes()) { |
2574 throw new IndexOutOfRangeException(offsetInBytes); | 2604 throw new IndexOutOfRangeException(offsetInBytes); |
2575 } | 2605 } |
2576 int lengthInBytes = length * _BYTES_PER_ELEMENT; | 2606 int lengthInBytes = _length * _BYTES_PER_ELEMENT; |
2577 if (length < 0 || (lengthInBytes + _offset) > array.lengthInBytes()) { | 2607 if (_length < 0 || (lengthInBytes + _offset) > array.lengthInBytes()) { |
2578 throw new IndexOutOfRangeException(length); | 2608 throw new IndexOutOfRangeException(_length); |
2579 } | 2609 } |
2580 } | 2610 } |
2581 | 2611 |
2582 get length() { | 2612 get length() { |
2583 return _length; | 2613 return _length; |
2584 } | 2614 } |
2585 | 2615 |
2586 int operator[](int index) { | 2616 int operator[](int index) { |
2587 if (index < 0 || index >= _length) { | 2617 if (index < 0 || index >= _length) { |
2588 throw new IndexOutOfRangeException(index); | 2618 throw new IndexOutOfRangeException(index); |
2589 } | 2619 } |
2590 return _array.getUint16(_offset + (index * _BYTES_PER_ELEMENT)); | 2620 return _array.getUint16(_offset + (index * _BYTES_PER_ELEMENT)); |
2591 } | 2621 } |
2592 | 2622 |
2593 void operator[]=(int index, int value) { | 2623 void operator[]=(int index, int value) { |
2594 if (index < 0 || index >= _length) { | 2624 if (index < 0 || index >= _length) { |
2595 throw new IndexOutOfRangeException(index); | 2625 throw new IndexOutOfRangeException(index); |
2596 } | 2626 } |
2597 _array.setUint16(_offset + (index * _BYTES_PER_ELEMENT), _toUint16(value)); | 2627 _array.setUint16(_offset + (index * _BYTES_PER_ELEMENT), _toUint16(value)); |
2598 } | 2628 } |
2599 | 2629 |
2600 Iterator<int> iterator() { | 2630 Iterator<int> iterator() { |
2601 return new _ByteArrayIterator<int>(this); | 2631 return new _ByteArrayIterator<int>(this); |
2602 } | 2632 } |
2603 | 2633 |
2604 List<int> getRange(int start, int length) { | 2634 List<int> getRange(int start, int length) { |
2605 _rangeCheck(this, start, length); | 2635 _rangeCheck(this.length, start, length); |
2606 List<int> result = new Uint16List(length); | 2636 List<int> result = new Uint16List(length); |
2607 result.setRange(0, length, this, start); | 2637 result.setRange(0, length, this, start); |
2608 return result; | 2638 return result; |
2609 } | 2639 } |
2610 | 2640 |
2611 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | 2641 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
2612 Arrays.copy(from, startFrom, this, start, length); | 2642 Arrays.copy(from, startFrom, this, start, length); |
2613 } | 2643 } |
2614 | 2644 |
2615 String toString() { | 2645 String toString() { |
2616 return Collections.collectionToString(this); | 2646 return Collections.collectionToString(this); |
2617 } | 2647 } |
2618 | 2648 |
2619 int bytesPerElement() { | 2649 int bytesPerElement() { |
2620 return _BYTES_PER_ELEMENT; | 2650 return _BYTES_PER_ELEMENT; |
2621 } | 2651 } |
2622 | 2652 |
2623 int lengthInBytes() { | 2653 int lengthInBytes() { |
2624 return _length * _BYTES_PER_ELEMENT; | 2654 return _length * _BYTES_PER_ELEMENT; |
2625 } | 2655 } |
2626 | 2656 |
2627 ByteArray asByteArray([int start = 0, int length]) { | 2657 ByteArray asByteArray([int start = 0, int length]) { |
2628 if (length == null) { | 2658 if (length == null) { |
2629 length = this.lengthInBytes(); | 2659 length = this.lengthInBytes(); |
2630 } | 2660 } |
2631 _rangeCheck(start, length); | 2661 _rangeCheck(this.length, start, length); |
2632 return _array.subByteArray(_offset + start, length); | 2662 return _array.subByteArray(_offset + start, length); |
2633 } | 2663 } |
2634 | 2664 |
2635 static final int _BYTES_PER_ELEMENT = 2; | 2665 static final int _BYTES_PER_ELEMENT = 2; |
2636 final ByteArray _array; | 2666 final ByteArray _array; |
2637 final int _offset; | 2667 final int _offset; |
2638 final int _length; | 2668 final int _length; |
2639 } | 2669 } |
2640 | 2670 |
2641 | 2671 |
2642 class _Int32ArrayView extends _ByteArrayViewBase implements Int32List { | 2672 class _Int32ArrayView extends _ByteArrayViewBase implements Int32List { |
2643 _Int32ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) | 2673 _Int32ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) |
2644 : _array = array, | 2674 : _array = array, |
2645 _offset = offsetInBytes, | 2675 _offset = _requireInteger(offsetInBytes), |
2646 _length = (length === null) ? (array.lengthInBytes() - offsetInBytes) | 2676 _length = _requireIntegerOrNull( |
2647 : length { | 2677 length, |
2678 ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT)) { | |
2648 if (offsetInBytes < 0 || offsetInBytes >= array.lengthInBytes()) { | 2679 if (offsetInBytes < 0 || offsetInBytes >= array.lengthInBytes()) { |
2649 throw new IndexOutOfRangeException(offsetInBytes); | 2680 throw new IndexOutOfRangeException(offsetInBytes); |
2650 } | 2681 } |
2651 int lengthInBytes = length * _BYTES_PER_ELEMENT; | 2682 int lengthInBytes = _length * _BYTES_PER_ELEMENT; |
2652 if (length < 0 || (lengthInBytes + _offset) > array.lengthInBytes()) { | 2683 if (_length < 0 || (lengthInBytes + _offset) > array.lengthInBytes()) { |
2653 throw new IndexOutOfRangeException(length); | 2684 throw new IndexOutOfRangeException(_length); |
2654 } | 2685 } |
2655 } | 2686 } |
2656 | 2687 |
2657 get length() { | 2688 get length() { |
2658 return _length; | 2689 return _length; |
2659 } | 2690 } |
2660 | 2691 |
2661 int operator[](int index) { | 2692 int operator[](int index) { |
2662 if (index < 0 || index >= _length) { | 2693 if (index < 0 || index >= _length) { |
2663 throw new IndexOutOfRangeException(index); | 2694 throw new IndexOutOfRangeException(index); |
2664 } | 2695 } |
2665 return _array.getInt32(_offset + (index * _BYTES_PER_ELEMENT)); | 2696 return _array.getInt32(_offset + (index * _BYTES_PER_ELEMENT)); |
2666 } | 2697 } |
2667 | 2698 |
2668 void operator[]=(int index, int value) { | 2699 void operator[]=(int index, int value) { |
2669 if (index < 0 || index >= _length) { | 2700 if (index < 0 || index >= _length) { |
2670 throw new IndexOutOfRangeException(index); | 2701 throw new IndexOutOfRangeException(index); |
2671 } | 2702 } |
2672 _array.setInt32(_offset + (index * _BYTES_PER_ELEMENT), _toInt32(value)); | 2703 _array.setInt32(_offset + (index * _BYTES_PER_ELEMENT), _toInt32(value)); |
2673 } | 2704 } |
2674 | 2705 |
2675 Iterator<int> iterator() { | 2706 Iterator<int> iterator() { |
2676 return new _ByteArrayIterator<int>(this); | 2707 return new _ByteArrayIterator<int>(this); |
2677 } | 2708 } |
2678 | 2709 |
2679 List<int> getRange(int start, int length) { | 2710 List<int> getRange(int start, int length) { |
2680 _rangeCheck(this, start, length); | 2711 _rangeCheck(this.length, start, length); |
2681 List<int> result = new Int32List(length); | 2712 List<int> result = new Int32List(length); |
2682 result.setRange(0, length, this, start); | 2713 result.setRange(0, length, this, start); |
2683 return result; | 2714 return result; |
2684 } | 2715 } |
2685 | 2716 |
2686 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | 2717 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
2687 Arrays.copy(from, startFrom, this, start, length); | 2718 Arrays.copy(from, startFrom, this, start, length); |
2688 } | 2719 } |
2689 | 2720 |
2690 String toString() { | 2721 String toString() { |
2691 return Collections.collectionToString(this); | 2722 return Collections.collectionToString(this); |
2692 } | 2723 } |
2693 | 2724 |
2694 int bytesPerElement() { | 2725 int bytesPerElement() { |
2695 return _BYTES_PER_ELEMENT; | 2726 return _BYTES_PER_ELEMENT; |
2696 } | 2727 } |
2697 | 2728 |
2698 int lengthInBytes() { | 2729 int lengthInBytes() { |
2699 return _length * _BYTES_PER_ELEMENT; | 2730 return _length * _BYTES_PER_ELEMENT; |
2700 } | 2731 } |
2701 | 2732 |
2702 ByteArray asByteArray([int start = 0, int length]) { | 2733 ByteArray asByteArray([int start = 0, int length]) { |
2703 if (length == null) { | 2734 if (length == null) { |
2704 length = this.lengthInBytes(); | 2735 length = this.lengthInBytes(); |
2705 } | 2736 } |
2706 _rangeCheck(start, length); | 2737 _rangeCheck(this.length, start, length); |
2707 return _array.subByteArray(_offset + start, length); | 2738 return _array.subByteArray(_offset + start, length); |
2708 } | 2739 } |
2709 | 2740 |
2710 static final int _BYTES_PER_ELEMENT = 4; | 2741 static final int _BYTES_PER_ELEMENT = 4; |
2711 final ByteArray _array; | 2742 final ByteArray _array; |
2712 final int _offset; | 2743 final int _offset; |
2713 final int _length; | 2744 final int _length; |
2714 } | 2745 } |
2715 | 2746 |
2716 | 2747 |
2717 class _Uint32ArrayView extends _ByteArrayViewBase implements Uint32List { | 2748 class _Uint32ArrayView extends _ByteArrayViewBase implements Uint32List { |
2718 _Uint32ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) | 2749 _Uint32ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) |
2719 : _array = array, | 2750 : _array = array, |
2720 _offset = offsetInBytes, | 2751 _offset = _requireInteger(offsetInBytes), |
2721 _length = (length === null) ? (array.lengthInBytes() - offsetInBytes) | 2752 _length = _requireIntegerOrNull( |
2722 : length { | 2753 length, |
2754 ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT)) { | |
2723 if (offsetInBytes < 0 || offsetInBytes >= array.lengthInBytes()) { | 2755 if (offsetInBytes < 0 || offsetInBytes >= array.lengthInBytes()) { |
2724 throw new IndexOutOfRangeException(offsetInBytes); | 2756 throw new IndexOutOfRangeException(offsetInBytes); |
2725 } | 2757 } |
2726 int lengthInBytes = length * _BYTES_PER_ELEMENT; | 2758 int lengthInBytes = _length * _BYTES_PER_ELEMENT; |
2727 if (length < 0 || (lengthInBytes + _offset) > array.lengthInBytes()) { | 2759 if (_length < 0 || (lengthInBytes + _offset) > array.lengthInBytes()) { |
2728 throw new IndexOutOfRangeException(length); | 2760 throw new IndexOutOfRangeException(_length); |
2729 } | 2761 } |
2730 } | 2762 } |
2731 | 2763 |
2732 get length() { | 2764 get length() { |
2733 return _length; | 2765 return _length; |
2734 } | 2766 } |
2735 | 2767 |
2736 int operator[](int index) { | 2768 int operator[](int index) { |
2737 if (index < 0 || index >= _length) { | 2769 if (index < 0 || index >= _length) { |
2738 throw new IndexOutOfRangeException(index); | 2770 throw new IndexOutOfRangeException(index); |
2739 } | 2771 } |
2740 return _array.getUint32(_offset + (index * _BYTES_PER_ELEMENT)); | 2772 return _array.getUint32(_offset + (index * _BYTES_PER_ELEMENT)); |
2741 } | 2773 } |
2742 | 2774 |
2743 void operator[]=(int index, int value) { | 2775 void operator[]=(int index, int value) { |
2744 if (index < 0 || index >= _length) { | 2776 if (index < 0 || index >= _length) { |
2745 throw new IndexOutOfRangeException(index); | 2777 throw new IndexOutOfRangeException(index); |
2746 } | 2778 } |
2747 _array.setUint32(_offset + (index * _BYTES_PER_ELEMENT), _toUint32(value)); | 2779 _array.setUint32(_offset + (index * _BYTES_PER_ELEMENT), _toUint32(value)); |
2748 } | 2780 } |
2749 | 2781 |
2750 Iterator<int> iterator() { | 2782 Iterator<int> iterator() { |
2751 return new _ByteArrayIterator<int>(this); | 2783 return new _ByteArrayIterator<int>(this); |
2752 } | 2784 } |
2753 | 2785 |
2754 List<int> getRange(int start, int length) { | 2786 List<int> getRange(int start, int length) { |
2755 _rangeCheck(this, start, length); | 2787 _rangeCheck(this.length, start, length); |
2756 List<int> result = new Uint32List(length); | 2788 List<int> result = new Uint32List(length); |
2757 result.setRange(0, length, this, start); | 2789 result.setRange(0, length, this, start); |
2758 return result; | 2790 return result; |
2759 } | 2791 } |
2760 | 2792 |
2761 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | 2793 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
2762 Arrays.copy(from, startFrom, this, start, length); | 2794 Arrays.copy(from, startFrom, this, start, length); |
2763 } | 2795 } |
2764 | 2796 |
2765 String toString() { | 2797 String toString() { |
2766 return Collections.collectionToString(this); | 2798 return Collections.collectionToString(this); |
2767 } | 2799 } |
2768 | 2800 |
2769 int bytesPerElement() { | 2801 int bytesPerElement() { |
2770 return _BYTES_PER_ELEMENT; | 2802 return _BYTES_PER_ELEMENT; |
2771 } | 2803 } |
2772 | 2804 |
2773 int lengthInBytes() { | 2805 int lengthInBytes() { |
2774 return _length * _BYTES_PER_ELEMENT; | 2806 return _length * _BYTES_PER_ELEMENT; |
2775 } | 2807 } |
2776 | 2808 |
2777 ByteArray asByteArray([int start = 0, int length]) { | 2809 ByteArray asByteArray([int start = 0, int length]) { |
2778 if (length == null) { | 2810 if (length == null) { |
2779 length = this.lengthInBytes(); | 2811 length = this.lengthInBytes(); |
2780 } | 2812 } |
2781 _rangeCheck(start, length); | 2813 _rangeCheck(this.length, start, length); |
2782 return _array.subByteArray(_offset + start, length); | 2814 return _array.subByteArray(_offset + start, length); |
2783 } | 2815 } |
2784 | 2816 |
2785 static final int _BYTES_PER_ELEMENT = 4; | 2817 static final int _BYTES_PER_ELEMENT = 4; |
2786 final ByteArray _array; | 2818 final ByteArray _array; |
2787 final int _offset; | 2819 final int _offset; |
2788 final int _length; | 2820 final int _length; |
2789 } | 2821 } |
2790 | 2822 |
2791 | 2823 |
2792 class _Int64ArrayView extends _ByteArrayViewBase implements Int64List { | 2824 class _Int64ArrayView extends _ByteArrayViewBase implements Int64List { |
2793 _Int64ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) | 2825 _Int64ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) |
2794 : _array = array, | 2826 : _array = array, |
2795 _offset = offsetInBytes, | 2827 _offset = _requireInteger(offsetInBytes), |
2796 _length = (length === null) ? (array.lengthInBytes() - offsetInBytes) | 2828 _length = _requireIntegerOrNull( |
2797 : length { | 2829 length, |
2830 ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT)) { | |
2798 if (offsetInBytes < 0 || offsetInBytes >= array.lengthInBytes()) { | 2831 if (offsetInBytes < 0 || offsetInBytes >= array.lengthInBytes()) { |
2799 throw new IndexOutOfRangeException(offsetInBytes); | 2832 throw new IndexOutOfRangeException(offsetInBytes); |
2800 } | 2833 } |
2801 int lengthInBytes = length * _BYTES_PER_ELEMENT; | 2834 int lengthInBytes = _length * _BYTES_PER_ELEMENT; |
2802 if (length < 0 || (lengthInBytes + _offset) > array.lengthInBytes()) { | 2835 if (_length < 0 || (lengthInBytes + _offset) > array.lengthInBytes()) { |
2803 throw new IndexOutOfRangeException(length); | 2836 throw new IndexOutOfRangeException(_length); |
2804 } | 2837 } |
2805 } | 2838 } |
2806 | 2839 |
2807 get length() { | 2840 get length() { |
2808 return _length; | 2841 return _length; |
2809 } | 2842 } |
2810 | 2843 |
2811 int operator[](int index) { | 2844 int operator[](int index) { |
2812 if (index < 0 || index >= _length) { | 2845 if (index < 0 || index >= _length) { |
2813 throw new IndexOutOfRangeException(index); | 2846 throw new IndexOutOfRangeException(index); |
2814 } | 2847 } |
2815 return _array.getInt64(_offset + (index * _BYTES_PER_ELEMENT)); | 2848 return _array.getInt64(_offset + (index * _BYTES_PER_ELEMENT)); |
2816 } | 2849 } |
2817 | 2850 |
2818 void operator[]=(int index, int value) { | 2851 void operator[]=(int index, int value) { |
2819 if (index < 0 || index >= _length) { | 2852 if (index < 0 || index >= _length) { |
2820 throw new IndexOutOfRangeException(index); | 2853 throw new IndexOutOfRangeException(index); |
2821 } | 2854 } |
2822 _array.setInt64(_offset + (index * _BYTES_PER_ELEMENT), _toInt64(value)); | 2855 _array.setInt64(_offset + (index * _BYTES_PER_ELEMENT), _toInt64(value)); |
2823 } | 2856 } |
2824 | 2857 |
2825 Iterator<int> iterator() { | 2858 Iterator<int> iterator() { |
2826 return new _ByteArrayIterator<int>(this); | 2859 return new _ByteArrayIterator<int>(this); |
2827 } | 2860 } |
2828 | 2861 |
2829 List<int> getRange(int start, int length) { | 2862 List<int> getRange(int start, int length) { |
2830 _rangeCheck(this, start, length); | 2863 _rangeCheck(this.length, start, length); |
2831 List<int> result = new Int64List(length); | 2864 List<int> result = new Int64List(length); |
2832 result.setRange(0, length, this, start); | 2865 result.setRange(0, length, this, start); |
2833 return result; | 2866 return result; |
2834 } | 2867 } |
2835 | 2868 |
2836 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | 2869 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
2837 Arrays.copy(from, startFrom, this, start, length); | 2870 Arrays.copy(from, startFrom, this, start, length); |
2838 } | 2871 } |
2839 | 2872 |
2840 String toString() { | 2873 String toString() { |
2841 return Collections.collectionToString(this); | 2874 return Collections.collectionToString(this); |
2842 } | 2875 } |
2843 | 2876 |
2844 int bytesPerElement() { | 2877 int bytesPerElement() { |
2845 return _BYTES_PER_ELEMENT; | 2878 return _BYTES_PER_ELEMENT; |
2846 } | 2879 } |
2847 | 2880 |
2848 int lengthInBytes() { | 2881 int lengthInBytes() { |
2849 return _length * _BYTES_PER_ELEMENT; | 2882 return _length * _BYTES_PER_ELEMENT; |
2850 } | 2883 } |
2851 | 2884 |
2852 ByteArray asByteArray([int start = 0, int length]) { | 2885 ByteArray asByteArray([int start = 0, int length]) { |
2853 if (length == null) { | 2886 if (length == null) { |
2854 length = this.lengthInBytes(); | 2887 length = this.lengthInBytes(); |
2855 } | 2888 } |
2856 _rangeCheck(start, length); | 2889 _rangeCheck(this.length, start, length); |
2857 return _array.subByteArray(_offset + start, length); | 2890 return _array.subByteArray(_offset + start, length); |
2858 } | 2891 } |
2859 | 2892 |
2860 static final int _BYTES_PER_ELEMENT = 8; | 2893 static final int _BYTES_PER_ELEMENT = 8; |
2861 final ByteArray _array; | 2894 final ByteArray _array; |
2862 final int _offset; | 2895 final int _offset; |
2863 final int _length; | 2896 final int _length; |
2864 } | 2897 } |
2865 | 2898 |
2866 | 2899 |
2867 class _Uint64ArrayView extends _ByteArrayViewBase implements Uint64List { | 2900 class _Uint64ArrayView extends _ByteArrayViewBase implements Uint64List { |
2868 _Uint64ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) | 2901 _Uint64ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) |
2869 : _array = array, | 2902 : _array = array, |
2870 _offset = offsetInBytes, | 2903 _offset = _requireInteger(offsetInBytes), |
2871 _length = (length === null) ? (array.lengthInBytes() - offsetInBytes) | 2904 _length = _requireIntegerOrNull( |
2872 : length { | 2905 length, |
2906 ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT)) { | |
2873 if (offsetInBytes < 0 || offsetInBytes >= array.lengthInBytes()) { | 2907 if (offsetInBytes < 0 || offsetInBytes >= array.lengthInBytes()) { |
2874 throw new IndexOutOfRangeException(offsetInBytes); | 2908 throw new IndexOutOfRangeException(offsetInBytes); |
2875 } | 2909 } |
2876 int lengthInBytes = length * _BYTES_PER_ELEMENT; | 2910 int lengthInBytes = _length * _BYTES_PER_ELEMENT; |
2877 if (length < 0 || (lengthInBytes + _offset) > array.lengthInBytes()) { | 2911 if (_length < 0 || (lengthInBytes + _offset) > array.lengthInBytes()) { |
2878 throw new IndexOutOfRangeException(length); | 2912 throw new IndexOutOfRangeException(_length); |
2879 } | 2913 } |
siva
2012/06/21 23:33:08
This check code seems identical in each of the vie
cshapiro
2012/06/22 04:27:00
Yes, this is doing pretty much what _rangeCheck al
| |
2880 } | 2914 } |
2881 | 2915 |
2882 get length() { | 2916 get length() { |
2883 return _length; | 2917 return _length; |
2884 } | 2918 } |
2885 | 2919 |
2886 int operator[](int index) { | 2920 int operator[](int index) { |
2887 if (index < 0 || index >= _length) { | 2921 if (index < 0 || index >= _length) { |
2888 throw new IndexOutOfRangeException(index); | 2922 throw new IndexOutOfRangeException(index); |
2889 } | 2923 } |
2890 return _array.getUint64(_offset + (index * _BYTES_PER_ELEMENT)); | 2924 return _array.getUint64(_offset + (index * _BYTES_PER_ELEMENT)); |
2891 } | 2925 } |
2892 | 2926 |
2893 void operator[]=(int index, int value) { | 2927 void operator[]=(int index, int value) { |
2894 if (index < 0 || index >= _length) { | 2928 if (index < 0 || index >= _length) { |
2895 throw new IndexOutOfRangeException(index); | 2929 throw new IndexOutOfRangeException(index); |
2896 } | 2930 } |
2897 _array.setUint64(_offset + (index * _BYTES_PER_ELEMENT), _toUint64(value)); | 2931 _array.setUint64(_offset + (index * _BYTES_PER_ELEMENT), _toUint64(value)); |
2898 } | 2932 } |
2899 | 2933 |
2900 Iterator<int> iterator() { | 2934 Iterator<int> iterator() { |
2901 return new _ByteArrayIterator<int>(this); | 2935 return new _ByteArrayIterator<int>(this); |
2902 } | 2936 } |
2903 | 2937 |
2904 List<int> getRange(int start, int length) { | 2938 List<int> getRange(int start, int length) { |
2905 _rangeCheck(this, start, length); | 2939 _rangeCheck(this.length, start, length); |
2906 List<int> result = new Uint64List(length); | 2940 List<int> result = new Uint64List(length); |
2907 result.setRange(0, length, this, start); | 2941 result.setRange(0, length, this, start); |
2908 return result; | 2942 return result; |
2909 } | 2943 } |
2910 | 2944 |
2911 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | 2945 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
2912 Arrays.copy(from, startFrom, this, start, length); | 2946 Arrays.copy(from, startFrom, this, start, length); |
2913 } | 2947 } |
2914 | 2948 |
2915 String toString() { | 2949 String toString() { |
2916 return Collections.collectionToString(this); | 2950 return Collections.collectionToString(this); |
2917 } | 2951 } |
2918 | 2952 |
2919 int bytesPerElement() { | 2953 int bytesPerElement() { |
2920 return _BYTES_PER_ELEMENT; | 2954 return _BYTES_PER_ELEMENT; |
2921 } | 2955 } |
2922 | 2956 |
2923 int lengthInBytes() { | 2957 int lengthInBytes() { |
2924 return _length * _BYTES_PER_ELEMENT; | 2958 return _length * _BYTES_PER_ELEMENT; |
2925 } | 2959 } |
2926 | 2960 |
2927 ByteArray asByteArray([int start = 0, int length]) { | 2961 ByteArray asByteArray([int start = 0, int length]) { |
2928 if (length == null) { | 2962 if (length == null) { |
2929 length = this.lengthInBytes(); | 2963 length = this.lengthInBytes(); |
2930 } | 2964 } |
2931 _rangeCheck(start, length); | 2965 _rangeCheck(this.length, start, length); |
2932 return _array.subByteArray(_offset + start, length); | 2966 return _array.subByteArray(_offset + start, length); |
2933 } | 2967 } |
2934 | 2968 |
2935 static final int _BYTES_PER_ELEMENT = 8; | 2969 static final int _BYTES_PER_ELEMENT = 8; |
2936 final ByteArray _array; | 2970 final ByteArray _array; |
2937 final int _offset; | 2971 final int _offset; |
2938 final int _length; | 2972 final int _length; |
2939 } | 2973 } |
2940 | 2974 |
2941 | 2975 |
2942 class _Float32ArrayView extends _ByteArrayViewBase implements Float32List { | 2976 class _Float32ArrayView extends _ByteArrayViewBase implements Float32List { |
2943 _Float32ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) | 2977 _Float32ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) |
2944 : _array = array, | 2978 : _array = array, |
2945 _offset = offsetInBytes, | 2979 _offset = _requireInteger(offsetInBytes), |
2946 _length = (length === null) ? (array.lengthInBytes() - offsetInBytes) | 2980 _length = _requireIntegerOrNull( |
2947 : length { | 2981 length, |
2982 ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT)) { | |
2948 if (offsetInBytes < 0 || offsetInBytes >= array.lengthInBytes()) { | 2983 if (offsetInBytes < 0 || offsetInBytes >= array.lengthInBytes()) { |
2949 throw new IndexOutOfRangeException(offsetInBytes); | 2984 throw new IndexOutOfRangeException(offsetInBytes); |
2950 } | 2985 } |
2951 int lengthInBytes = length * _BYTES_PER_ELEMENT; | 2986 int lengthInBytes = _length * _BYTES_PER_ELEMENT; // TODO: broken |
2952 if (length < 0 || (lengthInBytes + _offset) > array.lengthInBytes()) { | 2987 if (_length < 0 || (lengthInBytes + _offset) > array.lengthInBytes()) { |
2953 throw new IndexOutOfRangeException(length); | 2988 throw new IndexOutOfRangeException(_length); |
2954 } | 2989 } |
2955 } | 2990 } |
2956 | 2991 |
2957 get length() { | 2992 get length() { |
2958 return _length; | 2993 return _length; |
2959 } | 2994 } |
2960 | 2995 |
2961 double operator[](int index) { | 2996 double operator[](int index) { |
2962 if (index < 0 || index >= _length) { | 2997 if (index < 0 || index >= _length) { |
2963 throw new IndexOutOfRangeException(index); | 2998 throw new IndexOutOfRangeException(index); |
2964 } | 2999 } |
2965 return _array.getFloat32(_offset + (index * _BYTES_PER_ELEMENT)); | 3000 return _array.getFloat32(_offset + (index * _BYTES_PER_ELEMENT)); |
2966 } | 3001 } |
2967 | 3002 |
2968 void operator[]=(int index, double value) { | 3003 void operator[]=(int index, double value) { |
2969 if (index < 0 || index >= _length) { | 3004 if (index < 0 || index >= _length) { |
2970 throw new IndexOutOfRangeException(index); | 3005 throw new IndexOutOfRangeException(index); |
2971 } | 3006 } |
2972 _array.setFloat32(_offset + (index * _BYTES_PER_ELEMENT), value); | 3007 _array.setFloat32(_offset + (index * _BYTES_PER_ELEMENT), value); |
2973 } | 3008 } |
2974 | 3009 |
2975 Iterator<double> iterator() { | 3010 Iterator<double> iterator() { |
2976 return new _ByteArrayIterator<double>(this); | 3011 return new _ByteArrayIterator<double>(this); |
2977 } | 3012 } |
2978 | 3013 |
2979 List<double> getRange(int start, int length) { | 3014 List<double> getRange(int start, int length) { |
2980 _rangeCheck(this, start, length); | 3015 _rangeCheck(this.length, start, length); |
2981 List<double> result = new Float32List(length); | 3016 List<double> result = new Float32List(length); |
2982 result.setRange(0, length, this, start); | 3017 result.setRange(0, length, this, start); |
2983 return result; | 3018 return result; |
2984 } | 3019 } |
2985 | 3020 |
2986 void setRange(int start, int length, List<double> from, [int startFrom = 0]) { | 3021 void setRange(int start, int length, List<double> from, [int startFrom = 0]) { |
2987 Arrays.copy(from, startFrom, this, start, length); | 3022 Arrays.copy(from, startFrom, this, start, length); |
2988 } | 3023 } |
2989 | 3024 |
2990 String toString() { | 3025 String toString() { |
2991 return Collections.collectionToString(this); | 3026 return Collections.collectionToString(this); |
2992 } | 3027 } |
2993 | 3028 |
2994 int bytesPerElement() { | 3029 int bytesPerElement() { |
2995 return _BYTES_PER_ELEMENT; | 3030 return _BYTES_PER_ELEMENT; |
2996 } | 3031 } |
2997 | 3032 |
2998 int lengthInBytes() { | 3033 int lengthInBytes() { |
2999 return _length * _BYTES_PER_ELEMENT; | 3034 return _length * _BYTES_PER_ELEMENT; |
3000 } | 3035 } |
3001 | 3036 |
3002 ByteArray asByteArray([int start = 0, int length]) { | 3037 ByteArray asByteArray([int start = 0, int length]) { |
3003 if (length == null) { | 3038 if (length == null) { |
3004 length = this.lengthInBytes(); | 3039 length = this.lengthInBytes(); |
3005 } | 3040 } |
3006 _rangeCheck(start, length); | 3041 _rangeCheck(this.length, start, length); |
3007 return _array.subByteArray(_offset + start, length); | 3042 return _array.subByteArray(_offset + start, length); |
3008 } | 3043 } |
3009 | 3044 |
3010 static final int _BYTES_PER_ELEMENT = 4; | 3045 static final int _BYTES_PER_ELEMENT = 4; |
3011 final ByteArray _array; | 3046 final ByteArray _array; |
3012 final int _offset; | 3047 final int _offset; |
3013 final int _length; | 3048 final int _length; |
3014 } | 3049 } |
3015 | 3050 |
3016 | 3051 |
3017 class _Float64ArrayView extends _ByteArrayViewBase implements Float64List { | 3052 class _Float64ArrayView extends _ByteArrayViewBase implements Float64List { |
3018 _Float64ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) | 3053 _Float64ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) |
3019 : _array = array, | 3054 : _array = array, |
3020 _offset = offsetInBytes, | 3055 _offset = _requireInteger(offsetInBytes), |
3021 _length = (length === null) ? (array.lengthInBytes() - offsetInBytes) | 3056 _length = _requireIntegerOrNull( |
3022 : length { | 3057 length, |
3058 ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT)) { | |
3023 if (offsetInBytes < 0 || offsetInBytes >= array.lengthInBytes()) { | 3059 if (offsetInBytes < 0 || offsetInBytes >= array.lengthInBytes()) { |
3024 throw new IndexOutOfRangeException(offsetInBytes); | 3060 throw new IndexOutOfRangeException(offsetInBytes); |
3025 } | 3061 } |
3026 int lengthInBytes = length * _BYTES_PER_ELEMENT; | 3062 int lengthInBytes = _length * _BYTES_PER_ELEMENT; |
3027 if (length < 0 || (lengthInBytes + _offset) > array.lengthInBytes()) { | 3063 if (_length < 0 || (lengthInBytes + _offset) > array.lengthInBytes()) { |
3028 throw new IndexOutOfRangeException(length); | 3064 throw new IndexOutOfRangeException(_length); |
3029 } | 3065 } |
3030 } | 3066 } |
3031 | 3067 |
3032 get length() { | 3068 get length() { |
3033 return _length; | 3069 return _length; |
3034 } | 3070 } |
3035 | 3071 |
3036 double operator[](int index) { | 3072 double operator[](int index) { |
3037 if (index < 0 || index >= _length) { | 3073 if (index < 0 || index >= _length) { |
3038 throw new IndexOutOfRangeException(index); | 3074 throw new IndexOutOfRangeException(index); |
3039 } | 3075 } |
3040 return _array.getFloat64(_offset + (index * _BYTES_PER_ELEMENT)); | 3076 return _array.getFloat64(_offset + (index * _BYTES_PER_ELEMENT)); |
3041 } | 3077 } |
3042 | 3078 |
3043 void operator[]=(int index, double value) { | 3079 void operator[]=(int index, double value) { |
3044 if (index < 0 || index >= _length) { | 3080 if (index < 0 || index >= _length) { |
3045 throw new IndexOutOfRangeException(index); | 3081 throw new IndexOutOfRangeException(index); |
3046 } | 3082 } |
3047 _array.setFloat64(_offset + (index * _BYTES_PER_ELEMENT), value); | 3083 _array.setFloat64(_offset + (index * _BYTES_PER_ELEMENT), value); |
3048 } | 3084 } |
3049 | 3085 |
3050 Iterator<double> iterator() { | 3086 Iterator<double> iterator() { |
3051 return new _ByteArrayIterator<double>(this); | 3087 return new _ByteArrayIterator<double>(this); |
3052 } | 3088 } |
3053 | 3089 |
3054 List<double> getRange(int start, int length) { | 3090 List<double> getRange(int start, int length) { |
3055 _rangeCheck(this, start, length); | 3091 _rangeCheck(this.length, start, length); |
3056 List<double> result = new Float64List(length); | 3092 List<double> result = new Float64List(length); |
3057 result.setRange(0, length, this, start); | 3093 result.setRange(0, length, this, start); |
3058 return result; | 3094 return result; |
3059 } | 3095 } |
3060 | 3096 |
3061 void setRange(int start, int length, List<double> from, [int startFrom = 0]) { | 3097 void setRange(int start, int length, List<double> from, [int startFrom = 0]) { |
3062 Arrays.copy(from, startFrom, this, start, length); | 3098 Arrays.copy(from, startFrom, this, start, length); |
3063 } | 3099 } |
3064 | 3100 |
3065 String toString() { | 3101 String toString() { |
3066 return Collections.collectionToString(this); | 3102 return Collections.collectionToString(this); |
3067 } | 3103 } |
3068 | 3104 |
3069 int bytesPerElement() { | 3105 int bytesPerElement() { |
3070 return _BYTES_PER_ELEMENT; | 3106 return _BYTES_PER_ELEMENT; |
3071 } | 3107 } |
3072 | 3108 |
3073 int lengthInBytes() { | 3109 int lengthInBytes() { |
3074 return _length * _BYTES_PER_ELEMENT; | 3110 return _length * _BYTES_PER_ELEMENT; |
3075 } | 3111 } |
3076 | 3112 |
3077 ByteArray asByteArray([int start = 0, int length]) { | 3113 ByteArray asByteArray([int start = 0, int length]) { |
3078 if (length == null) { | 3114 if (length == null) { |
3079 length = this.lengthInBytes(); | 3115 length = this.lengthInBytes(); |
3080 } | 3116 } |
3081 _rangeCheck(start, length); | 3117 _rangeCheck(this.length, start, length); |
3082 return _array.subByteArray(_offset + start, length); | 3118 return _array.subByteArray(_offset + start, length); |
3083 } | 3119 } |
3084 | 3120 |
3085 static final int _BYTES_PER_ELEMENT = 8; | 3121 static final int _BYTES_PER_ELEMENT = 8; |
3086 final ByteArray _array; | 3122 final ByteArray _array; |
3087 final int _offset; | 3123 final int _offset; |
3088 final int _length; | 3124 final int _length; |
3089 } | 3125 } |
OLD | NEW |