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 interface ByteArray extends List default _InternalByteArray { | 5 interface ByteArray { |
6 ByteArray(int length); | 6 int lengthInBytes(); |
7 | 7 |
8 int get length(); | 8 ByteArray subByteArray([int start, int length]); |
9 | 9 |
10 int getInt8(int byteOffset); | 10 int getInt8(int byteOffset); |
11 | 11 |
12 void setInt8(int byteOffset, int value); | 12 void setInt8(int byteOffset, int value); |
13 | 13 |
14 int getUint8(int byteOffset); | 14 int getUint8(int byteOffset); |
15 | 15 |
16 void setUint8(int byteOffset, int value); | 16 void setUint8(int byteOffset, int value); |
17 | 17 |
18 int getInt16(int byteOffset); | 18 int getInt16(int byteOffset); |
(...skipping 23 matching lines...) Expand all Loading... |
42 double getFloat32(int byteOffset); | 42 double getFloat32(int byteOffset); |
43 | 43 |
44 void setFloat32(int byteOffset, double value); | 44 void setFloat32(int byteOffset, double value); |
45 | 45 |
46 double getFloat64(int byteOffset); | 46 double getFloat64(int byteOffset); |
47 | 47 |
48 void setFloat64(int byteOffset, double value); | 48 void setFloat64(int byteOffset, double value); |
49 } | 49 } |
50 | 50 |
51 | 51 |
52 class _ByteArrayBase { | 52 interface ByteArrayViewable { |
53 | 53 int bytesPerElement(); |
54 // Iterable interface | 54 |
55 | 55 int lengthInBytes(); |
56 Iterator iterator() { | 56 |
57 return new _ByteArrayIterator(this); | 57 ByteArray asByteArray([int offsetInBytes, int lengthInBytes]); |
58 } | 58 } |
59 | 59 |
60 // Collection interface | 60 |
| 61 interface Int8List extends List<int>, ByteArrayViewable |
| 62 default _Int8ArrayFactory { |
| 63 Int8List(int length); |
| 64 Int8List.view(ByteArray array, [int start, int length]); |
| 65 } |
| 66 |
| 67 |
| 68 interface Uint8List extends List<int>, ByteArrayViewable |
| 69 default _Uint8ArrayFactory { |
| 70 Uint8List(int length); |
| 71 Uint8List.view(ByteArray array, [int start, int length]); |
| 72 } |
| 73 |
| 74 |
| 75 interface Int16List extends List<int>, ByteArrayViewable |
| 76 default _Int16ArrayFactory { |
| 77 Int16List(int length); |
| 78 Int16List.view(ByteArray array, [int start, int length]); |
| 79 } |
| 80 |
| 81 |
| 82 interface Uint16List extends List<int>, ByteArrayViewable |
| 83 default _Uint16ArrayFactory { |
| 84 Uint16List(int length); |
| 85 Uint16List.view(ByteArray array, [int start, int length]); |
| 86 } |
| 87 |
| 88 |
| 89 interface Int32List extends List<int>, ByteArrayViewable |
| 90 default _Int32ArrayFactory { |
| 91 Int32List(int length); |
| 92 Int32List.view(ByteArray array, [int start, int length]); |
| 93 } |
| 94 |
| 95 |
| 96 interface Uint32List extends List<int>, ByteArrayViewable |
| 97 default _Uint32ArrayFactory { |
| 98 Uint32List(int length); |
| 99 Uint32List.view(ByteArray array, [int start, int length]); |
| 100 |
| 101 } |
| 102 |
| 103 |
| 104 interface Int64List extends List<int>, ByteArrayViewable |
| 105 default _Int64ArrayFactory { |
| 106 Int64List(int length); |
| 107 Int64List.view(ByteArray array, [int start, int length]); |
| 108 } |
| 109 |
| 110 |
| 111 interface Uint64List extends List<int>, ByteArrayViewable |
| 112 default _Uint64ArrayFactory { |
| 113 Uint64List(int length); |
| 114 Uint64List.view(ByteArray array, [int start, int length]); |
| 115 } |
| 116 |
| 117 |
| 118 interface Float32List extends List<double>, ByteArrayViewable |
| 119 default _Float32ArrayFactory { |
| 120 Float32List(int length); |
| 121 Float32List.view(ByteArray array, [int start, int length]); |
| 122 } |
| 123 |
| 124 |
| 125 interface Float64List extends List<double>, ByteArrayViewable |
| 126 default _Float64ArrayFactory { |
| 127 Float64List(int length); |
| 128 Float64List.view(ByteArray array, [int start, int length]); |
| 129 } |
| 130 |
| 131 |
| 132 class _Int8ArrayFactory { |
| 133 factory Int8List(int length) { |
| 134 return new _Int8Array(length); |
| 135 } |
| 136 |
| 137 factory Int8List.view(ByteArray array, [int start, int length]) { |
| 138 return new _Int8ArrayView(array, start, length); |
| 139 } |
| 140 } |
| 141 |
| 142 |
| 143 class _Uint8ArrayFactory { |
| 144 factory Uint8List(int length) { |
| 145 return new _Uint8Array(length); |
| 146 } |
| 147 |
| 148 factory Uint8List.view(ByteArray array, [int start, int length]) { |
| 149 return new _Uint8ArrayView(array, start, length); |
| 150 } |
| 151 } |
| 152 |
| 153 |
| 154 class _Int16ArrayFactory { |
| 155 factory Int16List(int length) { |
| 156 return new _Int16Array(length); |
| 157 } |
| 158 |
| 159 factory Int16List.view(ByteArray array, [int start, int length]) { |
| 160 return new _Int16ArrayView(array, start, length); |
| 161 } |
| 162 } |
| 163 |
| 164 |
| 165 class _Uint16ArrayFactory { |
| 166 factory Uint16List(int length) { |
| 167 return new _Uint16Array(length); |
| 168 } |
| 169 |
| 170 factory Uint16List.view(ByteArray array, [int start, int length]) { |
| 171 return new _Uint16ArrayView(array, start, length); |
| 172 } |
| 173 } |
| 174 |
| 175 |
| 176 class _Int32ArrayFactory { |
| 177 factory Int32List(int length) { |
| 178 return new _Int32Array(length); |
| 179 } |
| 180 |
| 181 factory Int32List.view(ByteArray array, [int start, int length]) { |
| 182 return new _Int32ArrayView(array, start, length); |
| 183 } |
| 184 } |
| 185 |
| 186 |
| 187 class _Uint32ArrayFactory { |
| 188 factory Uint32List(int length) { |
| 189 return new _Uint32Array(length); |
| 190 } |
| 191 |
| 192 factory Uint32List.view(ByteArray array, [int start, int length]) { |
| 193 return new _Uint32ArrayView(array, start, length); |
| 194 } |
| 195 } |
| 196 |
| 197 |
| 198 class _Int64ArrayFactory { |
| 199 factory Int64List(int length) { |
| 200 return new _Int64Array(length); |
| 201 } |
| 202 |
| 203 factory Int64List.view(ByteArray array, [int start, int length]) { |
| 204 return new _Int64ArrayView(array, start, length); |
| 205 } |
| 206 } |
| 207 |
| 208 |
| 209 class _Uint64ArrayFactory { |
| 210 factory Uint64List(int length) { |
| 211 return new _Uint64Array(length); |
| 212 } |
| 213 |
| 214 factory Uint64List.view(ByteArray array, [int start, int length]) { |
| 215 return new _Uint64ArrayView(array, start, length); |
| 216 } |
| 217 } |
| 218 |
| 219 |
| 220 class _Float32ArrayFactory { |
| 221 factory Float32List(int length) { |
| 222 return new _Float32Array(length); |
| 223 } |
| 224 |
| 225 factory Float32List.view(ByteArray array, [int start, int length]) { |
| 226 return new _Float32ArrayView(array, start, length); |
| 227 } |
| 228 } |
| 229 |
| 230 |
| 231 class _Float64ArrayFactory { |
| 232 factory Float64List(int length) { |
| 233 return new _Float64Array(length); |
| 234 } |
| 235 |
| 236 factory Float64List.view(ByteArray array, [int start, int length]) { |
| 237 return new _Float64ArrayView(array, start, length); |
| 238 } |
| 239 } |
| 240 |
| 241 |
| 242 abstract class _ByteArrayBase { |
| 243 void add(value) { |
| 244 throw const UnsupportedOperationException( |
| 245 "Cannot add to a non-extendable array"); |
| 246 } |
| 247 |
| 248 void addLast(value) { |
| 249 throw const UnsupportedOperationException( |
| 250 "Cannot add to a non-extendable array"); |
| 251 } |
| 252 |
| 253 void addAll(Collection value) { |
| 254 throw const UnsupportedOperationException( |
| 255 "Cannot add to a non-extendable array"); |
| 256 } |
| 257 |
| 258 void clear() { |
| 259 throw const UnsupportedOperationException( |
| 260 "Cannot remove from a non-extendable array"); |
| 261 } |
| 262 |
| 263 void insertRange(int start, int length, [initialValue]) { |
| 264 throw const UnsupportedOperationException( |
| 265 "Cannot add to a non-extendable array"); |
| 266 } |
61 | 267 |
62 int get length() { | 268 int get length() { |
63 return _length(); | 269 return _length(); |
64 } | 270 } |
65 | 271 |
66 bool every(bool f(int element)) { | 272 set length(newLength) { |
67 return Collections.every(this, f); | 273 throw const UnsupportedOperationException( |
68 } | 274 "Cannot resize a non-extendable array"); |
69 | |
70 Collection map(f(int element)) { | |
71 return Collections.map(this, | |
72 new GrowableObjectArray.withCapacity(length), | |
73 f); | |
74 } | |
75 | |
76 Collection filter(bool f(int element)) { | |
77 return Collections.filter(this, new GrowableObjectArray(), f); | |
78 } | |
79 | |
80 void forEach(f(int element)) { | |
81 Collections.forEach(this, f); | |
82 } | |
83 | |
84 bool isEmpty() { | |
85 return this.length === 0; | |
86 } | |
87 | |
88 bool some(bool f(int element)) { | |
89 return Collections.some(this, f); | |
90 } | |
91 | |
92 // List interface | |
93 | |
94 int operator[](int index) { | |
95 return getUint8(index); | |
96 } | |
97 | |
98 void operator[]=(int index, int value) { | |
99 setUint8(index, value); | |
100 } | |
101 | |
102 void set length(int newLength) { | |
103 throw const UnsupportedOperationException("Cannot add to a byte array"); | |
104 } | |
105 | |
106 void add(int element) { | |
107 throw const UnsupportedOperationException("Cannot add to a byte array"); | |
108 } | |
109 | |
110 void addLast(int element) { | |
111 add(element); | |
112 } | |
113 | |
114 void addAll(Collection elements) { | |
115 throw const UnsupportedOperationException("Cannot add to a byte array"); | |
116 } | |
117 | |
118 void sort(int compare(int a, b)) { | |
119 DualPivotQuicksort.sort(this, compare); | |
120 } | |
121 | |
122 int indexOf(int element, [int start = 0]) { | |
123 return Arrays.indexOf(this, element, start, this.length); | |
124 } | |
125 | |
126 int lastIndexOf(int element, [int start = null]) { | |
127 if (start === null) start = length - 1; | |
128 return Arrays.lastIndexOf(this, element, start); | |
129 } | |
130 | |
131 void clear() { | |
132 throw const UnsupportedOperationException("Cannot clear a byte array"); | |
133 } | 275 } |
134 | 276 |
135 int removeLast() { | 277 int removeLast() { |
136 throw const UnsupportedOperationException( | 278 throw const UnsupportedOperationException( |
137 "Cannot remove from a byte array"); | 279 "Cannot remove from a non-extendable array"); |
138 } | 280 } |
139 | 281 |
140 int last() { | 282 void removeRange(int start, int length) { |
141 return this[length - 1]; | 283 throw const UnsupportedOperationException( |
142 } | 284 "Cannot remove from a non-extendable array"); |
143 | 285 } |
144 String toString() { | 286 |
145 return Collections.collectionToString(this); | 287 ByteArray asByteArray([int offsetInBytes = 0, int lengthInBytes]) { |
| 288 if (lengthInBytes === null) { |
| 289 lengthInBytes = this.lengthInBytes(); |
| 290 } |
| 291 return new _ByteArrayView(this, offsetInBytes, lengthInBytes); |
| 292 } |
| 293 |
| 294 int _length() native "ByteArray_getLength"; |
| 295 |
| 296 void _setRange(int startInBytes, int lengthInBytes, |
| 297 _ByteArrayBase from, int startFromInBytes) |
| 298 native "ByteArray_setRange"; |
| 299 |
| 300 int _getInt8(int byteOffset) native "ByteArray_getInt8"; |
| 301 void _setInt8(int byteOffset, int value) native "ByteArray_setInt8"; |
| 302 |
| 303 int _getUint8(int byteOffset) native "ByteArray_getUint8"; |
| 304 void _setUint8(int byteOffset, int value) native "ByteArray_setUint8"; |
| 305 |
| 306 int _getInt16(int byteOffset) native "ByteArray_getInt16"; |
| 307 void _setInt16(int byteOffset, int value) native "ByteArray_setInt16"; |
| 308 |
| 309 int _getUint16(int byteOffset) native "ByteArray_getUint16"; |
| 310 void _setUint16(int byteOffset, int value) native "ByteArray_setUint16"; |
| 311 |
| 312 int _getInt32(int byteOffset) native "ByteArray_getInt32"; |
| 313 void _setInt32(int byteOffset, int value) native "ByteArray_setInt32"; |
| 314 |
| 315 int _getUint32(int byteOffset) native "ByteArray_getUint32"; |
| 316 void _setUint32(int byteOffset, int value) native "ByteArray_setUint32"; |
| 317 |
| 318 int _getInt64(int byteOffset) native "ByteArray_getInt64"; |
| 319 void _setInt64(int byteOffset, int value) native "ByteArray_setInt64"; |
| 320 |
| 321 int _getUint64(int byteOffset) native "ByteArray_getUint64"; |
| 322 void _setUint64(int byteOffset, int value) native "ByteArray_setUint64"; |
| 323 |
| 324 double _getFloat32(int byteOffset) native "ByteArray_getFloat32"; |
| 325 void _setFloat32(int byteOffset, double value) native "ByteArray_setFloat32"; |
| 326 |
| 327 double _getFloat64(int byteOffset) native "ByteArray_getFloat64"; |
| 328 void _setFloat64(int byteOffset, double value) native "ByteArray_setFloat64"; |
| 329 } |
| 330 |
| 331 |
| 332 int _toInt(int value, int mask) { |
| 333 value &= mask; |
| 334 if (value > (mask >> 1)) value -= mask + 1; |
| 335 return value; |
| 336 } |
| 337 |
| 338 int _toInt8(int value) { |
| 339 return _toInt(value, 0xFF); |
| 340 } |
| 341 int _toUint8(int value) { |
| 342 return value & 0xFF; |
| 343 } |
| 344 |
| 345 |
| 346 int _toInt16(int value) { |
| 347 return _toInt(value, 0xFFFF); |
| 348 } |
| 349 int _toUint16(int value) { |
| 350 return value & 0xFFFF; |
| 351 } |
| 352 |
| 353 |
| 354 int _toInt32(int value) { |
| 355 return _toInt(value, 0xFFFFFFFF); |
| 356 } |
| 357 int _toUint32(int value) { |
| 358 return value & 0xFFFFFFFF; |
| 359 } |
| 360 |
| 361 |
| 362 int _toInt64(int value) { |
| 363 return _toInt(value, 0xFFFFFFFFFFFFFFFF); |
| 364 } |
| 365 int _toUint64(int value) { |
| 366 return value & 0xFFFFFFFFFFFFFFFF; |
| 367 } |
| 368 |
| 369 |
| 370 void _rangeCheck(List a, int start, int length) { |
| 371 if (length < 0) { |
| 372 throw new IllegalArgumentException("negative length $length"); |
| 373 } |
| 374 if (start < 0) { |
| 375 throw new IndexOutOfRangeException("negative start $start"); |
| 376 } |
| 377 if (start + length > a.length) { |
| 378 throw new IndexOutOfRangeException(start + length); |
| 379 } |
| 380 } |
| 381 |
| 382 |
| 383 class _Int8Array extends _ByteArrayBase implements Int8List { |
| 384 factory _Int8Array(int length) { |
| 385 return _new(length); |
| 386 } |
| 387 |
| 388 factory _Int8Array.view(ByteArray array, [int start = 0, int length]) { |
| 389 if (length === null) { |
| 390 length = array.lengthInBytes(); |
| 391 } |
| 392 return new _Int8ArrayView(array, start, length); |
| 393 } |
| 394 |
| 395 int operator[](int index) { |
| 396 return _getIndexed(index); |
| 397 } |
| 398 |
| 399 void operator[]=(int index, int value) { |
| 400 _setIndexed(index, _toInt8(value)); |
| 401 } |
| 402 |
| 403 Iterator<int> iterator() { |
| 404 return new _ByteArrayIterator<int>(this); |
| 405 } |
| 406 |
| 407 List<int> getRange(int start, int length) { |
| 408 _rangeCheck(this, start, length); |
| 409 List<int> result = _new(length); |
| 410 result.setRange(0, length, this, start); |
| 411 return result; |
146 } | 412 } |
147 | 413 |
148 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | 414 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
149 if (length < 0) { | 415 if (from is _Int8Array) { |
150 throw new IllegalArgumentException("negative length $length"); | 416 int startInBytes = start * _BYTES_PER_ELEMENT; |
151 } | 417 int lengthInBytes = length * _BYTES_PER_ELEMENT; |
152 if (from is ByteArray) { | 418 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; |
153 _setRange(start, length, from, startFrom); | 419 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); |
154 } else { | 420 } else { |
155 Arrays.copy(from, startFrom, this, start, length); | 421 Arrays.copy(from, startFrom, this, start, length); |
156 } | 422 } |
157 } | 423 } |
158 | 424 |
159 List getRange(int start, int length) { | 425 String toString() { |
160 if (length == 0) return []; | 426 return Collections.collectionToString(this); |
161 Arrays.rangeCheck(this, start, length); | 427 } |
162 ByteArray list = new ByteArray(length); | 428 |
163 list._setRange(0, length, this, start); | 429 int bytesPerElement() { |
164 return list; | 430 return _BYTES_PER_ELEMENT; |
165 } | 431 } |
166 | 432 |
167 // Implementation | 433 int lengthInBytes() { |
168 | 434 return _length() * _BYTES_PER_ELEMENT; |
169 static final int _UINT8_MAX = (1 << 8) - 1; | 435 } |
170 static final int _UINT16_MAX = (1 << 16) - 1; | 436 |
171 static final int _UINT32_MAX = (1 << 32) - 1; | 437 static final int _BYTES_PER_ELEMENT = 1; |
172 static final int _UINT64_MAX = (1 << 64) - 1; | 438 |
173 | 439 static _Int8Array _new(int length) native "Int8Array_new"; |
174 int _toInt(int value, int mask) { | 440 |
175 int result = value & mask; | 441 int _getIndexed(int index) native "Int8Array_getIndexed"; |
176 return result > (mask >> 1) ? (result - mask) : result; | 442 void _setIndexed(int index, int value) native "Int8Array_setIndexed"; |
177 } | 443 } |
178 | 444 |
179 int _toInt8(int value) { | 445 |
180 return _toInt(value, _UINT8_MAX); | 446 class _Uint8Array extends _ByteArrayBase implements Uint8List { |
181 } | 447 factory _Uint8Array(int length) { |
182 | 448 return _new(length); |
183 int _toUint8(int value) { | 449 } |
184 return value & _UINT8_MAX; | 450 |
185 } | 451 factory _Uint8Array.view(ByteArray array, [int start = 0, int length]) { |
186 | 452 if (length === null) { |
187 int _toInt16(int value) { | 453 length = array.lengthInBytes(); |
188 return _toInt(value, _UINT16_MAX); | 454 } |
189 } | 455 return new _Uint8ArrayView(array, start, length); |
190 | 456 } |
191 int _toUint16(int value) { | 457 |
192 return value & _UINT16_MAX; | 458 int operator[](int index) { |
193 } | 459 return _getIndexed(index); |
194 | 460 } |
195 int _toInt32(int value) { | 461 |
196 return _toInt(value, _UINT32_MAX); | 462 void operator[]=(int index, int value) { |
197 } | 463 _setIndexed(index, _toUint8(value)); |
198 | 464 } |
199 int _toUint32(int value) { | 465 |
200 return value & _UINT32_MAX; | 466 Iterator<int> iterator() { |
201 } | 467 return new _ByteArrayIterator<int>(this); |
202 | 468 } |
203 int _toInt64(int value) { | 469 |
204 return _toInt(value, _UINT64_MAX); | 470 List<int> getRange(int start, int length) { |
205 } | 471 _rangeCheck(this, start, length); |
206 | 472 List<int> result = _new(length); |
207 int _toUint64(int value) { | 473 result.setRange(0, length, this, start); |
208 return value & _UINT64_MAX; | 474 return result; |
209 } | 475 } |
210 | 476 |
211 int _length() native "ByteArray_getLength"; | 477 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
212 | 478 if (from is _Uint8Array) { |
213 void _setRange(int start, int length, ByteArray from, int startFrom) | 479 int startInBytes = start * _BYTES_PER_ELEMENT; |
214 native "ByteArray_setRange"; | 480 int lengthInBytes = length * _BYTES_PER_ELEMENT; |
215 } | 481 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; |
216 | 482 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); |
217 | 483 } else { |
218 class _ByteArrayIterator implements Iterator { | 484 Arrays.copy(from, startFrom, this, start, length); |
219 _ByteArrayIterator(List byteArray) | 485 } |
220 : _byteArray = byteArray, _length = byteArray.length, _pos = 0 { | 486 } |
221 assert(byteArray is ByteArray); | 487 |
222 } | 488 String toString() { |
| 489 return Collections.collectionToString(this); |
| 490 } |
| 491 |
| 492 int bytesPerElement() { |
| 493 return _BYTES_PER_ELEMENT; |
| 494 } |
| 495 |
| 496 int lengthInBytes() { |
| 497 return _length() * _BYTES_PER_ELEMENT; |
| 498 } |
| 499 |
| 500 static final int _BYTES_PER_ELEMENT = 1; |
| 501 |
| 502 static _Uint8Array _new(int length) native "Uint8Array_new"; |
| 503 |
| 504 int _getIndexed(int index) native "Uint8Array_getIndexed"; |
| 505 void _setIndexed(int index, int value) native "Uint8Array_setIndexed"; |
| 506 } |
| 507 |
| 508 |
| 509 class _Int16Array extends _ByteArrayBase implements Int16List { |
| 510 factory _Int16Array(int length) { |
| 511 return _new(length); |
| 512 } |
| 513 |
| 514 factory _Int16Array.view(ByteArray array, [int start = 0, int length]) { |
| 515 if (length === null) { |
| 516 length = (array.lengthInBytes() - start) ~/ _BYTES_PER_ELEMENT; |
| 517 } |
| 518 return new _Int16ArrayView(array, start, length); |
| 519 } |
| 520 |
| 521 int operator[](int index) { |
| 522 return _getIndexed(index); |
| 523 } |
| 524 |
| 525 void operator[]=(int index, int value) { |
| 526 _setIndexed(index, _toInt16(value)); |
| 527 } |
| 528 |
| 529 Iterator<int> iterator() { |
| 530 return new _ByteArrayIterator<int>(this); |
| 531 } |
| 532 |
| 533 List<int> getRange(int start, int length) { |
| 534 _rangeCheck(this, start, length); |
| 535 List<int> result = _new(length); |
| 536 result.setRange(0, length, this, start); |
| 537 return result; |
| 538 } |
| 539 |
| 540 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
| 541 if (from is _Int16Array) { |
| 542 int startInBytes = start * _BYTES_PER_ELEMENT; |
| 543 int lengthInBytes = length * _BYTES_PER_ELEMENT; |
| 544 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; |
| 545 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); |
| 546 } else { |
| 547 Arrays.copy(from, startFrom, this, start, length); |
| 548 } |
| 549 } |
| 550 |
| 551 String toString() { |
| 552 return Collections.collectionToString(this); |
| 553 } |
| 554 |
| 555 int bytesPerElement() { |
| 556 return _BYTES_PER_ELEMENT; |
| 557 } |
| 558 |
| 559 int lengthInBytes() { |
| 560 return _length() * _BYTES_PER_ELEMENT; |
| 561 } |
| 562 |
| 563 static final int _BYTES_PER_ELEMENT = 2; |
| 564 |
| 565 static _Int16Array _new(int length) native "Int16Array_new"; |
| 566 |
| 567 int _getIndexed(int index) native "Int16Array_getIndexed"; |
| 568 void _setIndexed(int index, int value) native "Int16Array_setIndexed"; |
| 569 } |
| 570 |
| 571 |
| 572 class _Uint16Array extends _ByteArrayBase implements Uint16List { |
| 573 factory _Uint16Array(int length) { |
| 574 return _new(length); |
| 575 } |
| 576 |
| 577 factory _Uint16Array.view(ByteArray array, [int start = 0, int length]) { |
| 578 if (length === null) { |
| 579 length = (array.lengthInBytes() - start) ~/ _BYTES_PER_ELEMENT; |
| 580 } |
| 581 return new _Uint16ArrayView(array, start, length); |
| 582 } |
| 583 |
| 584 int operator[](int index) { |
| 585 return _getIndexed(index); |
| 586 } |
| 587 |
| 588 void operator[]=(int index, int value) { |
| 589 _setIndexed(index, _toUint16(value)); |
| 590 } |
| 591 |
| 592 Iterator<int> iterator() { |
| 593 return new _ByteArrayIterator<int>(this); |
| 594 } |
| 595 |
| 596 List<int> getRange(int start, int length) { |
| 597 _rangeCheck(this, start, length); |
| 598 List<int> result = _new(length); |
| 599 result.setRange(0, length, this, start); |
| 600 return result; |
| 601 } |
| 602 |
| 603 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
| 604 if (from is _Uint16Array) { |
| 605 int startInBytes = start * _BYTES_PER_ELEMENT; |
| 606 int lengthInBytes = length * _BYTES_PER_ELEMENT; |
| 607 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; |
| 608 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); |
| 609 } else { |
| 610 Arrays.copy(from, startFrom, this, start, length); |
| 611 } |
| 612 } |
| 613 |
| 614 String toString() { |
| 615 return Collections.collectionToString(this); |
| 616 } |
| 617 |
| 618 int bytesPerElement() { |
| 619 return _BYTES_PER_ELEMENT; |
| 620 } |
| 621 |
| 622 int lengthInBytes() { |
| 623 return _length() * _BYTES_PER_ELEMENT; |
| 624 } |
| 625 |
| 626 static final int _BYTES_PER_ELEMENT = 2; |
| 627 |
| 628 static _Uint16Array _new(int length) native "Uint16Array_new"; |
| 629 |
| 630 int _getIndexed(int index) native "Uint16Array_getIndexed"; |
| 631 void _setIndexed(int index, int value) native "Uint16Array_setIndexed"; |
| 632 } |
| 633 |
| 634 |
| 635 class _Int32Array extends _ByteArrayBase implements Int32List { |
| 636 factory _Int32Array(int length) { |
| 637 return _new(length); |
| 638 } |
| 639 |
| 640 factory _Int32Array.view(ByteArray array, [int start = 0, int length]) { |
| 641 if (length === null) { |
| 642 length = (array.lengthInBytes() - start) ~/ _BYTES_PER_ELEMENT; |
| 643 } |
| 644 return new _Int32ArrayView(array, start, length); |
| 645 } |
| 646 |
| 647 int operator[](int index) { |
| 648 return _getIndexed(index); |
| 649 } |
| 650 |
| 651 void operator[]=(int index, int value) { |
| 652 _setIndexed(index, _toInt32(value)); |
| 653 } |
| 654 |
| 655 Iterator<int> iterator() { |
| 656 return new _ByteArrayIterator<int>(this); |
| 657 } |
| 658 |
| 659 List<int> getRange(int start, int length) { |
| 660 _rangeCheck(this, start, length); |
| 661 List<int> result = _new(length); |
| 662 result.setRange(0, length, this, start); |
| 663 return result; |
| 664 } |
| 665 |
| 666 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
| 667 if (from is _Int32Array) { |
| 668 int startInBytes = start * _BYTES_PER_ELEMENT; |
| 669 int lengthInBytes = length * _BYTES_PER_ELEMENT; |
| 670 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; |
| 671 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); |
| 672 } else { |
| 673 Arrays.copy(from, startFrom, this, start, length); |
| 674 } |
| 675 } |
| 676 |
| 677 String toString() { |
| 678 return Collections.collectionToString(this); |
| 679 } |
| 680 |
| 681 int bytesPerElement() { |
| 682 return _BYTES_PER_ELEMENT; |
| 683 } |
| 684 |
| 685 int lengthInBytes() { |
| 686 return _length() * _BYTES_PER_ELEMENT; |
| 687 } |
| 688 |
| 689 static final int _BYTES_PER_ELEMENT = 4; |
| 690 |
| 691 static _Int32Array _new(int length) native "Int32Array_new"; |
| 692 |
| 693 int _getIndexed(int index) native "Int32Array_getIndexed"; |
| 694 void _setIndexed(int index, int value) native "Int32Array_setIndexed"; |
| 695 } |
| 696 |
| 697 |
| 698 class _Uint32Array extends _ByteArrayBase implements Uint32List { |
| 699 factory _Uint32Array(int length) { |
| 700 return _new(length); |
| 701 } |
| 702 |
| 703 factory _Uint32Array.view(ByteArray array, [int start = 0, int length]) { |
| 704 if (length === null) { |
| 705 length = (array.lengthInBytes() - start) ~/ _BYTES_PER_ELEMENT; |
| 706 } |
| 707 return new _Uint32ArrayView(array, start, length); |
| 708 } |
| 709 |
| 710 int operator[](int index) { |
| 711 return _getIndexed(index); |
| 712 } |
| 713 |
| 714 void operator[]=(int index, int value) { |
| 715 _setIndexed(index, _toUint32(value)); |
| 716 } |
| 717 |
| 718 Iterator<int> iterator() { |
| 719 return new _ByteArrayIterator<int>(this); |
| 720 } |
| 721 |
| 722 List<int> getRange(int start, int length) { |
| 723 _rangeCheck(this, start, length); |
| 724 List<int> result = _new(length); |
| 725 result.setRange(0, length, this, start); |
| 726 return result; |
| 727 } |
| 728 |
| 729 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
| 730 if (from is _Uint32Array) { |
| 731 int startInBytes = start * _BYTES_PER_ELEMENT; |
| 732 int lengthInBytes = length * _BYTES_PER_ELEMENT; |
| 733 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; |
| 734 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); |
| 735 } else { |
| 736 Arrays.copy(from, startFrom, this, start, length); |
| 737 } |
| 738 } |
| 739 |
| 740 String toString() { |
| 741 return Collections.collectionToString(this); |
| 742 } |
| 743 |
| 744 int bytesPerElement() { |
| 745 return _BYTES_PER_ELEMENT; |
| 746 } |
| 747 |
| 748 int lengthInBytes() { |
| 749 return _length() * _BYTES_PER_ELEMENT; |
| 750 } |
| 751 |
| 752 static final int _BYTES_PER_ELEMENT = 4; |
| 753 |
| 754 static _Uint32Array _new(int length) native "Uint32Array_new"; |
| 755 |
| 756 int _getIndexed(int index) native "Uint32Array_getIndexed"; |
| 757 void _setIndexed(int index, int value) native "Uint32Array_setIndexed"; |
| 758 } |
| 759 |
| 760 |
| 761 class _Int64Array extends _ByteArrayBase implements Int64List { |
| 762 factory _Int64Array(int length) { |
| 763 return _new(length); |
| 764 } |
| 765 |
| 766 factory _Int64Array.view(ByteArray array, [int start = 0, int length]) { |
| 767 if (length === null) { |
| 768 length = (array.lengthInBytes() - start) ~/ _BYTES_PER_ELEMENT; |
| 769 } |
| 770 return new _Int64ArrayView(array, start, length); |
| 771 } |
| 772 |
| 773 int operator[](int index) { |
| 774 return _getIndexed(index); |
| 775 } |
| 776 |
| 777 void operator[]=(int index, int value) { |
| 778 _setIndexed(index, _toInt64(value)); |
| 779 } |
| 780 |
| 781 Iterator<int> iterator() { |
| 782 return new _ByteArrayIterator<int>(this); |
| 783 } |
| 784 |
| 785 List<int> getRange(int start, int length) { |
| 786 _rangeCheck(this, start, length); |
| 787 List<int> result = _new(length); |
| 788 result.setRange(0, length, this, start); |
| 789 return result; |
| 790 } |
| 791 |
| 792 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
| 793 if (from is _Int64Array) { |
| 794 int startInBytes = start * _BYTES_PER_ELEMENT; |
| 795 int lengthInBytes = length * _BYTES_PER_ELEMENT; |
| 796 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; |
| 797 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); |
| 798 } else { |
| 799 Arrays.copy(from, startFrom, this, start, length); |
| 800 } |
| 801 } |
| 802 |
| 803 String toString() { |
| 804 return Collections.collectionToString(this); |
| 805 } |
| 806 |
| 807 int bytesPerElement() { |
| 808 return _BYTES_PER_ELEMENT; |
| 809 } |
| 810 |
| 811 int lengthInBytes() { |
| 812 return _length() * _BYTES_PER_ELEMENT; |
| 813 } |
| 814 |
| 815 static final int _BYTES_PER_ELEMENT = 8; |
| 816 |
| 817 static _Int64Array _new(int length) native "Int64Array_new"; |
| 818 |
| 819 int _getIndexed(int index) native "Int64Array_getIndexed"; |
| 820 void _setIndexed(int index, int value) native "Int64Array_setIndexed"; |
| 821 } |
| 822 |
| 823 |
| 824 class _Uint64Array extends _ByteArrayBase implements Uint64List { |
| 825 factory _Uint64Array(int length) { |
| 826 return _new(length); |
| 827 } |
| 828 |
| 829 factory _Uint64Array.view(ByteArray array, [int start = 0, int length]) { |
| 830 if (length === null) { |
| 831 length = (array.lengthInBytes() - start) ~/ _BYTES_PER_ELEMENT; |
| 832 } |
| 833 return new _Uint64ArrayView(array, start, length); |
| 834 } |
| 835 |
| 836 int operator[](int index) { |
| 837 return _getIndexed(index); |
| 838 } |
| 839 |
| 840 void operator[]=(int index, int value) { |
| 841 _setIndexed(index, _toUint64(value)); |
| 842 } |
| 843 |
| 844 Iterator<int> iterator() { |
| 845 return new _ByteArrayIterator<int>(this); |
| 846 } |
| 847 |
| 848 List<int> getRange(int start, int length) { |
| 849 _rangeCheck(this, start, length); |
| 850 List<int> result = _new(length); |
| 851 result.setRange(0, length, this, start); |
| 852 return result; |
| 853 } |
| 854 |
| 855 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
| 856 if (from is _Uint64Array) { |
| 857 int startInBytes = start * _BYTES_PER_ELEMENT; |
| 858 int lengthInBytes = length * _BYTES_PER_ELEMENT; |
| 859 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; |
| 860 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); |
| 861 } else { |
| 862 Arrays.copy(from, startFrom, this, start, length); |
| 863 } |
| 864 } |
| 865 |
| 866 String toString() { |
| 867 return Collections.collectionToString(this); |
| 868 } |
| 869 |
| 870 int bytesPerElement() { |
| 871 return _BYTES_PER_ELEMENT; |
| 872 } |
| 873 |
| 874 int lengthInBytes() { |
| 875 return _length() * _BYTES_PER_ELEMENT; |
| 876 } |
| 877 |
| 878 static final int _BYTES_PER_ELEMENT = 8; |
| 879 |
| 880 static _Uint64Array _new(int length) native "Uint64Array_new"; |
| 881 |
| 882 int _getIndexed(int index) native "Uint64Array_getIndexed"; |
| 883 void _setIndexed(int index, int value) native "Uint64Array_setIndexed"; |
| 884 } |
| 885 |
| 886 |
| 887 class _Float32Array extends _ByteArrayBase implements Float32List { |
| 888 factory _Float32Array(int length) { |
| 889 return _new(length); |
| 890 } |
| 891 |
| 892 factory _Float32Array.view(ByteArray array, [int start = 0, int length]) { |
| 893 if (length === null) { |
| 894 length = (array.lengthInBytes() - start) ~/ _BYTES_PER_ELEMENT; |
| 895 } |
| 896 return new _Float32ArrayView(array, start, length); |
| 897 } |
| 898 |
| 899 double operator[](int index) { |
| 900 return _getIndexed(index); |
| 901 } |
| 902 |
| 903 void operator[]=(int index, double value) { |
| 904 _setIndexed(index, value); |
| 905 } |
| 906 |
| 907 Iterator<double> iterator() { |
| 908 return new _ByteArrayIterator<double>(this); |
| 909 } |
| 910 |
| 911 List<double> getRange(int start, int length) { |
| 912 _rangeCheck(this, start, length); |
| 913 List<double> result = _new(length); |
| 914 result.setRange(0, length, this, start); |
| 915 return result; |
| 916 } |
| 917 |
| 918 void setRange(int start, int length, List<double> from, [int startFrom = 0]) { |
| 919 if (from is _Float32Array) { |
| 920 int startInBytes = start * _BYTES_PER_ELEMENT; |
| 921 int lengthInBytes = length * _BYTES_PER_ELEMENT; |
| 922 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; |
| 923 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); |
| 924 } else { |
| 925 Arrays.copy(from, startFrom, this, start, length); |
| 926 } |
| 927 } |
| 928 |
| 929 String toString() { |
| 930 return Collections.collectionToString(this); |
| 931 } |
| 932 |
| 933 int bytesPerElement() { |
| 934 return _BYTES_PER_ELEMENT; |
| 935 } |
| 936 |
| 937 int lengthInBytes() { |
| 938 return _length() * _BYTES_PER_ELEMENT; |
| 939 } |
| 940 |
| 941 static final int _BYTES_PER_ELEMENT = 4; |
| 942 |
| 943 static _Float32Array _new(int length) native "Float32Array_new"; |
| 944 |
| 945 double _getIndexed(int index) native "Float32Array_getIndexed"; |
| 946 void _setIndexed(int index, double value) native "Float32Array_setIndexed"; |
| 947 } |
| 948 |
| 949 |
| 950 class _Float64Array extends _ByteArrayBase implements Float64List { |
| 951 factory _Float64Array(int length) { |
| 952 return _new(length); |
| 953 } |
| 954 |
| 955 factory _Float64Array.view(ByteArray array, [int start = 0, int length]) { |
| 956 if (length === null) { |
| 957 length = (array.lengthInBytes() - start) ~/ _BYTES_PER_ELEMENT; |
| 958 } |
| 959 return new _Float64ArrayView(array, start, length); |
| 960 } |
| 961 |
| 962 double operator[](int index) { |
| 963 return _getIndexed(index); |
| 964 } |
| 965 |
| 966 void operator[]=(int index, double value) { |
| 967 _setIndexed(index, value); |
| 968 } |
| 969 |
| 970 Iterator<double> iterator() { |
| 971 return new _ByteArrayIterator<double>(this); |
| 972 } |
| 973 |
| 974 List<double> getRange(int start, int length) { |
| 975 _rangeCheck(this, start, length); |
| 976 List<double> result = _new(length); |
| 977 result.setRange(0, length, this, start); |
| 978 return result; |
| 979 } |
| 980 |
| 981 void setRange(int start, int length, List<double> from, [int startFrom = 0]) { |
| 982 if (from is _Float64Array) { |
| 983 int startInBytes = start * _BYTES_PER_ELEMENT; |
| 984 int lengthInBytes = length * _BYTES_PER_ELEMENT; |
| 985 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; |
| 986 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); |
| 987 } else { |
| 988 Arrays.copy(from, startFrom, this, start, length); |
| 989 } |
| 990 } |
| 991 |
| 992 String toString() { |
| 993 return Collections.collectionToString(this); |
| 994 } |
| 995 |
| 996 int bytesPerElement() { |
| 997 return _BYTES_PER_ELEMENT; |
| 998 } |
| 999 |
| 1000 int lengthInBytes() { |
| 1001 return _length() * _BYTES_PER_ELEMENT; |
| 1002 } |
| 1003 |
| 1004 static final int _BYTES_PER_ELEMENT = 8; |
| 1005 |
| 1006 static _Float64Array _new(int length) native "Float64Array_new"; |
| 1007 |
| 1008 double _getIndexed(int index) native "Float64Array_getIndexed"; |
| 1009 void _setIndexed(int index, double value) native "Float64Array_setIndexed"; |
| 1010 } |
| 1011 |
| 1012 |
| 1013 class _ExternalInt8Array extends _ByteArrayBase implements Int8List { |
| 1014 int operator[](int index) { |
| 1015 return _getIndexed(index); |
| 1016 } |
| 1017 |
| 1018 int operator[]=(int index, int value) { |
| 1019 _setIndexed(index, _toInt8(value)); |
| 1020 } |
| 1021 |
| 1022 Iterator<int> iterator() { |
| 1023 return new _ByteArrayIterator<int>(this); |
| 1024 } |
| 1025 |
| 1026 List<int> getRange(int start, int length) { |
| 1027 _rangeCheck(this, start, length); |
| 1028 List<int> result = new Int8List(length); |
| 1029 result.setRange(0, length, this, start); |
| 1030 return result; |
| 1031 } |
| 1032 |
| 1033 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
| 1034 if (from is _ExternalInt8Array) { |
| 1035 int startInBytes = start * _BYTES_PER_ELEMENT; |
| 1036 int lengthInBytes = length * _BYTES_PER_ELEMENT; |
| 1037 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; |
| 1038 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); |
| 1039 } else { |
| 1040 Arrays.copy(from, startFrom, this, start, length); |
| 1041 } |
| 1042 } |
| 1043 |
| 1044 String toString() { |
| 1045 return Collections.collectionToString(this); |
| 1046 } |
| 1047 |
| 1048 int bytesPerElement() { |
| 1049 return _BYTES_PER_ELEMENT; |
| 1050 } |
| 1051 |
| 1052 int lengthInBytes() { |
| 1053 return _length() * _BYTES_PER_ELEMENT; |
| 1054 } |
| 1055 |
| 1056 static final int _BYTES_PER_ELEMENT = 1; |
| 1057 |
| 1058 int _getIndexed(int index) native "ExternalInt8Array_getIndexed"; |
| 1059 void _setIndexed(int index, int value) native "ExternalInt8Array_setIndexed"; |
| 1060 } |
| 1061 |
| 1062 |
| 1063 class _ExternalUint8Array extends _ByteArrayBase implements Uint8List { |
| 1064 int operator[](int index) { |
| 1065 return _getIndexed(index); |
| 1066 } |
| 1067 |
| 1068 int operator[]=(int index, int value) { |
| 1069 _setIndexed(index, _toUint8(value)); |
| 1070 } |
| 1071 |
| 1072 Iterator<int> iterator() { |
| 1073 return new _ByteArrayIterator<int>(this); |
| 1074 } |
| 1075 |
| 1076 List<int> getRange(int start, int length) { |
| 1077 _rangeCheck(this, start, length); |
| 1078 List<int> result = new Uint8List(length); |
| 1079 result.setRange(0, length, this, start); |
| 1080 return result; |
| 1081 } |
| 1082 |
| 1083 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
| 1084 if (from is _ExternalUint8Array) { |
| 1085 int startInBytes = start * _BYTES_PER_ELEMENT; |
| 1086 int lengthInBytes = length * _BYTES_PER_ELEMENT; |
| 1087 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; |
| 1088 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); |
| 1089 } else { |
| 1090 Arrays.copy(from, startFrom, this, start, length); |
| 1091 } |
| 1092 } |
| 1093 |
| 1094 String toString() { |
| 1095 return Collections.collectionToString(this); |
| 1096 } |
| 1097 |
| 1098 int bytesPerElement() { |
| 1099 return _BYTES_PER_ELEMENT; |
| 1100 } |
| 1101 |
| 1102 int lengthInBytes() { |
| 1103 return _length() * _BYTES_PER_ELEMENT; |
| 1104 } |
| 1105 |
| 1106 static final int _BYTES_PER_ELEMENT = 1; |
| 1107 |
| 1108 int _getIndexed(int index) native "ExternalUint8Array_getIndexed"; |
| 1109 void _setIndexed(int index, int value) native "ExternalUint8Array_setIndexed"; |
| 1110 } |
| 1111 |
| 1112 |
| 1113 class _ExternalInt16Array extends _ByteArrayBase implements Int16List { |
| 1114 int operator[](int index) { |
| 1115 return _getIndexed(index); |
| 1116 } |
| 1117 |
| 1118 int operator[]=(int index, int value) { |
| 1119 _setIndexed(index, _toInt16(value)); |
| 1120 } |
| 1121 |
| 1122 Iterator<int> iterator() { |
| 1123 return new _ByteArrayIterator<int>(this); |
| 1124 } |
| 1125 |
| 1126 List<int> getRange(int start, int length) { |
| 1127 _rangeCheck(this, start, length); |
| 1128 List<int> result = new Int16List(length); |
| 1129 result.setRange(0, length, this, start); |
| 1130 return result; |
| 1131 } |
| 1132 |
| 1133 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
| 1134 if (from is _ExternalInt16Array) { |
| 1135 int startInBytes = start * _BYTES_PER_ELEMENT; |
| 1136 int lengthInBytes = length * _BYTES_PER_ELEMENT; |
| 1137 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; |
| 1138 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); |
| 1139 } else { |
| 1140 Arrays.copy(from, startFrom, this, start, length); |
| 1141 } |
| 1142 } |
| 1143 |
| 1144 String toString() { |
| 1145 return Collections.collectionToString(this); |
| 1146 } |
| 1147 |
| 1148 int bytesPerElement() { |
| 1149 return _BYTES_PER_ELEMENT; |
| 1150 } |
| 1151 |
| 1152 int lengthInBytes() { |
| 1153 return _length() * _BYTES_PER_ELEMENT; |
| 1154 } |
| 1155 |
| 1156 static final int _BYTES_PER_ELEMENT = 2; |
| 1157 |
| 1158 int _getIndexed(int index) native "ExternalInt16Array_getIndexed"; |
| 1159 void _setIndexed(int index, int value) native "ExternalInt16Array_setIndexed"; |
| 1160 } |
| 1161 |
| 1162 |
| 1163 class _ExternalUint16Array extends _ByteArrayBase implements Uint16List { |
| 1164 int operator[](int index) { |
| 1165 return _getIndexed(index); |
| 1166 } |
| 1167 |
| 1168 int operator[]=(int index, int value) { |
| 1169 _setIndexed(index, _toUint16(value)); |
| 1170 } |
| 1171 |
| 1172 Iterator<int> iterator() { |
| 1173 return new _ByteArrayIterator<int>(this); |
| 1174 } |
| 1175 |
| 1176 List<int> getRange(int start, int length) { |
| 1177 _rangeCheck(this, start, length); |
| 1178 List<int> result = new Uint16List(length); |
| 1179 result.setRange(0, length, this, start); |
| 1180 return result; |
| 1181 } |
| 1182 |
| 1183 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
| 1184 if (from is _ExternalUint16Array) { |
| 1185 int startInBytes = start * _BYTES_PER_ELEMENT; |
| 1186 int lengthInBytes = length * _BYTES_PER_ELEMENT; |
| 1187 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; |
| 1188 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); |
| 1189 } else { |
| 1190 Arrays.copy(from, startFrom, this, start, length); |
| 1191 } |
| 1192 } |
| 1193 |
| 1194 String toString() { |
| 1195 return Collections.collectionToString(this); |
| 1196 } |
| 1197 |
| 1198 int bytesPerElement() { |
| 1199 return _BYTES_PER_ELEMENT; |
| 1200 } |
| 1201 |
| 1202 int lengthInBytes() { |
| 1203 return _length() * _BYTES_PER_ELEMENT; |
| 1204 } |
| 1205 |
| 1206 static final int _BYTES_PER_ELEMENT = 2; |
| 1207 |
| 1208 int _getIndexed(int index) |
| 1209 native "ExternalUint16Array_getIndexed"; |
| 1210 void _setIndexed(int index, int value) |
| 1211 native "ExternalUint16Array_setIndexed"; |
| 1212 } |
| 1213 |
| 1214 |
| 1215 class _ExternalInt32Array extends _ByteArrayBase implements Int32List { |
| 1216 int operator[](int index) { |
| 1217 return _getIndexed(index); |
| 1218 } |
| 1219 |
| 1220 int operator[]=(int index, int value) { |
| 1221 _setIndexed(index, _toInt32(value)); |
| 1222 } |
| 1223 |
| 1224 Iterator<int> iterator() { |
| 1225 return new _ByteArrayIterator<int>(this); |
| 1226 } |
| 1227 |
| 1228 List<int> getRange(int start, int length) { |
| 1229 _rangeCheck(this, start, length); |
| 1230 List<int> result = new Int32List(length); |
| 1231 result.setRange(0, length, this, start); |
| 1232 return result; |
| 1233 } |
| 1234 |
| 1235 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
| 1236 if (from is _ExternalInt32Array) { |
| 1237 int startInBytes = start * _BYTES_PER_ELEMENT; |
| 1238 int lengthInBytes = length * _BYTES_PER_ELEMENT; |
| 1239 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; |
| 1240 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); |
| 1241 } else { |
| 1242 Arrays.copy(from, startFrom, this, start, length); |
| 1243 } |
| 1244 } |
| 1245 |
| 1246 String toString() { |
| 1247 return Collections.collectionToString(this); |
| 1248 } |
| 1249 |
| 1250 int bytesPerElement() { |
| 1251 return _BYTES_PER_ELEMENT; |
| 1252 } |
| 1253 |
| 1254 int lengthInBytes() { |
| 1255 return _length() * _BYTES_PER_ELEMENT; |
| 1256 } |
| 1257 |
| 1258 static final int _BYTES_PER_ELEMENT = 4; |
| 1259 |
| 1260 int _getIndexed(int index) |
| 1261 native "ExternalInt32Array_getIndexed"; |
| 1262 void _setIndexed(int index, int value) |
| 1263 native "ExternalInt32Array_setIndexed"; |
| 1264 } |
| 1265 |
| 1266 |
| 1267 class _ExternalUint32Array extends _ByteArrayBase implements Uint32List { |
| 1268 int operator[](int index) { |
| 1269 return _getIndexed(index); |
| 1270 } |
| 1271 |
| 1272 int operator[]=(int index, int value) { |
| 1273 _setIndexed(index, _toUint32(value)); |
| 1274 } |
| 1275 |
| 1276 Iterator<int> iterator() { |
| 1277 return new _ByteArrayIterator<int>(this); |
| 1278 } |
| 1279 |
| 1280 List<int> getRange(int start, int length) { |
| 1281 _rangeCheck(this, start, length); |
| 1282 List<int> result = new Uint32List(length); |
| 1283 result.setRange(0, length, this, start); |
| 1284 return result; |
| 1285 } |
| 1286 |
| 1287 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
| 1288 if (from is _ExternalUint32Array) { |
| 1289 int startInBytes = start * _BYTES_PER_ELEMENT; |
| 1290 int lengthInBytes = length * _BYTES_PER_ELEMENT; |
| 1291 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; |
| 1292 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); |
| 1293 } else { |
| 1294 Arrays.copy(from, startFrom, this, start, length); |
| 1295 } |
| 1296 } |
| 1297 |
| 1298 String toString() { |
| 1299 return Collections.collectionToString(this); |
| 1300 } |
| 1301 |
| 1302 int bytesPerElement() { |
| 1303 return _BYTES_PER_ELEMENT; |
| 1304 } |
| 1305 |
| 1306 int lengthInBytes() { |
| 1307 return _length() * _BYTES_PER_ELEMENT; |
| 1308 } |
| 1309 |
| 1310 static final int _BYTES_PER_ELEMENT = 4; |
| 1311 |
| 1312 int _getIndexed(int index) |
| 1313 native "ExternalUint32Array_getIndexed"; |
| 1314 void _setIndexed(int index, int value) |
| 1315 native "ExternalUint32Array_setIndexed"; |
| 1316 } |
| 1317 |
| 1318 |
| 1319 class _ExternalInt64Array extends _ByteArrayBase implements Int64List { |
| 1320 int operator[](int index) { |
| 1321 return _getIndexed(index); |
| 1322 } |
| 1323 |
| 1324 int operator[]=(int index, int value) { |
| 1325 _setIndexed(index, _toInt64(value)); |
| 1326 } |
| 1327 |
| 1328 Iterator<int> iterator() { |
| 1329 return new _ByteArrayIterator<int>(this); |
| 1330 } |
| 1331 |
| 1332 List<int> getRange(int start, int length) { |
| 1333 _rangeCheck(this, start, length); |
| 1334 List<int> result = new Int64List(length); |
| 1335 result.setRange(0, length, this, start); |
| 1336 return result; |
| 1337 } |
| 1338 |
| 1339 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
| 1340 if (from is _ExternalInt64Array) { |
| 1341 int startInBytes = start * _BYTES_PER_ELEMENT; |
| 1342 int lengthInBytes = length * _BYTES_PER_ELEMENT; |
| 1343 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; |
| 1344 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); |
| 1345 } else { |
| 1346 Arrays.copy(from, startFrom, this, start, length); |
| 1347 } |
| 1348 } |
| 1349 |
| 1350 String toString() { |
| 1351 return Collections.collectionToString(this); |
| 1352 } |
| 1353 |
| 1354 int bytesPerElement() { |
| 1355 return _BYTES_PER_ELEMENT; |
| 1356 } |
| 1357 |
| 1358 int lengthInBytes() { |
| 1359 return _length() * _BYTES_PER_ELEMENT; |
| 1360 } |
| 1361 |
| 1362 static final int _BYTES_PER_ELEMENT = 8; |
| 1363 |
| 1364 int _getIndexed(int index) |
| 1365 native "ExternalInt64Array_getIndexed"; |
| 1366 void _setIndexed(int index, int value) |
| 1367 native "ExternalInt64Array_setIndexed"; |
| 1368 } |
| 1369 |
| 1370 |
| 1371 class _ExternalUint64Array extends _ByteArrayBase implements Uint64List { |
| 1372 int operator[](int index) { |
| 1373 return _getIndexed(index); |
| 1374 } |
| 1375 |
| 1376 int operator[]=(int index, int value) { |
| 1377 _setIndexed(index, _toUint64(value)); |
| 1378 } |
| 1379 |
| 1380 Iterator<int> iterator() { |
| 1381 return new _ByteArrayIterator<int>(this); |
| 1382 } |
| 1383 |
| 1384 List<int> getRange(int start, int length) { |
| 1385 _rangeCheck(this, start, length); |
| 1386 List<int> result = new Uint64List(length); |
| 1387 result.setRange(0, length, this, start); |
| 1388 return result; |
| 1389 } |
| 1390 |
| 1391 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
| 1392 if (from is _ExternalUint64Array) { |
| 1393 int startInBytes = start * _BYTES_PER_ELEMENT; |
| 1394 int lengthInBytes = length * _BYTES_PER_ELEMENT; |
| 1395 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; |
| 1396 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); |
| 1397 } else { |
| 1398 Arrays.copy(from, startFrom, this, start, length); |
| 1399 } |
| 1400 } |
| 1401 |
| 1402 String toString() { |
| 1403 return Collections.collectionToString(this); |
| 1404 } |
| 1405 |
| 1406 int bytesPerElement() { |
| 1407 return _BYTES_PER_ELEMENT; |
| 1408 } |
| 1409 |
| 1410 int lengthInBytes() { |
| 1411 return _length() * _BYTES_PER_ELEMENT; |
| 1412 } |
| 1413 |
| 1414 static final int _BYTES_PER_ELEMENT = 8; |
| 1415 |
| 1416 int _getIndexed(int index) |
| 1417 native "ExternalUint64Array_getIndexed"; |
| 1418 void _setIndexed(int index, int value) |
| 1419 native "ExternalUint64Array_setIndexed"; |
| 1420 } |
| 1421 |
| 1422 |
| 1423 class _ExternalFloat32Array extends _ByteArrayBase implements Float32List { |
| 1424 int operator[](int index) { |
| 1425 return _getIndexed(index); |
| 1426 } |
| 1427 |
| 1428 int operator[]=(int index, double value) { |
| 1429 _setIndexed(index, value); |
| 1430 } |
| 1431 |
| 1432 Iterator<double> iterator() { |
| 1433 return new _ByteArrayIterator<double>(this); |
| 1434 } |
| 1435 |
| 1436 List<double> getRange(int start, int length) { |
| 1437 _rangeCheck(this, start, length); |
| 1438 List<double> result = new Float32List(length); |
| 1439 result.setRange(0, length, this, start); |
| 1440 return result; |
| 1441 } |
| 1442 |
| 1443 void setRange(int start, int length, List<double> from, [int startFrom = 0]) { |
| 1444 if (from is _ExternalFloat32Array) { |
| 1445 int startInBytes = start * _BYTES_PER_ELEMENT; |
| 1446 int lengthInBytes = length * _BYTES_PER_ELEMENT; |
| 1447 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; |
| 1448 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); |
| 1449 } else { |
| 1450 Arrays.copy(from, startFrom, this, start, length); |
| 1451 } |
| 1452 } |
| 1453 |
| 1454 String toString() { |
| 1455 return Collections.collectionToString(this); |
| 1456 } |
| 1457 |
| 1458 int bytesPerElement() { |
| 1459 return _BYTES_PER_ELEMENT; |
| 1460 } |
| 1461 |
| 1462 int lengthInBytes() { |
| 1463 return _length() * _BYTES_PER_ELEMENT; |
| 1464 } |
| 1465 |
| 1466 static final int _BYTES_PER_ELEMENT = 4; |
| 1467 |
| 1468 double _getIndexed(int index) |
| 1469 native "ExternalFloat32Array_getIndexed"; |
| 1470 void _setIndexed(int index, double value) |
| 1471 native "ExternalFloat32Array_setIndexed"; |
| 1472 } |
| 1473 |
| 1474 |
| 1475 class _ExternalFloat64Array extends _ByteArrayBase implements Float64List { |
| 1476 int operator[](int index) { |
| 1477 return _getIndexed(index); |
| 1478 } |
| 1479 |
| 1480 int operator[]=(int index, double value) { |
| 1481 _setIndexed(index, value); |
| 1482 } |
| 1483 |
| 1484 Iterator<double> iterator() { |
| 1485 return new _ByteArrayIterator<double>(this); |
| 1486 } |
| 1487 |
| 1488 List<double> getRange(int start, int length) { |
| 1489 _rangeCheck(this, start, length); |
| 1490 List<double> result = new Float64List(length); |
| 1491 result.setRange(0, length, this, start); |
| 1492 return result; |
| 1493 } |
| 1494 |
| 1495 void setRange(int start, int length, List<double> from, [int startFrom = 0]) { |
| 1496 if (from is _ExternalFloat64Array) { |
| 1497 int startInBytes = start * _BYTES_PER_ELEMENT; |
| 1498 int lengthInBytes = length * _BYTES_PER_ELEMENT; |
| 1499 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; |
| 1500 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); |
| 1501 } else { |
| 1502 Arrays.copy(from, startFrom, this, start, length); |
| 1503 } |
| 1504 } |
| 1505 |
| 1506 String toString() { |
| 1507 return Collections.collectionToString(this); |
| 1508 } |
| 1509 |
| 1510 int bytesPerElement() { |
| 1511 return _BYTES_PER_ELEMENT; |
| 1512 } |
| 1513 |
| 1514 int lengthInBytes() { |
| 1515 return _length() * _BYTES_PER_ELEMENT; |
| 1516 } |
| 1517 |
| 1518 static final int _BYTES_PER_ELEMENT = 8; |
| 1519 |
| 1520 double _getIndexed(int index) |
| 1521 native "ExternalFloat64Array_getIndexed"; |
| 1522 void _setIndexed(int index, double value) |
| 1523 native "ExternalFloat64Array_setIndexed"; |
| 1524 } |
| 1525 |
| 1526 |
| 1527 class _ByteArrayIterator<E> implements Iterator<E> { |
| 1528 _ByteArrayIterator(_ByteArrayBase array) |
| 1529 : _array = array, _length = array.length, _pos = 0; |
223 | 1530 |
224 bool hasNext() { | 1531 bool hasNext() { |
225 return _length > _pos; | 1532 return _length > _pos; |
226 } | 1533 } |
227 | 1534 |
228 int next() { | 1535 E next() { |
229 if (!hasNext()) { | 1536 if (!hasNext()) { |
230 throw const NoMoreElementsException(); | 1537 throw const NoMoreElementsException(); |
231 } | 1538 } |
232 return _byteArray[_pos++]; | 1539 return _array[_pos++]; |
233 } | 1540 } |
234 | 1541 |
235 final List _byteArray; | 1542 final List<E> _array; |
236 | 1543 |
237 final int _length; | 1544 final int _length; |
238 | 1545 |
239 int _pos; | 1546 int _pos; |
240 } | 1547 } |
241 | 1548 |
242 | 1549 |
243 class _InternalByteArray extends _ByteArrayBase implements ByteArray { | 1550 class _ByteArrayView implements ByteArray { |
244 factory _InternalByteArray(int length) { | 1551 _ByteArrayView(this._array, this._offset, this._length) { |
245 return _allocate(length); | 1552 } |
246 } | 1553 |
247 | 1554 int lengthInBytes() { |
248 // ByteArray interface | 1555 return _length; |
| 1556 } |
| 1557 |
| 1558 ByteArray subByteArray([int start = 0, int length]) { |
| 1559 if (length === null) { |
| 1560 length = this.lengthInBytes(); |
| 1561 } |
| 1562 _rangeCheck(start, length); |
| 1563 return new _ByteArrayView(_array, _offset + start, length); |
| 1564 } |
249 | 1565 |
250 int getInt8(int byteOffset) { | 1566 int getInt8(int byteOffset) { |
251 return _getInt8(byteOffset); | 1567 return _array._getInt8(_offset + byteOffset); |
252 } | 1568 } |
253 | |
254 void setInt8(int byteOffset, int value) { | 1569 void setInt8(int byteOffset, int value) { |
255 _setInt8(byteOffset, _toInt8(value)); | 1570 _array._setInt8(_offset + byteOffset, value); |
256 } | 1571 } |
257 | 1572 |
258 int getUint8(int byteOffset) { | 1573 int getUint8(int byteOffset) { |
259 return _getUint8(byteOffset); | 1574 return _array._getUint8(_offset + byteOffset); |
260 } | 1575 } |
261 | |
262 void setUint8(int byteOffset, int value) { | 1576 void setUint8(int byteOffset, int value) { |
263 _setUint8(byteOffset, _toUint8(value)); | 1577 _array._setUint8(_offset + byteOffset, value); |
264 } | 1578 } |
265 | 1579 |
266 int getInt16(int byteOffset) { | 1580 int getInt16(int byteOffset) { |
267 return _getInt16(byteOffset); | 1581 return _array._getInt16(_offset + byteOffset); |
268 } | 1582 } |
269 | |
270 void setInt16(int byteOffset, int value) { | 1583 void setInt16(int byteOffset, int value) { |
271 _setInt16(byteOffset, _toInt16(value)); | 1584 _array._setInt16(_offset + byteOffset, value); |
272 } | 1585 } |
273 | 1586 |
274 int getUint16(int byteOffset) { | 1587 int getUint16(int byteOffset) { |
275 return _getInt16(byteOffset); | 1588 return _array._getUint16(_offset + byteOffset); |
276 } | 1589 } |
277 | |
278 void setUint16(int byteOffset, int value) { | 1590 void setUint16(int byteOffset, int value) { |
279 _setUint16(byteOffset, _toUint16(value)); | 1591 _array._setUint16(_offset + byteOffset, value); |
280 } | 1592 } |
281 | 1593 |
282 int getInt32(int byteOffset) { | 1594 int getInt32(int byteOffset) { |
283 return _getInt32(byteOffset); | 1595 return _array._getInt32(_offset + byteOffset); |
284 } | 1596 } |
285 | |
286 void setInt32(int byteOffset, int value) { | 1597 void setInt32(int byteOffset, int value) { |
287 _setInt32(byteOffset, _toInt32(value)); | 1598 _array._setInt32(_offset + byteOffset, value); |
288 } | 1599 } |
289 | 1600 |
290 int getUint32(int byteOffset) { | 1601 int getUint32(int byteOffset) { |
291 return _getUint32(byteOffset); | 1602 return _array._getUint32(_offset + byteOffset); |
292 } | 1603 } |
293 | |
294 void setUint32(int byteOffset, int value) { | 1604 void setUint32(int byteOffset, int value) { |
295 _setUint32(byteOffset, _toUint32(value)); | 1605 _array._setUint32(_offset + byteOffset, value); |
296 } | 1606 } |
297 | 1607 |
298 int getInt64(int byteOffset) { | 1608 int getInt64(int byteOffset) { |
299 return _getInt64(byteOffset); | 1609 return _array._getInt64(_offset + byteOffset); |
300 } | 1610 } |
301 | |
302 void setInt64(int byteOffset, int value) { | 1611 void setInt64(int byteOffset, int value) { |
303 _setInt64(byteOffset, _toInt64(value)); | 1612 _array._setInt64(_offset + byteOffset, value); |
304 } | 1613 } |
305 | 1614 |
306 int getUint64(int byteOffset) { | 1615 int getUint64(int byteOffset) { |
307 return _getUint64(byteOffset); | 1616 return _array._getUint64(_offset + byteOffset); |
308 } | 1617 } |
309 | |
310 void setUint64(int byteOffset, int value) { | 1618 void setUint64(int byteOffset, int value) { |
311 _setUint64(byteOffset, _toUint64(value)); | 1619 _array._setUint64(_offset + byteOffset, value); |
312 } | 1620 } |
313 | 1621 |
314 double getFloat32(int byteOffset) { | 1622 double getFloat32(int byteOffset) { |
315 return _getFloat32(byteOffset); | 1623 return _array._getFloat32(_offset + byteOffset); |
316 } | 1624 } |
317 | |
318 void setFloat32(int byteOffset, double value) { | 1625 void setFloat32(int byteOffset, double value) { |
319 _setFloat32(byteOffset, value); | 1626 _array._setFloat32(_offset + byteOffset, value); |
320 } | 1627 } |
321 | 1628 |
322 double getFloat64(int byteOffset) { | 1629 double getFloat64(int byteOffset) { |
323 return _getFloat64(byteOffset); | 1630 return _array._getFloat64(_offset + byteOffset); |
324 } | 1631 } |
325 | |
326 void setFloat64(int byteOffset, double value) { | 1632 void setFloat64(int byteOffset, double value) { |
327 _setFloat64(byteOffset, value); | 1633 _array._setFloat64(_offset + byteOffset, value); |
328 } | 1634 } |
329 | 1635 |
330 // Implementation | 1636 final _ByteArrayBase _array; |
331 | 1637 final int _offset; |
332 static _InternalByteArray _allocate(int length) | 1638 final int _length; |
333 native "InternalByteArray_allocate"; | 1639 } |
334 | 1640 |
335 int _getInt8(int byteOffset) | 1641 |
336 native "InternalByteArray_getInt8"; | 1642 class _ByteArrayViewBase { |
337 | 1643 void add(value) { |
338 void _setInt8(int byteOffset, int value) | 1644 throw const UnsupportedOperationException( |
339 native "InternalByteArray_setInt8"; | 1645 "Cannot add to a non-extendable array"); |
340 | 1646 } |
341 int _getUint8(int byteOffset) | 1647 |
342 native "InternalByteArray_getUint8"; | 1648 void addLast(value) { |
343 | 1649 throw const UnsupportedOperationException( |
344 void _setUint8(int byteOffset, int value) | 1650 "Cannot add to a non-extendable array"); |
345 native "InternalByteArray_setUint8"; | 1651 } |
346 | 1652 |
347 int _getInt16(int byteOffset) | 1653 void addAll(Collection value) { |
348 native "InternalByteArray_getInt16"; | 1654 throw const UnsupportedOperationException( |
349 | 1655 "Cannot add to a non-extendable array"); |
350 void _setInt16(int byteOffset, int value) | 1656 } |
351 native "InternalByteArray_setInt16"; | 1657 |
352 | 1658 void clear() { |
353 int _getUint16(int byteOffset) | 1659 throw const UnsupportedOperationException( |
354 native "InternalByteArray_getUint16"; | 1660 "Cannot remove from a non-extendable array"); |
355 | 1661 } |
356 void _setUint16(int byteOffset, int value) | 1662 |
357 native "InternalByteArray_setUint16"; | 1663 void insertRange(int start, int length, [initialValue]) { |
358 | 1664 throw const UnsupportedOperationException( |
359 int _getInt32(int byteOffset) | 1665 "Cannot add to a non-extendable array"); |
360 native "InternalByteArray_getInt32"; | 1666 } |
361 | 1667 |
362 void _setInt32(int byteOffset, int value) | 1668 set length(int newLength) { |
363 native "InternalByteArray_setInt32"; | 1669 throw const UnsupportedOperationException( |
364 | 1670 "Cannot resize a non-extendable array"); |
365 int _getUint32(int byteOffset) | 1671 } |
366 native "InternalByteArray_getUint32"; | 1672 |
367 | 1673 int removeLast() { |
368 void _setUint32(int byteOffset, int value) | 1674 throw const UnsupportedOperationException( |
369 native "InternalByteArray_setUint32"; | 1675 "Cannot remove from a non-extendable array"); |
370 | 1676 } |
371 int _getInt64(int byteOffset) | 1677 |
372 native "InternalByteArray_getInt64"; | 1678 void removeRange(int start, int length) { |
373 | 1679 throw const UnsupportedOperationException( |
374 void _setInt64(int byteOffset, int value) | 1680 "Cannot remove from a non-extendable array"); |
375 native "InternalByteArray_setInt64"; | 1681 } |
376 | 1682 } |
377 int _getUint64(int byteOffset) | 1683 |
378 native "InternalByteArray_getUint64"; | 1684 |
379 | 1685 class _Int8ArrayView extends _ByteArrayViewBase implements Int8List { |
380 void _setUint64(int byteOffset, int value) | 1686 _Int8ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) |
381 native "InternalByteArray_setUint64"; | 1687 : _array = array, |
382 | 1688 _offset = offsetInBytes, |
383 double _getFloat32(int byteOffset) | 1689 _length = (length === null) ? (array.lengthInBytes() - offsetInBytes) |
384 native "InternalByteArray_getFloat32"; | 1690 : length { |
385 | 1691 if (offsetInBytes < 0 || offsetInBytes >= array.lengthInBytes()) { |
386 void _setFloat32(int byteOffset, double value) | 1692 throw new IndexOutOfRangeException(offsetInBytes); |
387 native "InternalByteArray_setFloat32"; | 1693 } |
388 | 1694 int lengthInBytes = length * _BYTES_PER_ELEMENT; |
389 double _getFloat64(int byteOffset) | 1695 if (length < 0 || (lengthInBytes + _offset) > array.lengthInBytes()) { |
390 native "InternalByteArray_getFloat64"; | 1696 throw new IndexOutOfRangeException(length); |
391 | 1697 } |
392 void _setFloat64(int byteOffset, double value) | 1698 } |
393 native "InternalByteArray_setFloat64"; | 1699 |
394 } | 1700 get length() { |
395 | 1701 return _length; |
396 | 1702 } |
397 class _ExternalByteArray extends _ByteArrayBase implements ByteArray { | 1703 |
398 // Collection interface | 1704 int operator[](int index) { |
399 | 1705 if (index < 0 || index >= _length) { |
400 int get length() { | 1706 throw new IndexOutOfRangeException(index); |
401 return _length(); | 1707 } |
402 } | 1708 return _array.getInt8(_offset + (index * _BYTES_PER_ELEMENT)); |
403 | |
404 // List interface | |
405 | |
406 int operator[](int index) { | |
407 return _getUint8(index); | |
408 } | 1709 } |
409 | 1710 |
410 void operator[]=(int index, int value) { | 1711 void operator[]=(int index, int value) { |
411 _setUint8(index, value); | 1712 if (index < 0 || index >= _length) { |
412 } | 1713 throw new IndexOutOfRangeException(index); |
413 | 1714 } |
414 // ByteArray interface | 1715 _array.setInt8(_offset + (index * _BYTES_PER_ELEMENT), _toInt8(value)); |
415 | 1716 } |
416 int getInt8(int byteOffset) { | 1717 |
417 return _getInt8(byteOffset); | 1718 Iterator<int> iterator() { |
418 } | 1719 return new _ByteArrayIterator<int>(this); |
419 | 1720 } |
420 void setInt8(int byteOffset, int value) { | 1721 |
421 _setInt8(byteOffset, _toInt8(value)); | 1722 List<int> getRange(int start, int length) { |
422 } | 1723 _rangeCheck(this, start, length); |
423 | 1724 List<int> result = new Int8List(length); |
424 int getUint8(int byteOffset) { | 1725 result.setRange(0, length, this, start); |
425 return _getUint8(byteOffset); | 1726 return result; |
426 } | 1727 } |
427 | 1728 |
428 void setUint8(int byteOffset, int value) { | 1729 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
429 _setUint8(byteOffset, _toUint8(value)); | 1730 Arrays.copy(from, startFrom, this, start, length); |
430 } | 1731 } |
431 | 1732 |
432 int getInt16(int byteOffset) { | 1733 String toString() { |
433 return _getInt16(byteOffset); | 1734 return Collections.collectionToString(this); |
434 } | 1735 } |
435 | 1736 |
436 void setInt16(int byteOffset, int value) { | 1737 int bytesPerElement() { |
437 _setInt16(byteOffset, _toInt16(value)); | 1738 return _BYTES_PER_ELEMENT; |
438 } | 1739 } |
439 | 1740 |
440 int getUint16(int byteOffset) { | 1741 int lengthInBytes() { |
441 return _getInt16(byteOffset); | 1742 return _length * _BYTES_PER_ELEMENT; |
442 } | 1743 } |
443 | 1744 |
444 void setUint16(int byteOffset, int value) { | 1745 ByteArray asByteArray([int start = 0, int length]) { |
445 _setUint16(byteOffset, _toUint16(value)); | 1746 if (length == null) { |
446 } | 1747 length = this.lengthInBytes(); |
447 | 1748 } |
448 int getInt32(int byteOffset) { | 1749 _rangeCheck(start, length); |
449 return _getInt32(byteOffset); | 1750 return _array.subByteArray(_offset + start, length); |
450 } | 1751 } |
451 | 1752 |
452 void setInt32(int byteOffset, int value) { | 1753 static final int _BYTES_PER_ELEMENT = 1; |
453 _setInt32(byteOffset, _toInt32(value)); | 1754 final ByteArray _array; |
454 } | 1755 final int _offset; |
455 | 1756 final int _length; |
456 int getUint32(int byteOffset) { | 1757 } |
457 return _getUint32(byteOffset); | 1758 |
458 } | 1759 |
459 | 1760 class _Uint8ArrayView extends _ByteArrayViewBase implements Uint8List { |
460 void setUint32(int byteOffset, int value) { | 1761 _Uint8ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) |
461 _setUint32(byteOffset, _toUint32(value)); | 1762 : _array = array, |
462 } | 1763 _offset = offsetInBytes, |
463 | 1764 _length = (length === null) ? (array.lengthInBytes() - offsetInBytes) |
464 int getInt64(int byteOffset) { | 1765 : length { |
465 return _getInt64(byteOffset); | 1766 if (offsetInBytes < 0 || offsetInBytes >= array.lengthInBytes()) { |
466 } | 1767 throw new IndexOutOfRangeException(offsetInBytes); |
467 | 1768 } |
468 void setInt64(int byteOffset, int value) { | 1769 int lengthInBytes = length * _BYTES_PER_ELEMENT; |
469 _setInt64(byteOffset, _toInt64(value)); | 1770 if (length < 0 || (lengthInBytes + _offset) > array.lengthInBytes()) { |
470 } | 1771 throw new IndexOutOfRangeException(length); |
471 | 1772 } |
472 int getUint64(int byteOffset) { | 1773 } |
473 return _getUint64(byteOffset); | 1774 |
474 } | 1775 get length() { |
475 | 1776 return _length; |
476 void setUint64(int byteOffset, int value) { | 1777 } |
477 _setUint64(byteOffset, _toUint64(value)); | 1778 |
478 } | 1779 int operator[](int index) { |
479 | 1780 if (index < 0 || index >= _length) { |
480 double getFloat32(int byteOffset) { | 1781 throw new IndexOutOfRangeException(index); |
481 return _getFloat32(byteOffset); | 1782 } |
482 } | 1783 return _array.getUint8(_offset + (index * _BYTES_PER_ELEMENT)); |
483 | 1784 } |
484 void setFloat32(int byteOffset, double value) { | 1785 |
485 _setFloat32(byteOffset, value); | 1786 void operator[]=(int index, int value) { |
486 } | 1787 if (index < 0 || index >= _length) { |
487 | 1788 throw new IndexOutOfRangeException(index); |
488 double getFloat64(int byteOffset) { | 1789 } |
489 return _getFloat64(byteOffset); | 1790 _array.setUint8(_offset + (index * _BYTES_PER_ELEMENT), _toUint8(value)); |
490 } | 1791 } |
491 | 1792 |
492 void setFloat64(int byteOffset, double value) { | 1793 Iterator<int> iterator() { |
493 _setFloat64(byteOffset, value); | 1794 return new _ByteArrayIterator<int>(this); |
494 } | 1795 } |
495 | 1796 |
496 // Implementation | 1797 List<int> getRange(int start, int length) { |
497 | 1798 _rangeCheck(this, start, length); |
498 int _getInt8(int byteOffset) | 1799 List<int> result = new Uint8List(length); |
499 native "ExternalByteArray_getInt8"; | 1800 result.setRange(0, length, this, start); |
500 | 1801 return result; |
501 void _setInt8(int byteOffset, int value) | 1802 } |
502 native "ExternalByteArray_setInt8"; | 1803 |
503 | 1804 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
504 int _getUint8(int byteOffset) | 1805 Arrays.copy(from, startFrom, this, start, length); |
505 native "ExternalByteArray_getUint8"; | 1806 } |
506 | 1807 |
507 void _setUint8(int byteOffset, int value) | 1808 String toString() { |
508 native "ExternalByteArray_setUint8"; | 1809 return Collections.collectionToString(this); |
509 | 1810 } |
510 int _getInt16(int byteOffset) | 1811 |
511 native "ExternalByteArray_getInt16"; | 1812 int bytesPerElement() { |
512 | 1813 return _BYTES_PER_ELEMENT; |
513 void _setInt16(int byteOffset, int value) | 1814 } |
514 native "ExternalByteArray_setInt16"; | 1815 |
515 | 1816 int lengthInBytes() { |
516 int _getUint16(int byteOffset) | 1817 return _length * _BYTES_PER_ELEMENT; |
517 native "ExternalByteArray_getUint16"; | 1818 } |
518 | 1819 |
519 void _setUint16(int byteOffset, int value) | 1820 ByteArray asByteArray([int start = 0, int length]) { |
520 native "ExternalByteArray_setUint16"; | 1821 if (length == null) { |
521 | 1822 length = this.lengthInBytes(); |
522 int _getInt32(int byteOffset) | 1823 } |
523 native "ExternalByteArray_getInt32"; | 1824 _rangeCheck(start, length); |
524 | 1825 return _array.subByteArray(_offset + start, length); |
525 void _setInt32(int byteOffset, int value) | 1826 } |
526 native "ExternalByteArray_setInt32"; | 1827 |
527 | 1828 static final int _BYTES_PER_ELEMENT = 1; |
528 int _getUint32(int byteOffset) | 1829 final ByteArray _array; |
529 native "ExternalByteArray_getUint32"; | 1830 final int _offset; |
530 | 1831 final int _length; |
531 void _setUint32(int byteOffset, int value) | 1832 } |
532 native "ExternalByteArray_setUint32"; | 1833 |
533 | 1834 |
534 int _getInt64(int byteOffset) | 1835 class _Int16ArrayView extends _ByteArrayViewBase implements Int16List { |
535 native "ExternalByteArray_getInt64"; | 1836 _Int16ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) |
536 | 1837 : _array = array, |
537 void _setInt64(int byteOffset, int value) | 1838 _offset = offsetInBytes, |
538 native "ExternalByteArray_setInt64"; | 1839 _length = (length === null) ? (array.lengthInBytes() - offsetInBytes) |
539 | 1840 : length { |
540 int _getUint64(int byteOffset) | 1841 if (offsetInBytes < 0 || offsetInBytes >= array.lengthInBytes()) { |
541 native "ExternalByteArray_getUint64"; | 1842 throw new IndexOutOfRangeException(offsetInBytes); |
542 | 1843 } |
543 void _setUint64(int byteOffset, int value) | 1844 int lengthInBytes = length * _BYTES_PER_ELEMENT; |
544 native "ExternalByteArray_setUint64"; | 1845 if (length < 0 || (lengthInBytes + _offset) > array.lengthInBytes()) { |
545 | 1846 throw new IndexOutOfRangeException(length); |
546 double _getFloat32(int byteOffset) | 1847 } |
547 native "ExternalByteArray_getFloat32"; | 1848 } |
548 | 1849 |
549 void _setFloat32(int byteOffset, double value) | 1850 get length() { |
550 native "ExternalByteArray_setFloat32"; | 1851 return _length; |
551 | 1852 } |
552 double _getFloat64(int byteOffset) | 1853 |
553 native "ExternalByteArray_getFloat64"; | 1854 int operator[](int index) { |
554 | 1855 if (index < 0 || index >= _length) { |
555 void _setFloat64(int byteOffset, double value) | 1856 throw new IndexOutOfRangeException(index); |
556 native "ExternalByteArray_setFloat64"; | 1857 } |
557 } | 1858 return _array.getInt16(_offset + (index * _BYTES_PER_ELEMENT)); |
| 1859 } |
| 1860 |
| 1861 void operator[]=(int index, int value) { |
| 1862 if (index < 0 || index >= _length) { |
| 1863 throw new IndexOutOfRangeException(index); |
| 1864 } |
| 1865 _array.setInt16(_offset + (index * _BYTES_PER_ELEMENT), _toInt16(value)); |
| 1866 } |
| 1867 |
| 1868 Iterator<int> iterator() { |
| 1869 return new _ByteArrayIterator<int>(this); |
| 1870 } |
| 1871 |
| 1872 List<int> getRange(int start, int length) { |
| 1873 _rangeCheck(this, start, length); |
| 1874 List<int> result = new Int16List(length); |
| 1875 result.setRange(0, length, this, start); |
| 1876 return result; |
| 1877 } |
| 1878 |
| 1879 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
| 1880 Arrays.copy(from, startFrom, this, start, length); |
| 1881 } |
| 1882 |
| 1883 String toString() { |
| 1884 return Collections.collectionToString(this); |
| 1885 } |
| 1886 |
| 1887 int bytesPerElement() { |
| 1888 return _BYTES_PER_ELEMENT; |
| 1889 } |
| 1890 |
| 1891 int lengthInBytes() { |
| 1892 return _length * _BYTES_PER_ELEMENT; |
| 1893 } |
| 1894 |
| 1895 ByteArray asByteArray([int start = 0, int length]) { |
| 1896 if (length == null) { |
| 1897 length = this.lengthInBytes(); |
| 1898 } |
| 1899 _rangeCheck(start, length); |
| 1900 return _array.subByteArray(_offset + start, length); |
| 1901 } |
| 1902 |
| 1903 static final int _BYTES_PER_ELEMENT = 2; |
| 1904 final ByteArray _array; |
| 1905 final int _offset; |
| 1906 final int _length; |
| 1907 } |
| 1908 |
| 1909 |
| 1910 class _Uint16ArrayView extends _ByteArrayViewBase implements Uint16List { |
| 1911 _Uint16ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) |
| 1912 : _array = array, |
| 1913 _offset = offsetInBytes, |
| 1914 _length = (length === null) ? (array.lengthInBytes() - offsetInBytes) |
| 1915 : length { |
| 1916 if (offsetInBytes < 0 || offsetInBytes >= array.lengthInBytes()) { |
| 1917 throw new IndexOutOfRangeException(offsetInBytes); |
| 1918 } |
| 1919 int lengthInBytes = length * _BYTES_PER_ELEMENT; |
| 1920 if (length < 0 || (lengthInBytes + _offset) > array.lengthInBytes()) { |
| 1921 throw new IndexOutOfRangeException(length); |
| 1922 } |
| 1923 } |
| 1924 |
| 1925 get length() { |
| 1926 return _length; |
| 1927 } |
| 1928 |
| 1929 int operator[](int index) { |
| 1930 if (index < 0 || index >= _length) { |
| 1931 throw new IndexOutOfRangeException(index); |
| 1932 } |
| 1933 return _array.getUint16(_offset + (index * _BYTES_PER_ELEMENT)); |
| 1934 } |
| 1935 |
| 1936 void operator[]=(int index, int value) { |
| 1937 if (index < 0 || index >= _length) { |
| 1938 throw new IndexOutOfRangeException(index); |
| 1939 } |
| 1940 _array.setUint16(_offset + (index * _BYTES_PER_ELEMENT), _toUint16(value)); |
| 1941 } |
| 1942 |
| 1943 Iterator<int> iterator() { |
| 1944 return new _ByteArrayIterator<int>(this); |
| 1945 } |
| 1946 |
| 1947 List<int> getRange(int start, int length) { |
| 1948 _rangeCheck(this, start, length); |
| 1949 List<int> result = new Uint16List(length); |
| 1950 result.setRange(0, length, this, start); |
| 1951 return result; |
| 1952 } |
| 1953 |
| 1954 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
| 1955 Arrays.copy(from, startFrom, this, start, length); |
| 1956 } |
| 1957 |
| 1958 String toString() { |
| 1959 return Collections.collectionToString(this); |
| 1960 } |
| 1961 |
| 1962 int bytesPerElement() { |
| 1963 return _BYTES_PER_ELEMENT; |
| 1964 } |
| 1965 |
| 1966 int lengthInBytes() { |
| 1967 return _length * _BYTES_PER_ELEMENT; |
| 1968 } |
| 1969 |
| 1970 ByteArray asByteArray([int start = 0, int length]) { |
| 1971 if (length == null) { |
| 1972 length = this.lengthInBytes(); |
| 1973 } |
| 1974 _rangeCheck(start, length); |
| 1975 return _array.subByteArray(_offset + start, length); |
| 1976 } |
| 1977 |
| 1978 static final int _BYTES_PER_ELEMENT = 2; |
| 1979 final ByteArray _array; |
| 1980 final int _offset; |
| 1981 final int _length; |
| 1982 } |
| 1983 |
| 1984 |
| 1985 class _Int32ArrayView extends _ByteArrayViewBase implements Int32List { |
| 1986 _Int32ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) |
| 1987 : _array = array, |
| 1988 _offset = offsetInBytes, |
| 1989 _length = (length === null) ? (array.lengthInBytes() - offsetInBytes) |
| 1990 : length { |
| 1991 if (offsetInBytes < 0 || offsetInBytes >= array.lengthInBytes()) { |
| 1992 throw new IndexOutOfRangeException(offsetInBytes); |
| 1993 } |
| 1994 int lengthInBytes = length * _BYTES_PER_ELEMENT; |
| 1995 if (length < 0 || (lengthInBytes + _offset) > array.lengthInBytes()) { |
| 1996 throw new IndexOutOfRangeException(length); |
| 1997 } |
| 1998 } |
| 1999 |
| 2000 get length() { |
| 2001 return _length; |
| 2002 } |
| 2003 |
| 2004 int operator[](int index) { |
| 2005 if (index < 0 || index >= _length) { |
| 2006 throw new IndexOutOfRangeException(index); |
| 2007 } |
| 2008 return _array.getInt32(_offset + (index * _BYTES_PER_ELEMENT)); |
| 2009 } |
| 2010 |
| 2011 void operator[]=(int index, int value) { |
| 2012 if (index < 0 || index >= _length) { |
| 2013 throw new IndexOutOfRangeException(index); |
| 2014 } |
| 2015 _array.setInt32(_offset + (index * _BYTES_PER_ELEMENT), _toInt32(value)); |
| 2016 } |
| 2017 |
| 2018 Iterator<int> iterator() { |
| 2019 return new _ByteArrayIterator<int>(this); |
| 2020 } |
| 2021 |
| 2022 List<int> getRange(int start, int length) { |
| 2023 _rangeCheck(this, start, length); |
| 2024 List<int> result = new Int32List(length); |
| 2025 result.setRange(0, length, this, start); |
| 2026 return result; |
| 2027 } |
| 2028 |
| 2029 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
| 2030 Arrays.copy(from, startFrom, this, start, length); |
| 2031 } |
| 2032 |
| 2033 String toString() { |
| 2034 return Collections.collectionToString(this); |
| 2035 } |
| 2036 |
| 2037 int bytesPerElement() { |
| 2038 return _BYTES_PER_ELEMENT; |
| 2039 } |
| 2040 |
| 2041 int lengthInBytes() { |
| 2042 return _length * _BYTES_PER_ELEMENT; |
| 2043 } |
| 2044 |
| 2045 ByteArray asByteArray([int start = 0, int length]) { |
| 2046 if (length == null) { |
| 2047 length = this.lengthInBytes(); |
| 2048 } |
| 2049 _rangeCheck(start, length); |
| 2050 return _array.subByteArray(_offset + start, length); |
| 2051 } |
| 2052 |
| 2053 static final int _BYTES_PER_ELEMENT = 4; |
| 2054 final ByteArray _array; |
| 2055 final int _offset; |
| 2056 final int _length; |
| 2057 } |
| 2058 |
| 2059 |
| 2060 class _Uint32ArrayView extends _ByteArrayViewBase implements Uint32List { |
| 2061 _Uint32ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) |
| 2062 : _array = array, |
| 2063 _offset = offsetInBytes, |
| 2064 _length = (length === null) ? (array.lengthInBytes() - offsetInBytes) |
| 2065 : length { |
| 2066 if (offsetInBytes < 0 || offsetInBytes >= array.lengthInBytes()) { |
| 2067 throw new IndexOutOfRangeException(offsetInBytes); |
| 2068 } |
| 2069 int lengthInBytes = length * _BYTES_PER_ELEMENT; |
| 2070 if (length < 0 || (lengthInBytes + _offset) > array.lengthInBytes()) { |
| 2071 throw new IndexOutOfRangeException(length); |
| 2072 } |
| 2073 } |
| 2074 |
| 2075 get length() { |
| 2076 return _length; |
| 2077 } |
| 2078 |
| 2079 int operator[](int index) { |
| 2080 if (index < 0 || index >= _length) { |
| 2081 throw new IndexOutOfRangeException(index); |
| 2082 } |
| 2083 return _array.getUint32(_offset + (index * _BYTES_PER_ELEMENT)); |
| 2084 } |
| 2085 |
| 2086 void operator[]=(int index, int value) { |
| 2087 if (index < 0 || index >= _length) { |
| 2088 throw new IndexOutOfRangeException(index); |
| 2089 } |
| 2090 _array.setUint32(_offset + (index * _BYTES_PER_ELEMENT), _toUint32(value)); |
| 2091 } |
| 2092 |
| 2093 Iterator<int> iterator() { |
| 2094 return new _ByteArrayIterator<int>(this); |
| 2095 } |
| 2096 |
| 2097 List<int> getRange(int start, int length) { |
| 2098 _rangeCheck(this, start, length); |
| 2099 List<int> result = new Uint32List(length); |
| 2100 result.setRange(0, length, this, start); |
| 2101 return result; |
| 2102 } |
| 2103 |
| 2104 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
| 2105 Arrays.copy(from, startFrom, this, start, length); |
| 2106 } |
| 2107 |
| 2108 String toString() { |
| 2109 return Collections.collectionToString(this); |
| 2110 } |
| 2111 |
| 2112 int bytesPerElement() { |
| 2113 return _BYTES_PER_ELEMENT; |
| 2114 } |
| 2115 |
| 2116 int lengthInBytes() { |
| 2117 return _length * _BYTES_PER_ELEMENT; |
| 2118 } |
| 2119 |
| 2120 ByteArray asByteArray([int start = 0, int length]) { |
| 2121 if (length == null) { |
| 2122 length = this.lengthInBytes(); |
| 2123 } |
| 2124 _rangeCheck(start, length); |
| 2125 return _array.subByteArray(_offset + start, length); |
| 2126 } |
| 2127 |
| 2128 static final int _BYTES_PER_ELEMENT = 4; |
| 2129 final ByteArray _array; |
| 2130 final int _offset; |
| 2131 final int _length; |
| 2132 } |
| 2133 |
| 2134 |
| 2135 class _Int64ArrayView extends _ByteArrayViewBase implements Int64List { |
| 2136 _Int64ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) |
| 2137 : _array = array, |
| 2138 _offset = offsetInBytes, |
| 2139 _length = (length === null) ? (array.lengthInBytes() - offsetInBytes) |
| 2140 : length { |
| 2141 if (offsetInBytes < 0 || offsetInBytes >= array.lengthInBytes()) { |
| 2142 throw new IndexOutOfRangeException(offsetInBytes); |
| 2143 } |
| 2144 int lengthInBytes = length * _BYTES_PER_ELEMENT; |
| 2145 if (length < 0 || (lengthInBytes + _offset) > array.lengthInBytes()) { |
| 2146 throw new IndexOutOfRangeException(length); |
| 2147 } |
| 2148 } |
| 2149 |
| 2150 get length() { |
| 2151 return _length; |
| 2152 } |
| 2153 |
| 2154 int operator[](int index) { |
| 2155 if (index < 0 || index >= _length) { |
| 2156 throw new IndexOutOfRangeException(index); |
| 2157 } |
| 2158 return _array.getInt64(_offset + (index * _BYTES_PER_ELEMENT)); |
| 2159 } |
| 2160 |
| 2161 void operator[]=(int index, int value) { |
| 2162 if (index < 0 || index >= _length) { |
| 2163 throw new IndexOutOfRangeException(index); |
| 2164 } |
| 2165 _array.setInt64(_offset + (index * _BYTES_PER_ELEMENT), _toInt64(value)); |
| 2166 } |
| 2167 |
| 2168 Iterator<int> iterator() { |
| 2169 return new _ByteArrayIterator<int>(this); |
| 2170 } |
| 2171 |
| 2172 List<int> getRange(int start, int length) { |
| 2173 _rangeCheck(this, start, length); |
| 2174 List<int> result = new Int64List(length); |
| 2175 result.setRange(0, length, this, start); |
| 2176 return result; |
| 2177 } |
| 2178 |
| 2179 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
| 2180 Arrays.copy(from, startFrom, this, start, length); |
| 2181 } |
| 2182 |
| 2183 String toString() { |
| 2184 return Collections.collectionToString(this); |
| 2185 } |
| 2186 |
| 2187 int bytesPerElement() { |
| 2188 return _BYTES_PER_ELEMENT; |
| 2189 } |
| 2190 |
| 2191 int lengthInBytes() { |
| 2192 return _length * _BYTES_PER_ELEMENT; |
| 2193 } |
| 2194 |
| 2195 ByteArray asByteArray([int start = 0, int length]) { |
| 2196 if (length == null) { |
| 2197 length = this.lengthInBytes(); |
| 2198 } |
| 2199 _rangeCheck(start, length); |
| 2200 return _array.subByteArray(_offset + start, length); |
| 2201 } |
| 2202 |
| 2203 static final int _BYTES_PER_ELEMENT = 8; |
| 2204 final ByteArray _array; |
| 2205 final int _offset; |
| 2206 final int _length; |
| 2207 } |
| 2208 |
| 2209 |
| 2210 class _Uint64ArrayView extends _ByteArrayViewBase implements Uint64List { |
| 2211 _Uint64ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) |
| 2212 : _array = array, |
| 2213 _offset = offsetInBytes, |
| 2214 _length = (length === null) ? (array.lengthInBytes() - offsetInBytes) |
| 2215 : length { |
| 2216 if (offsetInBytes < 0 || offsetInBytes >= array.lengthInBytes()) { |
| 2217 throw new IndexOutOfRangeException(offsetInBytes); |
| 2218 } |
| 2219 int lengthInBytes = length * _BYTES_PER_ELEMENT; |
| 2220 if (length < 0 || (lengthInBytes + _offset) > array.lengthInBytes()) { |
| 2221 throw new IndexOutOfRangeException(length); |
| 2222 } |
| 2223 } |
| 2224 |
| 2225 get length() { |
| 2226 return _length; |
| 2227 } |
| 2228 |
| 2229 int operator[](int index) { |
| 2230 if (index < 0 || index >= _length) { |
| 2231 throw new IndexOutOfRangeException(index); |
| 2232 } |
| 2233 return _array.getUint64(_offset + (index * _BYTES_PER_ELEMENT)); |
| 2234 } |
| 2235 |
| 2236 void operator[]=(int index, int value) { |
| 2237 if (index < 0 || index >= _length) { |
| 2238 throw new IndexOutOfRangeException(index); |
| 2239 } |
| 2240 _array.setUint64(_offset + (index * _BYTES_PER_ELEMENT), _toUint64(value)); |
| 2241 } |
| 2242 |
| 2243 Iterator<int> iterator() { |
| 2244 return new _ByteArrayIterator<int>(this); |
| 2245 } |
| 2246 |
| 2247 List<int> getRange(int start, int length) { |
| 2248 _rangeCheck(this, start, length); |
| 2249 List<int> result = new Uint64List(length); |
| 2250 result.setRange(0, length, this, start); |
| 2251 return result; |
| 2252 } |
| 2253 |
| 2254 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
| 2255 Arrays.copy(from, startFrom, this, start, length); |
| 2256 } |
| 2257 |
| 2258 String toString() { |
| 2259 return Collections.collectionToString(this); |
| 2260 } |
| 2261 |
| 2262 int bytesPerElement() { |
| 2263 return _BYTES_PER_ELEMENT; |
| 2264 } |
| 2265 |
| 2266 int lengthInBytes() { |
| 2267 return _length * _BYTES_PER_ELEMENT; |
| 2268 } |
| 2269 |
| 2270 ByteArray asByteArray([int start = 0, int length]) { |
| 2271 if (length == null) { |
| 2272 length = this.lengthInBytes(); |
| 2273 } |
| 2274 _rangeCheck(start, length); |
| 2275 return _array.subByteArray(_offset + start, length); |
| 2276 } |
| 2277 |
| 2278 static final int _BYTES_PER_ELEMENT = 8; |
| 2279 final ByteArray _array; |
| 2280 final int _offset; |
| 2281 final int _length; |
| 2282 } |
| 2283 |
| 2284 |
| 2285 class _Float32ArrayView extends _ByteArrayViewBase implements Float32List { |
| 2286 _Float32ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) |
| 2287 : _array = array, |
| 2288 _offset = offsetInBytes, |
| 2289 _length = (length === null) ? (array.lengthInBytes() - offsetInBytes) |
| 2290 : length { |
| 2291 if (offsetInBytes < 0 || offsetInBytes >= array.lengthInBytes()) { |
| 2292 throw new IndexOutOfRangeException(offsetInBytes); |
| 2293 } |
| 2294 int lengthInBytes = length * _BYTES_PER_ELEMENT; |
| 2295 if (length < 0 || (lengthInBytes + _offset) > array.lengthInBytes()) { |
| 2296 throw new IndexOutOfRangeException(length); |
| 2297 } |
| 2298 } |
| 2299 |
| 2300 get length() { |
| 2301 return _length; |
| 2302 } |
| 2303 |
| 2304 double operator[](int index) { |
| 2305 if (index < 0 || index >= _length) { |
| 2306 throw new IndexOutOfRangeException(index); |
| 2307 } |
| 2308 return _array.getFloat32(_offset + (index * _BYTES_PER_ELEMENT)); |
| 2309 } |
| 2310 |
| 2311 void operator[]=(int index, double value) { |
| 2312 if (index < 0 || index >= _length) { |
| 2313 throw new IndexOutOfRangeException(index); |
| 2314 } |
| 2315 _array.setFloat32(_offset + (index * _BYTES_PER_ELEMENT), value); |
| 2316 } |
| 2317 |
| 2318 Iterator<double> iterator() { |
| 2319 return new _ByteArrayIterator<double>(this); |
| 2320 } |
| 2321 |
| 2322 List<double> getRange(int start, int length) { |
| 2323 _rangeCheck(this, start, length); |
| 2324 List<double> result = new Float32List(length); |
| 2325 result.setRange(0, length, this, start); |
| 2326 return result; |
| 2327 } |
| 2328 |
| 2329 void setRange(int start, int length, List<double> from, [int startFrom = 0]) { |
| 2330 Arrays.copy(from, startFrom, this, start, length); |
| 2331 } |
| 2332 |
| 2333 String toString() { |
| 2334 return Collections.collectionToString(this); |
| 2335 } |
| 2336 |
| 2337 int bytesPerElement() { |
| 2338 return _BYTES_PER_ELEMENT; |
| 2339 } |
| 2340 |
| 2341 int lengthInBytes() { |
| 2342 return _length * _BYTES_PER_ELEMENT; |
| 2343 } |
| 2344 |
| 2345 ByteArray asByteArray([int start = 0, int length]) { |
| 2346 if (length == null) { |
| 2347 length = this.lengthInBytes(); |
| 2348 } |
| 2349 _rangeCheck(start, length); |
| 2350 return _array.subByteArray(_offset + start, length); |
| 2351 } |
| 2352 |
| 2353 static final int _BYTES_PER_ELEMENT = 4; |
| 2354 final ByteArray _array; |
| 2355 final int _offset; |
| 2356 final int _length; |
| 2357 } |
| 2358 |
| 2359 |
| 2360 class _Float64ArrayView extends _ByteArrayViewBase implements Float64List { |
| 2361 _Float64ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) |
| 2362 : _array = array, |
| 2363 _offset = offsetInBytes, |
| 2364 _length = (length === null) ? (array.lengthInBytes() - offsetInBytes) |
| 2365 : length { |
| 2366 if (offsetInBytes < 0 || offsetInBytes >= array.lengthInBytes()) { |
| 2367 throw new IndexOutOfRangeException(offsetInBytes); |
| 2368 } |
| 2369 int lengthInBytes = length * _BYTES_PER_ELEMENT; |
| 2370 if (length < 0 || (lengthInBytes + _offset) > array.lengthInBytes()) { |
| 2371 throw new IndexOutOfRangeException(length); |
| 2372 } |
| 2373 } |
| 2374 |
| 2375 get length() { |
| 2376 return _length; |
| 2377 } |
| 2378 |
| 2379 double operator[](int index) { |
| 2380 if (index < 0 || index >= _length) { |
| 2381 throw new IndexOutOfRangeException(index); |
| 2382 } |
| 2383 return _array.getFloat64(_offset + (index * _BYTES_PER_ELEMENT)); |
| 2384 } |
| 2385 |
| 2386 void operator[]=(int index, double value) { |
| 2387 if (index < 0 || index >= _length) { |
| 2388 throw new IndexOutOfRangeException(index); |
| 2389 } |
| 2390 _array.setFloat64(_offset + (index * _BYTES_PER_ELEMENT), value); |
| 2391 } |
| 2392 |
| 2393 Iterator<double> iterator() { |
| 2394 return new _ByteArrayIterator<double>(this); |
| 2395 } |
| 2396 |
| 2397 List<double> getRange(int start, int length) { |
| 2398 _rangeCheck(this, start, length); |
| 2399 List<double> result = new Float64List(length); |
| 2400 result.setRange(0, length, this, start); |
| 2401 return result; |
| 2402 } |
| 2403 |
| 2404 void setRange(int start, int length, List<double> from, [int startFrom = 0]) { |
| 2405 Arrays.copy(from, startFrom, this, start, length); |
| 2406 } |
| 2407 |
| 2408 String toString() { |
| 2409 return Collections.collectionToString(this); |
| 2410 } |
| 2411 |
| 2412 int bytesPerElement() { |
| 2413 return _BYTES_PER_ELEMENT; |
| 2414 } |
| 2415 |
| 2416 int lengthInBytes() { |
| 2417 return _length * _BYTES_PER_ELEMENT; |
| 2418 } |
| 2419 |
| 2420 ByteArray asByteArray([int start = 0, int length]) { |
| 2421 if (length == null) { |
| 2422 length = this.lengthInBytes(); |
| 2423 } |
| 2424 _rangeCheck(start, length); |
| 2425 return _array.subByteArray(_offset + start, length); |
| 2426 } |
| 2427 |
| 2428 static final int _BYTES_PER_ELEMENT = 8; |
| 2429 final ByteArray _array; |
| 2430 final int _offset; |
| 2431 final int _length; |
| 2432 } |
OLD | NEW |