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

Side by Side Diff: runtime/lib/typed_data.dart

Issue 2571563005: Turn the VM's dart:typed_data into a patch (Closed)
Patch Set: Fix interface/implementation type mismatch Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | runtime/lib/typed_data_patch.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 // Unlike the other SDK libraries, this file is not a patch that is applied to
6 // dart:typed_data. Instead, it completely replaces the implementation from the
7 // SDK.
8 library dart.typed_data;
9
10 import "dart:_internal";
11 import "dart:collection" show ListBase;
12 import 'dart:math' show Random;
13
14 /**
15 * A typed view of a sequence of bytes.
16 */
17 abstract class TypedData {
18 /**
19 * Returns the number of bytes in the representation of each element in this
20 * list.
21 */
22 int get elementSizeInBytes;
23
24 /**
25 * Returns the offset in bytes into the underlying byte buffer of this view.
26 */
27 int get offsetInBytes;
28
29 /**
30 * Returns the length of this view, in bytes.
31 */
32 int get lengthInBytes;
33
34 /**
35 * Returns the byte buffer associated with this object.
36 */
37 ByteBuffer get buffer;
38 }
39
40
41 /**
42 * Describes endianness to be used when accessing or updating a
43 * sequence of bytes.
44 */
45 class Endianness {
46 const Endianness._(this._littleEndian);
47
48 static const Endianness BIG_ENDIAN = const Endianness._(false);
49 static const Endianness LITTLE_ENDIAN = const Endianness._(true);
50 static final Endianness HOST_ENDIAN =
51 (new ByteData.view(new Uint16List.fromList([1]).buffer)).getInt8(0) == 1 ?
52 LITTLE_ENDIAN : BIG_ENDIAN;
53
54 final bool _littleEndian;
55 }
56
57
58 /**
59 * A fixed-length, random-access sequence of bytes that also provides random
60 * and unaligned access to the fixed-width integers and floating point
61 * numbers represented by those bytes.
62 *
63 * `ByteData` may be used to pack and unpack data from external sources
64 * (such as networks or files systems), and to process large quantities
65 * of numerical data more efficiently than would be possible
66 * with ordinary [List] implementations.
67 * `ByteData` can save space, by eliminating the need for object headers,
68 * and time, by eliminating the need for data copies.
69 * Finally, `ByteData` may be used to intentionally reinterpret the bytes
70 * representing one arithmetic type as another.
71 * For example this code fragment determine what 32-bit signed integer
72 * is represented by the bytes of a 32-bit floating point number:
73 *
74 * var buffer = new Uint8List(8).buffer;
75 * var bdata = new ByteData.view(buffer);
76 * bdata.setFloat32(0, 3.04);
77 * int huh = bdata.getInt32(0);
78 */
79 class ByteData implements TypedData {
80 /**
81 * Creates a [ByteData] of the specified length (in elements), all of
82 * whose bytes are initially zero.
83 */
84 factory ByteData(int length) {
85 var list = new Uint8List(length);
86 return new _ByteDataView(list, 0, length);
87 }
88
89 // Called directly from C code.
90 factory ByteData._view(TypedData typedData, int offsetInBytes, int length) {
91 return new _ByteDataView(typedData, offsetInBytes, length);
92 }
93
94 /**
95 * Creates an [ByteData] _view_ of the specified region in [buffer].
96 *
97 * Changes in the [ByteData] will be visible in the byte
98 * buffer and vice versa.
99 * If the [offsetInBytes] index of the region is not specified,
100 * it defaults to zero (the first byte in the byte buffer).
101 * If the length is not specified, it defaults to `null`,
102 * which indicates that the view extends to the end of the byte buffer.
103 *
104 * Throws [RangeError] if [offsetInBytes] or [length] are negative, or
105 * if [offsetInBytes] + ([length] * elementSizeInBytes) is greater than
106 * the length of [buffer].
107 */
108 factory ByteData.view(ByteBuffer buffer,
109 [int offsetInBytes = 0, int length]) {
110 return buffer.asByteData(offsetInBytes, length);
111 }
112
113 /**
114 * Returns the (possibly negative) integer represented by the byte at the
115 * specified [byteOffset] in this object, in two's complement binary
116 * representation.
117 *
118 * The return value will be between -128 and 127, inclusive.
119 *
120 * Throws [RangeError] if [byteOffset] is negative, or
121 * greater than or equal to the length of this object.
122 */
123 int getInt8(int byteOffset);
124
125 /**
126 * Sets the byte at the specified [byteOffset] in this object to the
127 * two's complement binary representation of the specified [value], which
128 * must fit in a single byte.
129 *
130 * In other words, [value] must be between -128 and 127, inclusive.
131 *
132 * Throws [RangeError] if [byteOffset] is negative, or
133 * greater than or equal to the length of this object.
134 */
135 void setInt8(int byteOffset, int value);
136
137 /**
138 * Returns the positive integer represented by the byte at the specified
139 * [byteOffset] in this object, in unsigned binary form.
140 *
141 * The return value will be between 0 and 255, inclusive.
142 *
143 * Throws [RangeError] if [byteOffset] is negative, or
144 * greater than or equal to the length of this object.
145 */
146 int getUint8(int byteOffset);
147
148 /**
149 * Sets the byte at the specified [byteOffset] in this object to the
150 * unsigned binary representation of the specified [value], which must fit
151 * in a single byte.
152 *
153 * In other words, [value] must be between 0 and 255, inclusive.
154 *
155 * Throws [RangeError] if [byteOffset] is negative,
156 * or greater than or equal to the length of this object.
157 */
158 void setUint8(int byteOffset, int value);
159
160 /**
161 * Returns the (possibly negative) integer represented by the two bytes at
162 * the specified [byteOffset] in this object, in two's complement binary
163 * form.
164 *
165 * The return value will be between 2<sup>15</sup> and 2<sup>15</sup> - 1,
166 * inclusive.
167 *
168 * Throws [RangeError] if [byteOffset] is negative, or
169 * `byteOffset + 2` is greater than the length of this object.
170 */
171 int getInt16(int byteOffset, [Endianness endian = Endianness.BIG_ENDIAN]);
172
173 /**
174 * Sets the two bytes starting at the specified [byteOffset] in this
175 * object to the two's complement binary representation of the specified
176 * [value], which must fit in two bytes.
177 *
178 * In other words, [value] must lie
179 * between 2<sup>15</sup> and 2<sup>15</sup> - 1, inclusive.
180 *
181 * Throws [RangeError] if [byteOffset] is negative, or
182 * `byteOffset + 2` is greater than the length of this object.
183 */
184 void setInt16(int byteOffset,
185 int value,
186 [Endianness endian = Endianness.BIG_ENDIAN]);
187
188 /**
189 * Returns the positive integer represented by the two bytes starting
190 * at the specified [byteOffset] in this object, in unsigned binary
191 * form.
192 *
193 * The return value will be between 0 and 2<sup>16</sup> - 1, inclusive.
194 *
195 * Throws [RangeError] if [byteOffset] is negative, or
196 * `byteOffset + 2` is greater than the length of this object.
197 */
198 int getUint16(int byteOffset, [Endianness endian = Endianness.BIG_ENDIAN]);
199
200 /**
201 * Sets the two bytes starting at the specified [byteOffset] in this object
202 * to the unsigned binary representation of the specified [value],
203 * which must fit in two bytes.
204 *
205 * In other words, [value] must be between
206 * 0 and 2<sup>16</sup> - 1, inclusive.
207 *
208 * Throws [RangeError] if [byteOffset] is negative, or
209 * `byteOffset + 2` is greater than the length of this object.
210 */
211 void setUint16(int byteOffset,
212 int value,
213 [Endianness endian = Endianness.BIG_ENDIAN]);
214
215 /**
216 * Returns the (possibly negative) integer represented by the four bytes at
217 * the specified [byteOffset] in this object, in two's complement binary
218 * form.
219 *
220 * The return value will be between 2<sup>31</sup> and 2<sup>31</sup> - 1,
221 * inclusive.
222 *
223 * Throws [RangeError] if [byteOffset] is negative, or
224 * `byteOffset + 4` is greater than the length of this object.
225 */
226 int getInt32(int byteOffset, [Endianness endian = Endianness.BIG_ENDIAN]);
227
228 /**
229 * Sets the four bytes starting at the specified [byteOffset] in this
230 * object to the two's complement binary representation of the specified
231 * [value], which must fit in four bytes.
232 *
233 * In other words, [value] must lie
234 * between 2<sup>31</sup> and 2<sup>31</sup> - 1, inclusive.
235 *
236 * Throws [RangeError] if [byteOffset] is negative, or
237 * `byteOffset + 4` is greater than the length of this object.
238 */
239 void setInt32(int byteOffset,
240 int value,
241 [Endianness endian = Endianness.BIG_ENDIAN]);
242
243 /**
244 * Returns the positive integer represented by the four bytes starting
245 * at the specified [byteOffset] in this object, in unsigned binary
246 * form.
247 *
248 * The return value will be between 0 and 2<sup>32</sup> - 1, inclusive.
249 *
250 * Throws [RangeError] if [byteOffset] is negative, or
251 * `byteOffset + 4` is greater than the length of this object.
252 */
253 int getUint32(int byteOffset, [Endianness endian = Endianness.BIG_ENDIAN]);
254
255 /**
256 * Sets the four bytes starting at the specified [byteOffset] in this object
257 * to the unsigned binary representation of the specified [value],
258 * which must fit in four bytes.
259 *
260 * In other words, [value] must be between
261 * 0 and 2<sup>32</sup> - 1, inclusive.
262 *
263 * Throws [RangeError] if [byteOffset] is negative, or
264 * `byteOffset + 4` is greater than the length of this object.
265 */
266 void setUint32(int byteOffset,
267 int value,
268 [Endianness endian = Endianness.BIG_ENDIAN]);
269
270 /**
271 * Returns the (possibly negative) integer represented by the eight bytes at
272 * the specified [byteOffset] in this object, in two's complement binary
273 * form.
274 *
275 * The return value will be between 2<sup>63</sup> and 2<sup>63</sup> - 1,
276 * inclusive.
277 *
278 * Throws [RangeError] if [byteOffset] is negative, or
279 * `byteOffset + 8` is greater than the length of this object.
280 */
281 int getInt64(int byteOffset, [Endianness endian = Endianness.BIG_ENDIAN]);
282
283 /**
284 * Sets the eight bytes starting at the specified [byteOffset] in this
285 * object to the two's complement binary representation of the specified
286 * [value], which must fit in eight bytes.
287 *
288 * In other words, [value] must lie
289 * between 2<sup>63</sup> and 2<sup>63</sup> - 1, inclusive.
290 *
291 * Throws [RangeError] if [byteOffset] is negative, or
292 * `byteOffset + 8` is greater than the length of this object.
293 */
294 void setInt64(int byteOffset,
295 int value,
296 [Endianness endian = Endianness.BIG_ENDIAN]);
297
298 /**
299 * Returns the positive integer represented by the eight bytes starting
300 * at the specified [byteOffset] in this object, in unsigned binary
301 * form.
302 *
303 * The return value will be between 0 and 2<sup>64</sup> - 1, inclusive.
304 *
305 * Throws [RangeError] if [byteOffset] is negative, or
306 * `byteOffset + 8` is greater than the length of this object.
307 */
308 int getUint64(int byteOffset, [Endianness endian = Endianness.BIG_ENDIAN]);
309
310 /**
311 * Sets the eight bytes starting at the specified [byteOffset] in this object
312 * to the unsigned binary representation of the specified [value],
313 * which must fit in eight bytes.
314 *
315 * In other words, [value] must be between
316 * 0 and 2<sup>64</sup> - 1, inclusive.
317 *
318 * Throws [RangeError] if [byteOffset] is negative, or
319 * `byteOffset + 8` is greater than the length of this object.
320 */
321 void setUint64(int byteOffset,
322 int value,
323 [Endianness endian = Endianness.BIG_ENDIAN]);
324
325 /**
326 * Returns the floating point number represented by the four bytes at
327 * the specified [byteOffset] in this object, in IEEE 754
328 * single-precision binary floating-point format (binary32).
329 *
330 * Throws [RangeError] if [byteOffset] is negative, or
331 * `byteOffset + 4` is greater than the length of this object.
332 */
333 double getFloat32(int byteOffset,
334 [Endianness endian = Endianness.BIG_ENDIAN]);
335
336 /**
337 * Sets the four bytes starting at the specified [byteOffset] in this
338 * object to the IEEE 754 single-precision binary floating-point
339 * (binary32) representation of the specified [value].
340 *
341 * **Note that this method can lose precision.** The input [value] is
342 * a 64-bit floating point value, which will be converted to 32-bit
343 * floating point value by IEEE 754 rounding rules before it is stored.
344 * If [value] cannot be represented exactly as a binary32, it will be
345 * converted to the nearest binary32 value. If two binary32 values are
346 * equally close, the one whose least significant bit is zero will be used.
347 * Note that finite (but large) values can be converted to infinity, and
348 * small non-zero values can be converted to zero.
349 *
350 * Throws [RangeError] if [byteOffset] is negative, or
351 * `byteOffset + 4` is greater than the length of this object.
352 */
353 void setFloat32(int byteOffset,
354 double value,
355 [Endianness endian = Endianness.BIG_ENDIAN]);
356
357 /**
358 * Returns the floating point number represented by the eight bytes at
359 * the specified [byteOffset] in this object, in IEEE 754
360 * double-precision binary floating-point format (binary64).
361 *
362 * Throws [RangeError] if [byteOffset] is negative, or
363 * `byteOffset + 8` is greater than the length of this object.
364 */
365 double getFloat64(int byteOffset,
366 [Endianness endian = Endianness.BIG_ENDIAN]);
367
368 /**
369 * Sets the eight bytes starting at the specified [byteOffset] in this
370 * object to the IEEE 754 double-precision binary floating-point
371 * (binary64) representation of the specified [value].
372 *
373 * Throws [RangeError] if [byteOffset] is negative, or
374 * `byteOffset + 8` is greater than the length of this object.
375 */
376 void setFloat64(int byteOffset,
377 double value,
378 [Endianness endian = Endianness.BIG_ENDIAN]);
379 }
380
381
382 // Based class for _TypedList that provides common methods for implementing
383 // the collection and list interfaces.
384 // This class does not extend ListBase<T> since that would add type arguments
385 // to instances of _TypeListBase. Instead the subclasses use type specific
386 // mixins (like _IntListMixin, _DoubleListMixin) to implement ListBase<T>.
387 abstract class _TypedListBase {
388
389 // Method(s) implementing the Collection interface.
390 bool contains(element) {
391 var len = this.length;
392 for (var i = 0; i < len; ++i) {
393 if (this[i] == element) return true;
394 }
395 return false;
396 }
397
398 void forEach(void f(element)) {
399 var len = this.length;
400 for (var i = 0; i < len; i++) {
401 f(this[i]);
402 }
403 }
404
405 String join([String separator = ""]) {
406 StringBuffer buffer = new StringBuffer();
407 buffer.writeAll(this, separator);
408 return buffer.toString();
409 }
410
411 dynamic reduce(dynamic combine(value, element)) {
412 var len = this.length;
413 if (len == 0) throw IterableElementError.noElement();
414 var i = 0;
415 var value = this[0];
416 for (var i = 1; i < len; ++i) {
417 value = combine(value, this[i]);
418 }
419 return value;
420 }
421
422 dynamic fold(dynamic initialValue,
423 dynamic combine(dynamic initialValue, element)) {
424 var len = this.length;
425 for (var i = 0; i < len; ++i) {
426 initialValue = combine(initialValue, this[i]);
427 }
428 return initialValue;
429 }
430
431 Iterable map(f(element)) => new MappedIterable(this, f);
432
433 Iterable expand(Iterable f(element)) => new ExpandIterable(this, f);
434
435 bool every(bool f(element)) {
436 var len = this.length;
437 for (var i = 0; i < len; ++i) {
438 if (!f(this[i])) return false;
439 }
440 return true;
441 }
442
443 bool any(bool f(element)) {
444 var len = this.length;
445 for (var i = 0; i < len; ++i) {
446 if (f(this[i])) return true;
447 }
448 return false;
449 }
450
451 dynamic firstWhere(bool test(element), {orElse()}) {
452 var len = this.length;
453 for (var i = 0; i < len; ++i) {
454 var element = this[i];
455 if (test(element)) return element;
456 }
457 if (orElse != null) return orElse();
458 throw IterableElementError.noElement();
459 }
460
461 dynamic lastWhere(bool test(element), {orElse()}) {
462 var result = null;
463 var len = this.length;
464 for (var i = len - 1; i >= 0; --i) {
465 var element = this[i];
466 if (test(element)) {
467 return element;
468 }
469 }
470 if (orElse != null) return orElse();
471 throw IterableElementError.noElement();
472 }
473
474 dynamic singleWhere(bool test(element)) {
475 var result = null;
476 bool foundMatching = false;
477 var len = this.length;
478 for (var i = 0; i < len; ++i) {
479 var element = this[i];
480 if (test(element)) {
481 if (foundMatching) {
482 throw IterableElementError.tooMany();
483 }
484 result = element;
485 foundMatching = true;
486 }
487 }
488 if (foundMatching) return result;
489 throw IterableElementError.noElement();
490 }
491
492 dynamic elementAt(int index) {
493 return this[index];
494 }
495
496 bool get isEmpty {
497 return this.length == 0;
498 }
499
500 bool get isNotEmpty => !isEmpty;
501
502 // Method(s) implementing the List interface.
503
504 set length(newLength) {
505 throw new UnsupportedError(
506 "Cannot resize a fixed-length list");
507 }
508
509 void add(value) {
510 throw new UnsupportedError(
511 "Cannot add to a fixed-length list");
512 }
513
514 void addAll(Iterable value) {
515 throw new UnsupportedError(
516 "Cannot add to a fixed-length list");
517 }
518
519 void insert(int index, value) {
520 throw new UnsupportedError(
521 "Cannot insert into a fixed-length list");
522 }
523
524 void insertAll(int index, Iterable values) {
525 throw new UnsupportedError(
526 "Cannot insert into a fixed-length list");
527 }
528
529 void sort([int compare(a, b)]) {
530 if (compare == null) compare = Comparable.compare;
531 Sort.sort(this, compare);
532 }
533
534 void shuffle([Random random]) {
535 if (random == null) random = new Random();
536 var i = this.length;
537 while (i > 1) {
538 int pos = random.nextInt(i);
539 i -= 1;
540 var tmp = this[i];
541 this[i] = this[pos];
542 this[pos] = tmp;
543 }
544 }
545
546 int indexOf(element, [int start = 0]) {
547 return Lists.indexOf(this, element, start, this.length);
548 }
549
550 int lastIndexOf(element, [int start = null]) {
551 if (start == null) start = this.length - 1;
552 return Lists.lastIndexOf(this, element, start);
553 }
554
555 void clear() {
556 throw new UnsupportedError(
557 "Cannot remove from a fixed-length list");
558 }
559
560 int removeLast() {
561 throw new UnsupportedError(
562 "Cannot remove from a fixed-length list");
563 }
564
565 bool remove(Object element) {
566 throw new UnsupportedError(
567 "Cannot remove from a fixed-length list");
568 }
569
570 bool removeAt(int index) {
571 throw new UnsupportedError(
572 "Cannot remove from a fixed-length list");
573 }
574
575 void removeWhere(bool test(element)) {
576 throw new UnsupportedError(
577 "Cannot remove from a fixed-length list");
578 }
579
580 void retainWhere(bool test(element)) {
581 throw new UnsupportedError(
582 "Cannot remove from a fixed-length list");
583 }
584
585 dynamic get first {
586 if (length > 0) return this[0];
587 throw IterableElementError.noElement();
588 }
589
590 dynamic get last {
591 if (length > 0) return this[length - 1];
592 throw IterableElementError.noElement();
593 }
594
595 dynamic get single {
596 if (length == 1) return this[0];
597 if (length == 0) throw IterableElementError.noElement();
598 throw IterableElementError.tooMany();
599 }
600
601 void removeRange(int start, int end) {
602 throw new UnsupportedError(
603 "Cannot remove from a fixed-length list");
604 }
605
606 void replaceRange(int start, int end, Iterable iterable) {
607 throw new UnsupportedError(
608 "Cannot remove from a fixed-length list");
609 }
610
611 List toList({bool growable: true}) {
612 return new List.from(this, growable: growable);
613 }
614
615 Set toSet() {
616 return new Set.from(this);
617 }
618
619 List sublist(int start, [int end]) {
620 end = RangeError.checkValidRange(start, end, this.length);
621 var length = end - start;
622 List result = _createList(length);
623 result.setRange(0, length, this, start);
624 return result;
625 }
626
627 void setRange(int start, int end, Iterable from, [int skipCount = 0]) {
628 // Check ranges.
629 if (0 > start || start > end || end > length) {
630 RangeError.checkValidRange(start, end, length); // Always throws.
631 assert(false);
632 }
633 if (skipCount < 0) {
634 throw new ArgumentError(skipCount);
635 }
636
637 final count = end - start;
638 if ((from.length - skipCount) < count) {
639 throw IterableElementError.tooFew();
640 }
641
642 if (from is _TypedListBase) {
643 if (this.elementSizeInBytes == from.elementSizeInBytes) {
644 if ((count < 10) && (from.buffer != this.buffer)) {
645 Lists.copy(from, skipCount, this, start, count);
646 return;
647 } else if (this.buffer._data._setRange(
648 start * elementSizeInBytes + this.offsetInBytes,
649 count * elementSizeInBytes,
650 from.buffer._data,
651 skipCount * elementSizeInBytes + from.offsetInBytes,
652 ClassID.getID(this), ClassID.getID(from))) {
653 return;
654 }
655 } else if (from.buffer == this.buffer) {
656 // Different element sizes, but same buffer means that we need
657 // an intermediate structure.
658 // TODO(srdjan): Optimize to skip copying if the range does not overlap.
659 final temp_buffer = new List(count);
660 for (var i = 0; i < count; i++) {
661 temp_buffer[i] = from[skipCount + i];
662 }
663 for (var i = start; i < end; i++) {
664 this[i] = temp_buffer[i - start];
665 }
666 return;
667 }
668 }
669
670 if (count == 0) return;
671 List otherList;
672 int otherStart;
673 if (from is List) {
674 otherList = from;
675 otherStart = skipCount;
676 } else {
677 otherList = from.skip(skipCount).toList(growable: false);
678 otherStart = 0;
679 }
680 if (otherStart + count > otherList.length) {
681 throw IterableElementError.tooFew();
682 }
683 Lists.copy(otherList, otherStart, this, start, count);
684 }
685
686 void setAll(int index, Iterable iterable) {
687 final end = iterable.length + index;
688 setRange(index, end, iterable);
689 }
690
691 void fillRange(int start, int end, [fillValue]) {
692 RangeError.checkValidRange(start, end, this.length);
693 for (var i = start; i < end; ++i) {
694 this[i] = fillValue;
695 }
696 }
697
698
699 // Method(s) implementing Object interface.
700
701 String toString() => ListBase.listToString(this);
702
703
704 // Internal utility methods.
705
706 // Returns true if operation succeeds.
707 // 'fromCid' and 'toCid' may be cid-s of the views and therefore may not
708 // match the cids of 'this' and 'from'.
709 // Uses toCid and fromCid to decide if clamping is necessary.
710 // Element size of toCid and fromCid must match (test at caller).
711 bool _setRange(int startInBytes, int lengthInBytes,
712 _TypedListBase from, int startFromInBytes,
713 int toCid, int fromCid)
714 native "TypedData_setRange";
715 }
716
717
718 class _IntListMixin {
719 Iterable<int> where(bool f(int element)) => new WhereIterable<int>(this, f);
720
721 Iterable<int> take(int n) => new SubListIterable<int>(this, 0, n);
722
723 Iterable<int> takeWhile(bool test(int element)) =>
724 new TakeWhileIterable<int>(this, test);
725
726 Iterable<int> skip(int n) => new SubListIterable<int>(this, n, null);
727
728 Iterable<int> skipWhile(bool test(element)) =>
729 new SkipWhileIterable<int>(this, test);
730
731 Iterable<int> get reversed => new ReversedListIterable<int>(this);
732
733 Map<int, int> asMap() => new ListMapView<int>(this);
734
735 Iterable<int> getRange(int start, [int end]) {
736 RangeError.checkValidRange(start, end, this.length);
737 return new SubListIterable<int>(this, start, end);
738 }
739
740 Iterator<int> get iterator => new _TypedListIterator<int>(this);
741
742 List<int> toList({bool growable: true}) {
743 return new List<int>.from(this, growable: growable);
744 }
745
746 Set<int> toSet() {
747 return new Set<int>.from(this);
748 }
749 }
750
751
752 class _DoubleListMixin {
753 Iterable<double> where(bool f(int element)) =>
754 new WhereIterable<double>(this, f);
755
756 Iterable<double> take(int n) => new SubListIterable<double>(this, 0, n);
757
758 Iterable<double> takeWhile(bool test(int element)) =>
759 new TakeWhileIterable<double>(this, test);
760
761 Iterable<double> skip(int n) => new SubListIterable<double>(this, n, null);
762
763 Iterable<double> skipWhile(bool test(element)) =>
764 new SkipWhileIterable<double>(this, test);
765
766 Iterable<double> get reversed => new ReversedListIterable<double>(this);
767
768 Map<int, double> asMap() => new ListMapView<double>(this);
769
770 Iterable<double> getRange(int start, [int end]) {
771 RangeError.checkValidRange(start, end, this.length);
772 return new SubListIterable<double>(this, start, end);
773 }
774
775 Iterator<double> get iterator => new _TypedListIterator<double>(this);
776
777 List<double> toList({bool growable: true}) {
778 return new List<double>.from(this, growable: growable);
779 }
780
781 Set<double> toSet() {
782 return new Set<double>.from(this);
783 }
784 }
785
786
787 class _Float32x4ListMixin {
788 Iterable<Float32x4> where(bool f(int element)) =>
789 new WhereIterable<Float32x4>(this, f);
790
791 Iterable<Float32x4> take(int n) => new SubListIterable<Float32x4>(this, 0, n);
792
793 Iterable<Float32x4> takeWhile(bool test(int element)) =>
794 new TakeWhileIterable<Float32x4>(this, test);
795
796 Iterable<Float32x4> skip(int n) =>
797 new SubListIterable<Float32x4>(this, n, null);
798
799 Iterable<Float32x4> skipWhile(bool test(element)) =>
800 new SkipWhileIterable<Float32x4>(this, test);
801
802 Iterable<Float32x4> get reversed => new ReversedListIterable<Float32x4>(this);
803
804 Map<int, Float32x4> asMap() => new ListMapView<Float32x4>(this);
805
806 Iterable<Float32x4> getRange(int start, [int end]) {
807 RangeError.checkValidRange(start, end, this.length);
808 return new SubListIterable<Float32x4>(this, start, end);
809 }
810
811 Iterator<Float32x4> get iterator => new _TypedListIterator<Float32x4>(this);
812
813 List<Float32x4> toList({bool growable: true}) {
814 return new List<Float32x4>.from(this, growable: growable);
815 }
816
817 Set<Float32x4> toSet() {
818 return new Set<Float32x4>.from(this);
819 }
820 }
821
822
823 class _Int32x4ListMixin {
824 Iterable<Int32x4> where(bool f(int element)) =>
825 new WhereIterable<Int32x4>(this, f);
826
827 Iterable<Int32x4> take(int n) => new SubListIterable<Int32x4>(this, 0, n);
828
829 Iterable<Int32x4> takeWhile(bool test(int element)) =>
830 new TakeWhileIterable<Int32x4>(this, test);
831
832 Iterable<Int32x4> skip(int n) => new SubListIterable<Int32x4>(this, n, null);
833
834 Iterable<Int32x4> skipWhile(bool test(element)) =>
835 new SkipWhileIterable<Int32x4>(this, test);
836
837 Iterable<Int32x4> get reversed => new ReversedListIterable<Int32x4>(this);
838
839 Map<int, Int32x4> asMap() => new ListMapView<Int32x4>(this);
840
841 Iterable<Int32x4> getRange(int start, [int end]) {
842 RangeError.checkValidRange(start, end, this.length);
843 return new SubListIterable<Int32x4>(this, start, end);
844 }
845
846 Iterator<Int32x4> get iterator => new _TypedListIterator<Int32x4>(this);
847
848 List<Int32x4> toList({bool growable: true}) {
849 return new List<Int32x4>.from(this, growable: growable);
850 }
851
852 Set<Int32x4> toSet() {
853 return new Set<Int32x4>.from(this);
854 }
855 }
856
857
858 class _Float64x2ListMixin {
859 Iterable<Float64x2> where(bool f(int element)) =>
860 new WhereIterable<Float64x2>(this, f);
861
862 Iterable<Float64x2> take(int n) => new SubListIterable<Float64x2>(this, 0, n);
863
864 Iterable<Float64x2> takeWhile(bool test(int element)) =>
865 new TakeWhileIterable<Float64x2>(this, test);
866
867 Iterable<Float64x2> skip(int n) =>
868 new SubListIterable<Float64x2>(this, n, null);
869
870 Iterable<Float64x2> skipWhile(bool test(element)) =>
871 new SkipWhileIterable<Float64x2>(this, test);
872
873 Iterable<Float64x2> get reversed => new ReversedListIterable<Float64x2>(this);
874
875 Map<int, Float64x2> asMap() => new ListMapView<Float64x2>(this);
876
877 Iterable<Float64x2> getRange(int start, [int end]) {
878 RangeError.checkValidRange(start, end, this.length);
879 return new SubListIterable<Float64x2>(this, start, end);
880 }
881
882 Iterator<Float64x2> get iterator => new _TypedListIterator<Float64x2>(this);
883
884 List<Float64x2> toList({bool growable: true}) {
885 return new List<Float64x2>.from(this, growable: growable);
886 }
887
888 Set<Float64x2> toSet() {
889 return new Set<Float64x2>.from(this);
890 }
891 }
892
893
894 class ByteBuffer {
895 final _TypedList _data;
896
897 ByteBuffer(this._data);
898
899 factory ByteBuffer._New(data) => new ByteBuffer(data);
900
901 // Forward calls to _data.
902 int get lengthInBytes => _data.lengthInBytes;
903 int get hashCode => _data.hashCode;
904 bool operator==(Object other) =>
905 (other is ByteBuffer) && identical(_data, other._data);
906
907 ByteData asByteData([int offsetInBytes = 0, int length]) {
908 if (length == null) {
909 length = this.lengthInBytes - offsetInBytes;
910 }
911 return new _ByteDataView(this._data, offsetInBytes, length);
912 }
913
914 Int8List asInt8List([int offsetInBytes = 0, int length]) {
915 if (length == null) {
916 length = this.lengthInBytes - offsetInBytes;
917 }
918 return new _Int8ArrayView(this, offsetInBytes, length);
919 }
920
921 Uint8List asUint8List([int offsetInBytes = 0, int length]) {
922 if (length == null) {
923 length = this.lengthInBytes - offsetInBytes;
924 }
925 return new _Uint8ArrayView(this, offsetInBytes, length);
926 }
927
928 Uint8ClampedList asUint8ClampedList([int offsetInBytes = 0, int length]) {
929 if (length == null) {
930 length = this.lengthInBytes - offsetInBytes;
931 }
932 return new _Uint8ClampedArrayView(this, offsetInBytes, length);
933 }
934
935 Int16List asInt16List([int offsetInBytes = 0, int length]) {
936 if (length == null) {
937 length = (this.lengthInBytes - offsetInBytes) ~/
938 Int16List.BYTES_PER_ELEMENT;
939 }
940 return new _Int16ArrayView(this, offsetInBytes, length);
941 }
942
943 Uint16List asUint16List([int offsetInBytes = 0, int length]) {
944 if (length == null) {
945 length = (this.lengthInBytes - offsetInBytes) ~/
946 Uint16List.BYTES_PER_ELEMENT;
947 }
948 return new _Uint16ArrayView(this, offsetInBytes, length);
949 }
950
951 Int32List asInt32List([int offsetInBytes = 0, int length]) {
952 if (length == null) {
953 length = (this.lengthInBytes - offsetInBytes) ~/
954 Int32List.BYTES_PER_ELEMENT;
955 }
956 return new _Int32ArrayView(this, offsetInBytes, length);
957 }
958
959 Uint32List asUint32List([int offsetInBytes = 0, int length]) {
960 if (length == null) {
961 length = (this.lengthInBytes - offsetInBytes) ~/
962 Uint32List.BYTES_PER_ELEMENT;
963 }
964 return new _Uint32ArrayView(this, offsetInBytes, length);
965 }
966
967 Int64List asInt64List([int offsetInBytes = 0, int length]) {
968 if (length == null) {
969 length = (this.lengthInBytes - offsetInBytes) ~/
970 Int64List.BYTES_PER_ELEMENT;
971 }
972 return new _Int64ArrayView(this, offsetInBytes, length);
973 }
974
975 Uint64List asUint64List([int offsetInBytes = 0, int length]) {
976 if (length == null) {
977 length = (this.lengthInBytes - offsetInBytes) ~/
978 Uint64List.BYTES_PER_ELEMENT;
979 }
980 return new _Uint64ArrayView(this, offsetInBytes, length);
981 }
982
983 Float32List asFloat32List([int offsetInBytes = 0, int length]) {
984 if (length == null) {
985 length = (this.lengthInBytes - offsetInBytes) ~/
986 Float32List.BYTES_PER_ELEMENT;
987 }
988 return new _Float32ArrayView(this, offsetInBytes, length);
989 }
990
991 Float64List asFloat64List([int offsetInBytes = 0, int length]) {
992 if (length == null) {
993 length = (this.lengthInBytes - offsetInBytes) ~/
994 Float64List.BYTES_PER_ELEMENT;
995 }
996 return new _Float64ArrayView(this, offsetInBytes, length);
997 }
998
999 Float32x4List asFloat32x4List([int offsetInBytes = 0, int length]) {
1000 if (length == null) {
1001 length = (this.lengthInBytes - offsetInBytes) ~/
1002 Float32x4List.BYTES_PER_ELEMENT;
1003 }
1004 return new _Float32x4ArrayView(this, offsetInBytes, length);
1005 }
1006
1007 Int32x4List asInt32x4List([int offsetInBytes = 0, int length]) {
1008 if (length == null) {
1009 length = (this.lengthInBytes - offsetInBytes) ~/
1010 Int32x4List.BYTES_PER_ELEMENT;
1011 }
1012 return new _Int32x4ArrayView(this, offsetInBytes, length);
1013 }
1014
1015 Float64x2List asFloat64x2List([int offsetInBytes = 0, int length]) {
1016 if (length == null) {
1017 length = (this.lengthInBytes - offsetInBytes) ~/
1018 Float64x2List.BYTES_PER_ELEMENT;
1019 }
1020 return new _Float64x2ArrayView(this, offsetInBytes, length);
1021 }
1022 }
1023
1024
1025 abstract class _TypedList extends _TypedListBase {
1026 // Default method implementing parts of the TypedData interface.
1027 int get offsetInBytes {
1028 return 0;
1029 }
1030
1031 int get lengthInBytes {
1032 return length * elementSizeInBytes;
1033 }
1034
1035 ByteBuffer get buffer => new ByteBuffer(this);
1036
1037 // Methods implementing the collection interface.
1038
1039 int get length native "TypedData_length";
1040
1041 // Internal utility methods.
1042
1043 int _getInt8(int offsetInBytes) native "TypedData_GetInt8";
1044 void _setInt8(int offsetInBytes, int value) native "TypedData_SetInt8";
1045
1046 int _getUint8(int offsetInBytes) native "TypedData_GetUint8";
1047 void _setUint8(int offsetInBytes, int value) native "TypedData_SetUint8";
1048
1049 int _getInt16(int offsetInBytes) native "TypedData_GetInt16";
1050 void _setInt16(int offsetInBytes, int value) native "TypedData_SetInt16";
1051
1052 int _getUint16(int offsetInBytes) native "TypedData_GetUint16";
1053 void _setUint16(int offsetInBytes, int value) native "TypedData_SetUint16";
1054
1055 int _getInt32(int offsetInBytes) native "TypedData_GetInt32";
1056 void _setInt32(int offsetInBytes, int value) native "TypedData_SetInt32";
1057
1058 int _getUint32(int offsetInBytes) native "TypedData_GetUint32";
1059 void _setUint32(int offsetInBytes, int value) native "TypedData_SetUint32";
1060
1061 int _getInt64(int offsetInBytes) native "TypedData_GetInt64";
1062 void _setInt64(int offsetInBytes, int value) native "TypedData_SetInt64";
1063
1064 int _getUint64(int offsetInBytes) native "TypedData_GetUint64";
1065 void _setUint64(int offsetInBytes, int value) native "TypedData_SetUint64";
1066
1067 double _getFloat32(int offsetInBytes) native "TypedData_GetFloat32";
1068 void _setFloat32(int offsetInBytes, double value)
1069 native "TypedData_SetFloat32";
1070
1071 double _getFloat64(int offsetInBytes) native "TypedData_GetFloat64";
1072 void _setFloat64(int offsetInBytes, double value)
1073 native "TypedData_SetFloat64";
1074
1075 Float32x4 _getFloat32x4(int offsetInBytes) native "TypedData_GetFloat32x4";
1076 void _setFloat32x4(int offsetInBytes, Float32x4 value)
1077 native "TypedData_SetFloat32x4";
1078
1079 Int32x4 _getInt32x4(int offsetInBytes) native "TypedData_GetInt32x4";
1080 void _setInt32x4(int offsetInBytes, Int32x4 value)
1081 native "TypedData_SetInt32x4";
1082
1083 Float64x2 _getFloat64x2(int offsetInBytes) native "TypedData_GetFloat64x2";
1084 void _setFloat64x2(int offsetInBytes, Float64x2 value)
1085 native "TypedData_SetFloat64x2";
1086
1087 /**
1088 * Stores the [CodeUnits] as UTF-16 units into this TypedData at
1089 * positions [start]..[end] (uint16 indices).
1090 */
1091 void _setCodeUnits(CodeUnits units,
1092 int byteStart, int length, int skipCount) {
1093 assert(byteStart + length * Uint16List.BYTES_PER_ELEMENT <= lengthInBytes);
1094 String string = CodeUnits.stringOf(units);
1095 int sliceEnd = skipCount + length;
1096 RangeError.checkValidRange(skipCount, sliceEnd,
1097 string.length,
1098 "skipCount", "skipCount + length");
1099 for (int i = 0; i < length; i++) {
1100 _setUint16(byteStart + i * Uint16List.BYTES_PER_ELEMENT,
1101 string.codeUnitAt(skipCount + i));
1102 }
1103 }
1104 }
1105
1106
1107 class Int8List extends _TypedList with _IntListMixin implements List<int>, Typed Data {
1108 // Factory constructors.
1109
1110 factory Int8List(int length) native "TypedData_Int8Array_new";
1111
1112 factory Int8List.fromList(List<int> elements) {
1113 return new Int8List(elements.length)
1114 ..setRange(0, elements.length, elements);
1115 }
1116
1117 factory Int8List.view(ByteBuffer buffer,
1118 [int offsetInBytes = 0, int length]) {
1119 return buffer.asInt8List(offsetInBytes, length);
1120 }
1121
1122 // Method(s) implementing List interface.
1123
1124 int operator[](int index) {
1125 if (index < 0 || index >= length) {
1126 throw new RangeError.index(index, this, "index");
1127 }
1128 return _getInt8(index);
1129 }
1130
1131 void operator[]=(int index, int value) {
1132 if (index < 0 || index >= length) {
1133 throw new RangeError.index(index, this, "index");
1134 }
1135 _setInt8(index, _toInt8(value));
1136 }
1137
1138 static const int BYTES_PER_ELEMENT = 1;
1139
1140 // Method(s) implementing TypedData interface.
1141
1142 int get elementSizeInBytes {
1143 return Int8List.BYTES_PER_ELEMENT;
1144 }
1145
1146
1147 // Internal utility methods.
1148
1149 Int8List _createList(int length) {
1150 return new Int8List(length);
1151 }
1152 }
1153
1154
1155 class Uint8List extends _TypedList with _IntListMixin implements List<int>, Type dData {
1156 // Factory constructors.
1157
1158 factory Uint8List(int length) native "TypedData_Uint8Array_new";
1159
1160 factory Uint8List.fromList(List<int> elements) {
1161 return new Uint8List(elements.length)
1162 ..setRange(0, elements.length, elements);
1163 }
1164
1165 factory Uint8List.view(ByteBuffer buffer,
1166 [int offsetInBytes = 0, int length]) {
1167 return buffer.asUint8List(offsetInBytes, length);
1168 }
1169
1170 // Methods implementing List interface.
1171 int operator[](int index) {
1172 if (index < 0 || index >= length) {
1173 throw new RangeError.index(index, this, "index");
1174 }
1175 return _getUint8(index);
1176 }
1177
1178 void operator[]=(int index, int value) {
1179 if (index < 0 || index >= length) {
1180 throw new RangeError.index(index, this, "index");
1181 }
1182 _setUint8(index, _toUint8(value));
1183 }
1184
1185 static const int BYTES_PER_ELEMENT = 1;
1186
1187 // Methods implementing TypedData interface.
1188 int get elementSizeInBytes {
1189 return Uint8List.BYTES_PER_ELEMENT;
1190 }
1191
1192 // Internal utility methods.
1193
1194 Uint8List _createList(int length) {
1195 return new Uint8List(length);
1196 }
1197 }
1198
1199
1200 class Uint8ClampedList extends _TypedList with _IntListMixin implements List<int >, TypedData {
1201 // Factory constructors.
1202
1203 factory Uint8ClampedList(int length) native "TypedData_Uint8ClampedArray_new";
1204
1205 factory Uint8ClampedList.fromList(List<int> elements) {
1206 return new Uint8ClampedList(elements.length)
1207 ..setRange(0, elements.length, elements);
1208 }
1209
1210 factory Uint8ClampedList.view(ByteBuffer buffer,
1211 [int offsetInBytes = 0, int length]) {
1212 return buffer.asUint8ClampedList(offsetInBytes, length);
1213 }
1214
1215 // Methods implementing List interface.
1216
1217 int operator[](int index) {
1218 if (index < 0 || index >= length) {
1219 throw new RangeError.index(index, this, "index");
1220 }
1221 return _getUint8(index);
1222 }
1223
1224 void operator[]=(int index, int value) {
1225 if (index < 0 || index >= length) {
1226 throw new RangeError.index(index, this, "index");
1227 }
1228 _setUint8(index, _toClampedUint8(value));
1229 }
1230
1231 static const int BYTES_PER_ELEMENT = 1;
1232
1233 // Methods implementing TypedData interface.
1234 int get elementSizeInBytes {
1235 return Uint8List.BYTES_PER_ELEMENT;
1236 }
1237
1238
1239 // Internal utility methods.
1240
1241 Uint8ClampedList _createList(int length) {
1242 return new Uint8ClampedList(length);
1243 }
1244 }
1245
1246
1247 class Int16List extends _TypedList with _IntListMixin implements List<int>, Type dData {
1248 // Factory constructors.
1249
1250 factory Int16List(int length) native "TypedData_Int16Array_new";
1251
1252 factory Int16List.fromList(List<int> elements) {
1253 return new Int16List(elements.length)
1254 ..setRange(0, elements.length, elements);
1255 }
1256
1257 factory Int16List.view(ByteBuffer buffer,
1258 [int offsetInBytes = 0, int length]) {
1259 return buffer.asInt16List(offsetInBytes, length);
1260 }
1261
1262 // Method(s) implementing List interface.
1263
1264 int operator[](int index) {
1265 if (index < 0 || index >= length) {
1266 throw new RangeError.index(index, this, "index");
1267 }
1268 return _getIndexedInt16(index);
1269 }
1270
1271 void operator[]=(int index, int value) {
1272 if (index < 0 || index >= length) {
1273 throw new RangeError.index(index, this, "index");
1274 }
1275 _setIndexedInt16(index, _toInt16(value));
1276 }
1277
1278 void setRange(int start, int end, Iterable iterable, [int skipCount = 0]) {
1279 if (iterable is CodeUnits) {
1280 end = RangeError.checkValidRange(start, end, this.length);
1281 int length = end - start;
1282 int byteStart = this.offsetInBytes + start * Int16List.BYTES_PER_ELEMENT;
1283 _setCodeUnits(iterable, byteStart, length, skipCount);
1284 } else {
1285 super.setRange(start, end, iterable, skipCount);
1286 }
1287 }
1288
1289 // Method(s) implementing TypedData interface.
1290 static const int BYTES_PER_ELEMENT = 2;
1291
1292 int get elementSizeInBytes {
1293 return Int16List.BYTES_PER_ELEMENT;
1294 }
1295
1296
1297 // Internal utility methods.
1298
1299 Int16List _createList(int length) {
1300 return new Int16List(length);
1301 }
1302
1303 int _getIndexedInt16(int index) {
1304 return _getInt16(index * Int16List.BYTES_PER_ELEMENT);
1305 }
1306
1307 void _setIndexedInt16(int index, int value) {
1308 _setInt16(index * Int16List.BYTES_PER_ELEMENT, value);
1309 }
1310 }
1311
1312
1313 class Uint16List extends _TypedList with _IntListMixin implements List<int>, Typ edData {
1314 // Factory constructors.
1315
1316 factory Uint16List(int length) native "TypedData_Uint16Array_new";
1317
1318 factory Uint16List.fromList(List<int> elements) {
1319 return new Uint16List(elements.length)
1320 ..setRange(0, elements.length, elements);
1321 }
1322
1323 factory Uint16List.view(ByteBuffer buffer,
1324 [int offsetInBytes = 0, int length]) {
1325 return buffer.asUint16List(offsetInBytes, length);
1326 }
1327
1328 // Method(s) implementing the List interface.
1329
1330 int operator[](int index) {
1331 if (index < 0 || index >= length) {
1332 throw new RangeError.index(index, this, "index");
1333 }
1334 return _getIndexedUint16(index);
1335 }
1336
1337 void operator[]=(int index, int value) {
1338 if (index < 0 || index >= length) {
1339 throw new RangeError.index(index, this, "index");
1340 }
1341 _setIndexedUint16(index, _toUint16(value));
1342 }
1343
1344 void setRange(int start, int end, Iterable iterable, [int skipCount = 0]) {
1345 if (iterable is CodeUnits) {
1346 end = RangeError.checkValidRange(start, end, this.length);
1347 int length = end - start;
1348 int byteStart = this.offsetInBytes + start * Uint16List.BYTES_PER_ELEMENT;
1349 _setCodeUnits(iterable, byteStart, length, skipCount);
1350 } else {
1351 super.setRange(start, end, iterable, skipCount);
1352 }
1353 }
1354
1355 // Method(s) implementing the TypedData interface.
1356 static const int BYTES_PER_ELEMENT = 2;
1357
1358 int get elementSizeInBytes {
1359 return Uint16List.BYTES_PER_ELEMENT;
1360 }
1361
1362
1363 // Internal utility methods.
1364
1365 Uint16List _createList(int length) {
1366 return new Uint16List(length);
1367 }
1368
1369 int _getIndexedUint16(int index) {
1370 return _getUint16(index * Uint16List.BYTES_PER_ELEMENT);
1371 }
1372
1373 void _setIndexedUint16(int index, int value) {
1374 _setUint16(index * Uint16List.BYTES_PER_ELEMENT, value);
1375 }
1376 }
1377
1378
1379 class Int32List extends _TypedList with _IntListMixin implements List<int>, Type dData {
1380 // Factory constructors.
1381
1382 factory Int32List(int length) native "TypedData_Int32Array_new";
1383
1384 factory Int32List.fromList(List<int> elements) {
1385 return new Int32List(elements.length)
1386 ..setRange(0, elements.length, elements);
1387 }
1388
1389 factory Int32List.view(ByteBuffer buffer,
1390 [int offsetInBytes = 0, int length]) {
1391 return buffer.asInt32List(offsetInBytes, length);
1392 }
1393
1394 // Method(s) implementing the List interface.
1395
1396 int operator[](int index) {
1397 if (index < 0 || index >= length) {
1398 throw new RangeError.index(index, this, "index");
1399 }
1400 return _getIndexedInt32(index);
1401 }
1402
1403 void operator[]=(int index, int value) {
1404 if (index < 0 || index >= length) {
1405 throw new RangeError.index(index, this, "index");
1406 }
1407 _setIndexedInt32(index, _toInt32(value));
1408 }
1409
1410
1411 // Method(s) implementing TypedData interface.
1412 static const int BYTES_PER_ELEMENT = 4;
1413
1414 int get elementSizeInBytes {
1415 return Int32List.BYTES_PER_ELEMENT;
1416 }
1417
1418
1419 // Internal utility methods.
1420
1421 Int32List _createList(int length) {
1422 return new Int32List(length);
1423 }
1424
1425 int _getIndexedInt32(int index) {
1426 return _getInt32(index * Int32List.BYTES_PER_ELEMENT);
1427 }
1428
1429 void _setIndexedInt32(int index, int value) {
1430 _setInt32(index * Int32List.BYTES_PER_ELEMENT, value);
1431 }
1432
1433 }
1434
1435
1436 class Uint32List extends _TypedList with _IntListMixin implements List<int>, Typ edData {
1437 // Factory constructors.
1438
1439 factory Uint32List(int length) native "TypedData_Uint32Array_new";
1440
1441 factory Uint32List.fromList(List<int> elements) {
1442 return new Uint32List(elements.length)
1443 ..setRange(0, elements.length, elements);
1444 }
1445
1446 factory Uint32List.view(ByteBuffer buffer,
1447 [int offsetInBytes = 0, int length]) {
1448 return buffer.asUint32List(offsetInBytes, length);
1449 }
1450
1451 // Method(s) implementing the List interface.
1452
1453 int operator[](int index) {
1454 if (index < 0 || index >= length) {
1455 throw new RangeError.index(index, this, "index");
1456 }
1457 return _getIndexedUint32(index);
1458 }
1459
1460 void operator[]=(int index, int value) {
1461 if (index < 0 || index >= length) {
1462 throw new RangeError.index(index, this, "index");
1463 }
1464 _setIndexedUint32(index, _toUint32(value));
1465 }
1466
1467
1468 // Method(s) implementing the TypedData interface.
1469 static const int BYTES_PER_ELEMENT = 4;
1470
1471 int get elementSizeInBytes {
1472 return Uint32List.BYTES_PER_ELEMENT;
1473 }
1474
1475
1476 // Internal utility methods.
1477
1478 Uint32List _createList(int length) {
1479 return new Uint32List(length);
1480 }
1481
1482 int _getIndexedUint32(int index) {
1483 return _getUint32(index * Uint32List.BYTES_PER_ELEMENT);
1484 }
1485
1486 void _setIndexedUint32(int index, int value) {
1487 _setUint32(index * Uint32List.BYTES_PER_ELEMENT, value);
1488 }
1489 }
1490
1491
1492 class Int64List extends _TypedList with _IntListMixin implements List<int>, Type dData {
1493 // Factory constructors.
1494
1495 factory Int64List(int length) native "TypedData_Int64Array_new";
1496
1497 factory Int64List.fromList(List<int> elements) {
1498 return new Int64List(elements.length)
1499 ..setRange(0, elements.length, elements);
1500 }
1501
1502 factory Int64List.view(ByteBuffer buffer,
1503 [int offsetInBytes = 0, int length]) {
1504 return buffer.asInt64List(offsetInBytes, length);
1505 }
1506
1507 // Method(s) implementing the List interface.
1508
1509 int operator[](int index) {
1510 if (index < 0 || index >= length) {
1511 throw new RangeError.index(index, this, "index");
1512 }
1513 return _getIndexedInt64(index);
1514 }
1515
1516 void operator[]=(int index, int value) {
1517 if (index < 0 || index >= length) {
1518 throw new RangeError.index(index, this, "index");
1519 }
1520 _setIndexedInt64(index, _toInt64(value));
1521 }
1522
1523
1524 // Method(s) implementing the TypedData interface.
1525 static const int BYTES_PER_ELEMENT = 8;
1526
1527 int get elementSizeInBytes {
1528 return Int64List.BYTES_PER_ELEMENT;
1529 }
1530
1531
1532 // Internal utility methods.
1533
1534 Int64List _createList(int length) {
1535 return new Int64List(length);
1536 }
1537
1538 int _getIndexedInt64(int index) {
1539 return _getInt64(index * Int64List.BYTES_PER_ELEMENT);
1540 }
1541
1542 void _setIndexedInt64(int index, int value) {
1543 _setInt64(index * Int64List.BYTES_PER_ELEMENT, value);
1544 }
1545 }
1546
1547
1548 class Uint64List extends _TypedList with _IntListMixin implements List<int>, Typ edData {
1549 // Factory constructors.
1550
1551 factory Uint64List(int length) native "TypedData_Uint64Array_new";
1552
1553 factory Uint64List.fromList(List<int> elements) {
1554 return new Uint64List(elements.length)
1555 ..setRange(0, elements.length, elements);
1556 }
1557
1558 factory Uint64List.view(ByteBuffer buffer,
1559 [int offsetInBytes = 0, int length]) {
1560 return buffer.asUint64List(offsetInBytes, length);
1561 }
1562
1563 // Method(s) implementing the List interface.
1564
1565 int operator[](int index) {
1566 if (index < 0 || index >= length) {
1567 throw new RangeError.index(index, this, "index");
1568 }
1569 return _getIndexedUint64(index);
1570 }
1571
1572 void operator[]=(int index, int value) {
1573 if (index < 0 || index >= length) {
1574 throw new RangeError.index(index, this, "index");
1575 }
1576 _setIndexedUint64(index, _toUint64(value));
1577 }
1578
1579
1580 // Method(s) implementing the TypedData interface.
1581 static const int BYTES_PER_ELEMENT = 8;
1582
1583 int get elementSizeInBytes {
1584 return Uint64List.BYTES_PER_ELEMENT;
1585 }
1586
1587
1588 // Internal utility methods.
1589
1590 Uint64List _createList(int length) {
1591 return new Uint64List(length);
1592 }
1593
1594 int _getIndexedUint64(int index) {
1595 return _getUint64(index * Uint64List.BYTES_PER_ELEMENT);
1596 }
1597
1598 void _setIndexedUint64(int index, int value) {
1599 _setUint64(index * Uint64List.BYTES_PER_ELEMENT, value);
1600 }
1601 }
1602
1603
1604 class Float32List extends _TypedList with _DoubleListMixin implements List<doubl e>, TypedData {
1605 // Factory constructors.
1606
1607 factory Float32List(int length) native "TypedData_Float32Array_new";
1608
1609 factory Float32List.fromList(List<double> elements) {
1610 return new Float32List(elements.length)
1611 ..setRange(0, elements.length, elements);
1612 }
1613
1614 factory Float32List.view(ByteBuffer buffer,
1615 [int offsetInBytes = 0, int length]) {
1616 return buffer.asFloat32List(offsetInBytes, length);
1617 }
1618
1619 // Method(s) implementing the List interface.
1620
1621 double operator[](int index) {
1622 if (index < 0 || index >= length) {
1623 throw new RangeError.index(index, this, "index");
1624 }
1625 return _getIndexedFloat32(index);
1626 }
1627
1628 void operator[]=(int index, double value) {
1629 if (index < 0 || index >= length) {
1630 throw new RangeError.index(index, this, "index");
1631 }
1632 _setIndexedFloat32(index, value);
1633 }
1634
1635
1636 // Method(s) implementing the TypedData interface.
1637 static const int BYTES_PER_ELEMENT = 4;
1638
1639 int get elementSizeInBytes {
1640 return Float32List.BYTES_PER_ELEMENT;
1641 }
1642
1643
1644 // Internal utility methods.
1645
1646 Float32List _createList(int length) {
1647 return new Float32List(length);
1648 }
1649
1650 double _getIndexedFloat32(int index) {
1651 return _getFloat32(index * Float32List.BYTES_PER_ELEMENT);
1652 }
1653
1654 void _setIndexedFloat32(int index, double value) {
1655 _setFloat32(index * Float32List.BYTES_PER_ELEMENT, value);
1656 }
1657 }
1658
1659
1660 class Float64List extends _TypedList with _DoubleListMixin implements List<doubl e>, TypedData {
1661 // Factory constructors.
1662
1663 factory Float64List(int length) native "TypedData_Float64Array_new";
1664
1665 factory Float64List.fromList(List<double> elements) {
1666 return new Float64List(elements.length)
1667 ..setRange(0, elements.length, elements);
1668 }
1669
1670 factory Float64List.view(ByteBuffer buffer,
1671 [int offsetInBytes = 0, int length]) {
1672 return buffer.asFloat64List(offsetInBytes, length);
1673 }
1674
1675 // Method(s) implementing the List interface.
1676
1677 double operator[](int index) {
1678 if (index < 0 || index >= length) {
1679 throw new RangeError.index(index, this, "index");
1680 }
1681 return _getIndexedFloat64(index);
1682 }
1683
1684 void operator[]=(int index, double value) {
1685 if (index < 0 || index >= length) {
1686 throw new RangeError.index(index, this, "index");
1687 }
1688 _setIndexedFloat64(index, value);
1689 }
1690
1691
1692 // Method(s) implementing the TypedData interface.
1693 static const int BYTES_PER_ELEMENT = 8;
1694
1695 int get elementSizeInBytes {
1696 return Float64List.BYTES_PER_ELEMENT;
1697 }
1698
1699
1700 // Internal utility methods.
1701
1702 Float64List _createList(int length) {
1703 return new Float64List(length);
1704 }
1705
1706 double _getIndexedFloat64(int index) {
1707 return _getFloat64(index * Float64List.BYTES_PER_ELEMENT);
1708 }
1709
1710 void _setIndexedFloat64(int index, double value) {
1711 _setFloat64(index * Float64List.BYTES_PER_ELEMENT, value);
1712 }
1713 }
1714
1715
1716 class Float32x4List extends _TypedList with _Float32x4ListMixin implements List< Float32x4>, TypedData {
1717 // Factory constructors.
1718
1719 factory Float32x4List(int length) native "TypedData_Float32x4Array_new";
1720
1721 factory Float32x4List.fromList(List<Float32x4> elements) {
1722 return new Float32x4List(elements.length)
1723 ..setRange(0, elements.length, elements);
1724 }
1725
1726 factory Float32x4List.view(ByteBuffer buffer,
1727 [int offsetInBytes = 0, int length]) {
1728 return buffer.asFloat32x4List(offsetInBytes, length);
1729 }
1730
1731 Float32x4 operator[](int index) {
1732 if (index < 0 || index >= length) {
1733 throw new RangeError.index(index, this, "index");
1734 }
1735 return _getIndexedFloat32x4(index);
1736 }
1737
1738 void operator[]=(int index, Float32x4 value) {
1739 if (index < 0 || index >= length) {
1740 throw new RangeError.index(index, this, "index");
1741 }
1742 _setIndexedFloat32x4(index, value);
1743 }
1744
1745
1746 // Method(s) implementing the TypedData interface.
1747 static const int BYTES_PER_ELEMENT = 16;
1748
1749 int get elementSizeInBytes {
1750 return Float32x4List.BYTES_PER_ELEMENT;
1751 }
1752
1753
1754 // Internal utility methods.
1755
1756 Float32x4List _createList(int length) {
1757 return new Float32x4List(length);
1758 }
1759
1760 Float32x4 _getIndexedFloat32x4(int index) {
1761 return _getFloat32x4(index * Float32x4List.BYTES_PER_ELEMENT);
1762 }
1763
1764 void _setIndexedFloat32x4(int index, Float32x4 value) {
1765 _setFloat32x4(index * Float32x4List.BYTES_PER_ELEMENT, value);
1766 }
1767 }
1768
1769
1770 class Int32x4List extends _TypedList with _Int32x4ListMixin implements List<Int3 2x4>, TypedData {
1771 // Factory constructors.
1772
1773 factory Int32x4List(int length) native "TypedData_Int32x4Array_new";
1774
1775 factory Int32x4List.fromList(List<Int32x4> elements) {
1776 return new Int32x4List(elements.length)
1777 ..setRange(0, elements.length, elements);
1778 }
1779
1780 factory Int32x4List.view(ByteBuffer buffer,
1781 [int offsetInBytes = 0, int length]) {
1782 return buffer.asInt32x4List(offsetInBytes, length);
1783 }
1784
1785 Int32x4 operator[](int index) {
1786 if (index < 0 || index >= length) {
1787 throw new RangeError.index(index, this, "index");
1788 }
1789 return _getIndexedInt32x4(index);
1790 }
1791
1792 void operator[]=(int index, Int32x4 value) {
1793 if (index < 0 || index >= length) {
1794 throw new RangeError.index(index, this, "index");
1795 }
1796 _setIndexedInt32x4(index, value);
1797 }
1798
1799
1800 // Method(s) implementing the TypedData interface.
1801 static const int BYTES_PER_ELEMENT = 16;
1802
1803 int get elementSizeInBytes {
1804 return Int32x4List.BYTES_PER_ELEMENT;
1805 }
1806
1807
1808 // Internal utility methods.
1809
1810 Int32x4List _createList(int length) {
1811 return new Int32x4List(length);
1812 }
1813
1814 Int32x4 _getIndexedInt32x4(int index) {
1815 return _getInt32x4(index * Int32x4List.BYTES_PER_ELEMENT);
1816 }
1817
1818 void _setIndexedInt32x4(int index, Int32x4 value) {
1819 _setInt32x4(index * Int32x4List.BYTES_PER_ELEMENT, value);
1820 }
1821 }
1822
1823
1824 class Float64x2List extends _TypedList with _Float64x2ListMixin implements List< Float64x2>, TypedData {
1825 // Factory constructors.
1826
1827 factory Float64x2List(int length) native "TypedData_Float64x2Array_new";
1828
1829 factory Float64x2List.fromList(List<Float64x2> elements) {
1830 return new Float64x2List(elements.length)
1831 ..setRange(0, elements.length, elements);
1832 }
1833
1834 factory Float64x2List.view(ByteBuffer buffer,
1835 [int offsetInBytes = 0, int length]) {
1836 return buffer.asFloat64x2List(offsetInBytes, length);
1837 }
1838
1839 Float64x2 operator[](int index) {
1840 if (index < 0 || index >= length) {
1841 throw new RangeError.index(index, this, "index");
1842 }
1843 return _getIndexedFloat64x2(index);
1844 }
1845
1846 void operator[]=(int index, Float64x2 value) {
1847 if (index < 0 || index >= length) {
1848 throw new RangeError.index(index, this, "index");
1849 }
1850 _setIndexedFloat64x2(index, value);
1851 }
1852
1853
1854 // Method(s) implementing the TypedData interface.
1855 static const int BYTES_PER_ELEMENT = 16;
1856
1857 int get elementSizeInBytes {
1858 return Float64x2List.BYTES_PER_ELEMENT;
1859 }
1860
1861
1862 // Internal utility methods.
1863
1864 Float64x2List _createList(int length) {
1865 return new Float64x2List(length);
1866 }
1867
1868 Float64x2 _getIndexedFloat64x2(int index) {
1869 return _getFloat64x2(index * Float64x2List.BYTES_PER_ELEMENT);
1870 }
1871
1872 void _setIndexedFloat64x2(int index, Float64x2 value) {
1873 _setFloat64x2(index * Float64x2List.BYTES_PER_ELEMENT, value);
1874 }
1875 }
1876
1877
1878 class _ExternalInt8Array extends _TypedList with _IntListMixin implements Int8Li st {
1879 // Method(s) implementing the List interface.
1880 int operator[](int index) {
1881 if (index < 0 || index >= length) {
1882 throw new RangeError.index(index, this, "index");
1883 }
1884 return _getInt8(index);
1885 }
1886
1887 void operator[]=(int index, int value) {
1888 if (index < 0 || index >= length) {
1889 throw new RangeError.index(index, this, "index");
1890 }
1891 _setInt8(index, value);
1892 }
1893
1894
1895 // Method(s) implementing the TypedData interface.
1896
1897 int get elementSizeInBytes {
1898 return Int8List.BYTES_PER_ELEMENT;
1899 }
1900
1901
1902 // Internal utility methods.
1903
1904 Int8List _createList(int length) {
1905 return new Int8List(length);
1906 }
1907 }
1908
1909
1910 class _ExternalUint8Array extends _TypedList with _IntListMixin implements Uint8 List {
1911 // Method(s) implementing the List interface.
1912
1913 int operator[](int index) {
1914 if (index < 0 || index >= length) {
1915 throw new RangeError.index(index, this, "index");
1916 }
1917 return _getUint8(index);
1918 }
1919
1920 void operator[]=(int index, int value) {
1921 if (index < 0 || index >= length) {
1922 throw new RangeError.index(index, this, "index");
1923 }
1924 _setUint8(index, _toUint8(value));
1925 }
1926
1927
1928 // Method(s) implementing the TypedData interface.
1929
1930 int get elementSizeInBytes {
1931 return Uint8List.BYTES_PER_ELEMENT;
1932 }
1933
1934
1935 // Internal utility methods.
1936
1937 Uint8List _createList(int length) {
1938 return new Uint8List(length);
1939 }
1940 }
1941
1942
1943 class _ExternalUint8ClampedArray extends _TypedList with _IntListMixin implement s Uint8ClampedList {
1944 // Method(s) implementing the List interface.
1945
1946 int operator[](int index) {
1947 if (index < 0 || index >= length) {
1948 throw new RangeError.index(index, this, "index");
1949 }
1950 return _getUint8(index);
1951 }
1952
1953 void operator[]=(int index, int value) {
1954 if (index < 0 || index >= length) {
1955 throw new RangeError.index(index, this, "index");
1956 }
1957 _setUint8(index, _toClampedUint8(value));
1958 }
1959
1960
1961 // Method(s) implementing the TypedData interface.
1962
1963 int get elementSizeInBytes {
1964 return Uint8List.BYTES_PER_ELEMENT;
1965 }
1966
1967
1968 // Internal utility methods.
1969
1970 Uint8ClampedList _createList(int length) {
1971 return new Uint8ClampedList(length);
1972 }
1973 }
1974
1975
1976 class _ExternalInt16Array extends _TypedList with _IntListMixin implements Int16 List {
1977 // Method(s) implementing the List interface.
1978
1979 int operator[](int index) {
1980 if (index < 0 || index >= length) {
1981 throw new RangeError.index(index, this, "index");
1982 }
1983 return _getIndexedInt16(index);
1984 }
1985
1986 void operator[]=(int index, int value) {
1987 if (index < 0 || index >= length) {
1988 throw new RangeError.index(index, this, "index");
1989 }
1990 _setIndexedInt16(index, _toInt16(value));
1991 }
1992
1993
1994 // Method(s) implementing the TypedData interface.
1995
1996 int get elementSizeInBytes {
1997 return Int16List.BYTES_PER_ELEMENT;
1998 }
1999
2000
2001 // Internal utility methods.
2002
2003 Int16List _createList(int length) {
2004 return new Int16List(length);
2005 }
2006
2007 int _getIndexedInt16(int index) {
2008 return _getInt16(index * Int16List.BYTES_PER_ELEMENT);
2009 }
2010
2011 void _setIndexedInt16(int index, int value) {
2012 _setInt16(index * Int16List.BYTES_PER_ELEMENT, value);
2013 }
2014 }
2015
2016
2017 class _ExternalUint16Array extends _TypedList with _IntListMixin implements Uint 16List {
2018 // Method(s) implementing the List interface.
2019
2020 int operator[](int index) {
2021 if (index < 0 || index >= length) {
2022 throw new RangeError.index(index, this, "index");
2023 }
2024 return _getIndexedUint16(index);
2025 }
2026
2027 void operator[]=(int index, int value) {
2028 if (index < 0 || index >= length) {
2029 throw new RangeError.index(index, this, "index");
2030 }
2031 _setIndexedUint16(index, _toUint16(value));
2032 }
2033
2034
2035 // Method(s) implementing the TypedData interface.
2036
2037 int get elementSizeInBytes {
2038 return Uint16List.BYTES_PER_ELEMENT;
2039 }
2040
2041
2042 // Internal utility methods.
2043
2044 Uint16List _createList(int length) {
2045 return new Uint16List(length);
2046 }
2047
2048 int _getIndexedUint16(int index) {
2049 return _getUint16(index * Uint16List.BYTES_PER_ELEMENT);
2050 }
2051
2052 void _setIndexedUint16(int index, int value) {
2053 _setUint16(index * Uint16List.BYTES_PER_ELEMENT, value);
2054 }
2055 }
2056
2057
2058 class _ExternalInt32Array extends _TypedList with _IntListMixin implements Int32 List {
2059 // Method(s) implementing the List interface.
2060
2061 int operator[](int index) {
2062 if (index < 0 || index >= length) {
2063 throw new RangeError.index(index, this, "index");
2064 }
2065 return _getIndexedInt32(index);
2066 }
2067
2068 void operator[]=(int index, int value) {
2069 if (index < 0 || index >= length) {
2070 throw new RangeError.index(index, this, "index");
2071 }
2072 _setIndexedInt32(index, _toInt32(value));
2073 }
2074
2075
2076 // Method(s) implementing the TypedData interface.
2077
2078 int get elementSizeInBytes {
2079 return Int32List.BYTES_PER_ELEMENT;
2080 }
2081
2082
2083 // Internal utility methods.
2084
2085 Int32List _createList(int length) {
2086 return new Int32List(length);
2087 }
2088
2089 int _getIndexedInt32(int index) {
2090 return _getInt32(index * Int32List.BYTES_PER_ELEMENT);
2091 }
2092
2093 void _setIndexedInt32(int index, int value) {
2094 _setInt32(index * Int32List.BYTES_PER_ELEMENT, value);
2095 }
2096 }
2097
2098
2099 class _ExternalUint32Array extends _TypedList with _IntListMixin implements Uint 32List {
2100 // Method(s) implementing the List interface.
2101
2102 int operator[](int index) {
2103 if (index < 0 || index >= length) {
2104 throw new RangeError.index(index, this, "index");
2105 }
2106 return _getIndexedUint32(index);
2107 }
2108
2109 void operator[]=(int index, int value) {
2110 if (index < 0 || index >= length) {
2111 throw new RangeError.index(index, this, "index");
2112 }
2113 _setIndexedUint32(index, _toUint32(value));
2114 }
2115
2116
2117 // Method(s) implementing the TypedData interface.
2118
2119 int get elementSizeInBytes {
2120 return Uint32List.BYTES_PER_ELEMENT;
2121 }
2122
2123
2124 // Internal utility methods.
2125
2126 Uint32List _createList(int length) {
2127 return new Uint32List(length);
2128 }
2129
2130 int _getIndexedUint32(int index) {
2131 return _getUint32(index * Uint32List.BYTES_PER_ELEMENT);
2132 }
2133
2134 void _setIndexedUint32(int index, int value) {
2135 _setUint32(index * Uint32List.BYTES_PER_ELEMENT, value);
2136 }
2137 }
2138
2139
2140 class _ExternalInt64Array extends _TypedList with _IntListMixin implements Int64 List {
2141 // Method(s) implementing the List interface.
2142
2143 int operator[](int index) {
2144 if (index < 0 || index >= length) {
2145 throw new RangeError.index(index, this, "index");
2146 }
2147 return _getIndexedInt64(index);
2148 }
2149
2150 void operator[]=(int index, int value) {
2151 if (index < 0 || index >= length) {
2152 throw new RangeError.index(index, this, "index");
2153 }
2154 _setIndexedInt64(index, _toInt64(value));
2155 }
2156
2157
2158 // Method(s) implementing the TypedData interface.
2159
2160 int get elementSizeInBytes {
2161 return Int64List.BYTES_PER_ELEMENT;
2162 }
2163
2164
2165 // Internal utility methods.
2166
2167 Int64List _createList(int length) {
2168 return new Int64List(length);
2169 }
2170
2171 int _getIndexedInt64(int index) {
2172 return _getInt64(index * Int64List.BYTES_PER_ELEMENT);
2173 }
2174
2175 void _setIndexedInt64(int index, int value) {
2176 _setInt64(index * Int64List.BYTES_PER_ELEMENT, value);
2177 }
2178 }
2179
2180
2181 class _ExternalUint64Array extends _TypedList with _IntListMixin implements Uint 64List {
2182 // Method(s) implementing the List interface.
2183
2184 int operator[](int index) {
2185 if (index < 0 || index >= length) {
2186 throw new RangeError.index(index, this, "index");
2187 }
2188 return _getIndexedUint64(index);
2189 }
2190
2191 void operator[]=(int index, int value) {
2192 if (index < 0 || index >= length) {
2193 throw new RangeError.index(index, this, "index");
2194 }
2195 _setIndexedUint64(index, _toUint64(value));
2196 }
2197
2198
2199 // Method(s) implementing the TypedData interface.
2200
2201 int get elementSizeInBytes {
2202 return Uint64List.BYTES_PER_ELEMENT;
2203 }
2204
2205
2206 // Internal utility methods.
2207
2208 Uint64List _createList(int length) {
2209 return new Uint64List(length);
2210 }
2211
2212 int _getIndexedUint64(int index) {
2213 return _getUint64(index * Uint64List.BYTES_PER_ELEMENT);
2214 }
2215
2216 void _setIndexedUint64(int index, int value) {
2217 _setUint64(index * Uint64List.BYTES_PER_ELEMENT, value);
2218 }
2219 }
2220
2221
2222 class _ExternalFloat32Array extends _TypedList with _DoubleListMixin implements Float32List {
2223 // Method(s) implementing the List interface.
2224
2225 double operator[](int index) {
2226 if (index < 0 || index >= length) {
2227 throw new RangeError.index(index, this, "index");
2228 }
2229 return _getIndexedFloat32(index);
2230 }
2231
2232 void operator[]=(int index, double value) {
2233 if (index < 0 || index >= length) {
2234 throw new RangeError.index(index, this, "index");
2235 }
2236 _setIndexedFloat32(index, value);
2237 }
2238
2239
2240 // Method(s) implementing the TypedData interface.
2241
2242 int get elementSizeInBytes {
2243 return Float32List.BYTES_PER_ELEMENT;
2244 }
2245
2246
2247 // Internal utility methods.
2248
2249 Float32List _createList(int length) {
2250 return new Float32List(length);
2251 }
2252
2253 double _getIndexedFloat32(int index) {
2254 return _getFloat32(index * Float32List.BYTES_PER_ELEMENT);
2255 }
2256
2257 void _setIndexedFloat32(int index, double value) {
2258 _setFloat32(index * Float32List.BYTES_PER_ELEMENT, value);
2259 }
2260 }
2261
2262
2263 class _ExternalFloat64Array extends _TypedList with _DoubleListMixin implements Float64List {
2264 // Method(s) implementing the List interface.
2265
2266 double operator[](int index) {
2267 if (index < 0 || index >= length) {
2268 throw new RangeError.index(index, this, "index");
2269 }
2270 return _getIndexedFloat64(index);
2271 }
2272
2273 void operator[]=(int index, double value) {
2274 if (index < 0 || index >= length) {
2275 throw new RangeError.index(index, this, "index");
2276 }
2277 _setIndexedFloat64(index, value);
2278 }
2279
2280
2281 // Method(s) implementing the TypedData interface.
2282
2283 int get elementSizeInBytes {
2284 return Float64List.BYTES_PER_ELEMENT;
2285 }
2286
2287
2288 // Internal utility methods.
2289
2290 Float64List _createList(int length) {
2291 return new Float64List(length);
2292 }
2293
2294 double _getIndexedFloat64(int index) {
2295 return _getFloat64(index * Float64List.BYTES_PER_ELEMENT);
2296 }
2297
2298 void _setIndexedFloat64(int index, double value) {
2299 _setFloat64(index * Float64List.BYTES_PER_ELEMENT, value);
2300 }
2301 }
2302
2303
2304 class _ExternalFloat32x4Array extends _TypedList with _Float32x4ListMixin implem ents Float32x4List {
2305 // Method(s) implementing the List interface.
2306
2307 Float32x4 operator[](int index) {
2308 if (index < 0 || index >= length) {
2309 throw new RangeError.index(index, this, "index");
2310 }
2311 return _getIndexedFloat32x4(index);
2312 }
2313
2314 void operator[]=(int index, Float32x4 value) {
2315 if (index < 0 || index >= length) {
2316 throw new RangeError.index(index, this, "index");
2317 }
2318 _setIndexedFloat32x4(index, value);
2319 }
2320
2321
2322 // Method(s) implementing the TypedData interface.
2323
2324 int get elementSizeInBytes {
2325 return Float32x4List.BYTES_PER_ELEMENT;
2326 }
2327
2328
2329 // Internal utility methods.
2330
2331 Float32x4List _createList(int length) {
2332 return new Float32x4List(length);
2333 }
2334
2335 Float32x4 _getIndexedFloat32x4(int index) {
2336 return _getFloat32x4(index * Float32x4List.BYTES_PER_ELEMENT);
2337 }
2338
2339 void _setIndexedFloat32x4(int index, Float32x4 value) {
2340 _setFloat32x4(index * Float32x4List.BYTES_PER_ELEMENT, value);
2341 }
2342 }
2343
2344
2345 class _ExternalInt32x4Array extends _TypedList with _Int32x4ListMixin implements Int32x4List {
2346 // Method(s) implementing the List interface.
2347
2348 Int32x4 operator[](int index) {
2349 if (index < 0 || index >= length) {
2350 throw new RangeError.index(index, this, "index");
2351 }
2352 return _getIndexedInt32x4(index);
2353 }
2354
2355 void operator[]=(int index, Int32x4 value) {
2356 if (index < 0 || index >= length) {
2357 throw new RangeError.index(index, this, "index");
2358 }
2359 _setIndexedInt32x4(index, value);
2360 }
2361
2362
2363 // Method(s) implementing the TypedData interface.
2364
2365 int get elementSizeInBytes {
2366 return Int32x4List.BYTES_PER_ELEMENT;
2367 }
2368
2369
2370 // Internal utility methods.
2371
2372 Int32x4List _createList(int length) {
2373 return new Int32x4List(length);
2374 }
2375
2376 Int32x4 _getIndexedInt32x4(int index) {
2377 return _getInt32x4(index * Int32x4List.BYTES_PER_ELEMENT);
2378 }
2379
2380 void _setIndexedInt32x4(int index, Int32x4 value) {
2381 _setInt32x4(index * Int32x4List.BYTES_PER_ELEMENT, value);
2382 }
2383 }
2384
2385
2386 class _ExternalFloat64x2Array extends _TypedList with _Float64x2ListMixin implem ents Float64x2List {
2387 // Method(s) implementing the List interface.
2388
2389 Float64x2 operator[](int index) {
2390 if (index < 0 || index >= length) {
2391 throw new RangeError.index(index, this, "index");
2392 }
2393 return _getIndexedFloat64x2(index);
2394 }
2395
2396 void operator[]=(int index, Float64x2 value) {
2397 if (index < 0 || index >= length) {
2398 throw new RangeError.index(index, this, "index");
2399 }
2400 _setIndexedFloat64x2(index, value);
2401 }
2402
2403
2404 // Method(s) implementing the TypedData interface.
2405
2406 int get elementSizeInBytes {
2407 return Float64x2List.BYTES_PER_ELEMENT;
2408 }
2409
2410
2411 // Internal utility methods.
2412
2413 Float64x2List _createList(int length) {
2414 return new Float64x2List(length);
2415 }
2416
2417 Float64x2 _getIndexedFloat64x2(int index) {
2418 return _getFloat64x2(index * Float64x2List.BYTES_PER_ELEMENT);
2419 }
2420
2421 void _setIndexedFloat64x2(int index, Float64x2 value) {
2422 _setFloat64x2(index * Float64x2List.BYTES_PER_ELEMENT, value);
2423 }
2424 }
2425
2426
2427 class Float32x4 {
2428 factory Float32x4(double x, double y, double z, double w)
2429 native "Float32x4_fromDoubles";
2430 factory Float32x4.splat(double v) native "Float32x4_splat";
2431 factory Float32x4.zero() native "Float32x4_zero";
2432 factory Float32x4.fromInt32x4Bits(Int32x4 x)
2433 native "Float32x4_fromInt32x4Bits";
2434 factory Float32x4.fromFloat64x2(Float64x2 v)
2435 native "Float32x4_fromFloat64x2";
2436 Float32x4 operator +(Float32x4 other) {
2437 return _add(other);
2438 }
2439 Float32x4 _add(Float32x4 other) native "Float32x4_add";
2440 Float32x4 operator -() {
2441 return _negate();
2442 }
2443 Float32x4 _negate() native "Float32x4_negate";
2444 Float32x4 operator -(Float32x4 other) {
2445 return _sub(other);
2446 }
2447 Float32x4 _sub(Float32x4 other) native "Float32x4_sub";
2448 Float32x4 operator *(Float32x4 other) {
2449 return _mul(other);
2450 }
2451 Float32x4 _mul(Float32x4 other) native "Float32x4_mul";
2452 Float32x4 operator /(Float32x4 other) {
2453 return _div(other);
2454 }
2455 Float32x4 _div(Float32x4 other) native "Float32x4_div";
2456 Int32x4 lessThan(Float32x4 other) {
2457 return _cmplt(other);
2458 }
2459 Int32x4 _cmplt(Float32x4 other) native "Float32x4_cmplt";
2460 Int32x4 lessThanOrEqual(Float32x4 other) {
2461 return _cmplte(other);
2462 }
2463 Int32x4 _cmplte(Float32x4 other) native "Float32x4_cmplte";
2464 Int32x4 greaterThan(Float32x4 other) {
2465 return _cmpgt(other);
2466 }
2467 Int32x4 _cmpgt(Float32x4 other) native "Float32x4_cmpgt";
2468 Int32x4 greaterThanOrEqual(Float32x4 other) {
2469 return _cmpgte(other);
2470 }
2471 Int32x4 _cmpgte(Float32x4 other) native "Float32x4_cmpgte";
2472 Int32x4 equal(Float32x4 other) {
2473 return _cmpequal(other);
2474 }
2475 Int32x4 _cmpequal(Float32x4 other)
2476 native "Float32x4_cmpequal";
2477 Int32x4 notEqual(Float32x4 other) {
2478 return _cmpnequal(other);
2479 }
2480 Int32x4 _cmpnequal(Float32x4 other)
2481 native "Float32x4_cmpnequal";
2482 Float32x4 scale(double s) {
2483 return _scale(s);
2484 }
2485 Float32x4 _scale(double s) native "Float32x4_scale";
2486 Float32x4 abs() {
2487 return _abs();
2488 }
2489 Float32x4 _abs() native "Float32x4_abs";
2490 Float32x4 clamp(Float32x4 lowerLimit, Float32x4 upperLimit) {
2491 return _clamp(lowerLimit, upperLimit);
2492 }
2493 Float32x4 _clamp(Float32x4 lowerLimit, Float32x4 upperLimit)
2494 native "Float32x4_clamp";
2495 double get x native "Float32x4_getX";
2496 double get y native "Float32x4_getY";
2497 double get z native "Float32x4_getZ";
2498 double get w native "Float32x4_getW";
2499 int get signMask native "Float32x4_getSignMask";
2500
2501 Float32x4 shuffle(int mask) native "Float32x4_shuffle";
2502 Float32x4 shuffleMix(Float32x4 zw, int mask) native "Float32x4_shuffleMix";
2503
2504 Float32x4 withX(double x) native "Float32x4_setX";
2505 Float32x4 withY(double y) native "Float32x4_setY";
2506 Float32x4 withZ(double z) native "Float32x4_setZ";
2507 Float32x4 withW(double w) native "Float32x4_setW";
2508 Float32x4 min(Float32x4 other) {
2509 return _min(other);
2510 }
2511 Float32x4 _min(Float32x4 other) native "Float32x4_min";
2512 Float32x4 max(Float32x4 other) {
2513 return _max(other);
2514 }
2515 Float32x4 _max(Float32x4 other) native "Float32x4_max";
2516 Float32x4 sqrt() {
2517 return _sqrt();
2518 }
2519 Float32x4 _sqrt() native "Float32x4_sqrt";
2520 Float32x4 reciprocal() {
2521 return _reciprocal();
2522 }
2523 Float32x4 _reciprocal() native "Float32x4_reciprocal";
2524 Float32x4 reciprocalSqrt() {
2525 return _reciprocalSqrt();
2526 }
2527 Float32x4 _reciprocalSqrt() native "Float32x4_reciprocalSqrt";
2528
2529 /// Mask passed to [shuffle] or [shuffleMix].
2530 static const int XXXX = 0x0;
2531 static const int XXXY = 0x40;
2532 static const int XXXZ = 0x80;
2533 static const int XXXW = 0xC0;
2534 static const int XXYX = 0x10;
2535 static const int XXYY = 0x50;
2536 static const int XXYZ = 0x90;
2537 static const int XXYW = 0xD0;
2538 static const int XXZX = 0x20;
2539 static const int XXZY = 0x60;
2540 static const int XXZZ = 0xA0;
2541 static const int XXZW = 0xE0;
2542 static const int XXWX = 0x30;
2543 static const int XXWY = 0x70;
2544 static const int XXWZ = 0xB0;
2545 static const int XXWW = 0xF0;
2546 static const int XYXX = 0x4;
2547 static const int XYXY = 0x44;
2548 static const int XYXZ = 0x84;
2549 static const int XYXW = 0xC4;
2550 static const int XYYX = 0x14;
2551 static const int XYYY = 0x54;
2552 static const int XYYZ = 0x94;
2553 static const int XYYW = 0xD4;
2554 static const int XYZX = 0x24;
2555 static const int XYZY = 0x64;
2556 static const int XYZZ = 0xA4;
2557 static const int XYZW = 0xE4;
2558 static const int XYWX = 0x34;
2559 static const int XYWY = 0x74;
2560 static const int XYWZ = 0xB4;
2561 static const int XYWW = 0xF4;
2562 static const int XZXX = 0x8;
2563 static const int XZXY = 0x48;
2564 static const int XZXZ = 0x88;
2565 static const int XZXW = 0xC8;
2566 static const int XZYX = 0x18;
2567 static const int XZYY = 0x58;
2568 static const int XZYZ = 0x98;
2569 static const int XZYW = 0xD8;
2570 static const int XZZX = 0x28;
2571 static const int XZZY = 0x68;
2572 static const int XZZZ = 0xA8;
2573 static const int XZZW = 0xE8;
2574 static const int XZWX = 0x38;
2575 static const int XZWY = 0x78;
2576 static const int XZWZ = 0xB8;
2577 static const int XZWW = 0xF8;
2578 static const int XWXX = 0xC;
2579 static const int XWXY = 0x4C;
2580 static const int XWXZ = 0x8C;
2581 static const int XWXW = 0xCC;
2582 static const int XWYX = 0x1C;
2583 static const int XWYY = 0x5C;
2584 static const int XWYZ = 0x9C;
2585 static const int XWYW = 0xDC;
2586 static const int XWZX = 0x2C;
2587 static const int XWZY = 0x6C;
2588 static const int XWZZ = 0xAC;
2589 static const int XWZW = 0xEC;
2590 static const int XWWX = 0x3C;
2591 static const int XWWY = 0x7C;
2592 static const int XWWZ = 0xBC;
2593 static const int XWWW = 0xFC;
2594 static const int YXXX = 0x1;
2595 static const int YXXY = 0x41;
2596 static const int YXXZ = 0x81;
2597 static const int YXXW = 0xC1;
2598 static const int YXYX = 0x11;
2599 static const int YXYY = 0x51;
2600 static const int YXYZ = 0x91;
2601 static const int YXYW = 0xD1;
2602 static const int YXZX = 0x21;
2603 static const int YXZY = 0x61;
2604 static const int YXZZ = 0xA1;
2605 static const int YXZW = 0xE1;
2606 static const int YXWX = 0x31;
2607 static const int YXWY = 0x71;
2608 static const int YXWZ = 0xB1;
2609 static const int YXWW = 0xF1;
2610 static const int YYXX = 0x5;
2611 static const int YYXY = 0x45;
2612 static const int YYXZ = 0x85;
2613 static const int YYXW = 0xC5;
2614 static const int YYYX = 0x15;
2615 static const int YYYY = 0x55;
2616 static const int YYYZ = 0x95;
2617 static const int YYYW = 0xD5;
2618 static const int YYZX = 0x25;
2619 static const int YYZY = 0x65;
2620 static const int YYZZ = 0xA5;
2621 static const int YYZW = 0xE5;
2622 static const int YYWX = 0x35;
2623 static const int YYWY = 0x75;
2624 static const int YYWZ = 0xB5;
2625 static const int YYWW = 0xF5;
2626 static const int YZXX = 0x9;
2627 static const int YZXY = 0x49;
2628 static const int YZXZ = 0x89;
2629 static const int YZXW = 0xC9;
2630 static const int YZYX = 0x19;
2631 static const int YZYY = 0x59;
2632 static const int YZYZ = 0x99;
2633 static const int YZYW = 0xD9;
2634 static const int YZZX = 0x29;
2635 static const int YZZY = 0x69;
2636 static const int YZZZ = 0xA9;
2637 static const int YZZW = 0xE9;
2638 static const int YZWX = 0x39;
2639 static const int YZWY = 0x79;
2640 static const int YZWZ = 0xB9;
2641 static const int YZWW = 0xF9;
2642 static const int YWXX = 0xD;
2643 static const int YWXY = 0x4D;
2644 static const int YWXZ = 0x8D;
2645 static const int YWXW = 0xCD;
2646 static const int YWYX = 0x1D;
2647 static const int YWYY = 0x5D;
2648 static const int YWYZ = 0x9D;
2649 static const int YWYW = 0xDD;
2650 static const int YWZX = 0x2D;
2651 static const int YWZY = 0x6D;
2652 static const int YWZZ = 0xAD;
2653 static const int YWZW = 0xED;
2654 static const int YWWX = 0x3D;
2655 static const int YWWY = 0x7D;
2656 static const int YWWZ = 0xBD;
2657 static const int YWWW = 0xFD;
2658 static const int ZXXX = 0x2;
2659 static const int ZXXY = 0x42;
2660 static const int ZXXZ = 0x82;
2661 static const int ZXXW = 0xC2;
2662 static const int ZXYX = 0x12;
2663 static const int ZXYY = 0x52;
2664 static const int ZXYZ = 0x92;
2665 static const int ZXYW = 0xD2;
2666 static const int ZXZX = 0x22;
2667 static const int ZXZY = 0x62;
2668 static const int ZXZZ = 0xA2;
2669 static const int ZXZW = 0xE2;
2670 static const int ZXWX = 0x32;
2671 static const int ZXWY = 0x72;
2672 static const int ZXWZ = 0xB2;
2673 static const int ZXWW = 0xF2;
2674 static const int ZYXX = 0x6;
2675 static const int ZYXY = 0x46;
2676 static const int ZYXZ = 0x86;
2677 static const int ZYXW = 0xC6;
2678 static const int ZYYX = 0x16;
2679 static const int ZYYY = 0x56;
2680 static const int ZYYZ = 0x96;
2681 static const int ZYYW = 0xD6;
2682 static const int ZYZX = 0x26;
2683 static const int ZYZY = 0x66;
2684 static const int ZYZZ = 0xA6;
2685 static const int ZYZW = 0xE6;
2686 static const int ZYWX = 0x36;
2687 static const int ZYWY = 0x76;
2688 static const int ZYWZ = 0xB6;
2689 static const int ZYWW = 0xF6;
2690 static const int ZZXX = 0xA;
2691 static const int ZZXY = 0x4A;
2692 static const int ZZXZ = 0x8A;
2693 static const int ZZXW = 0xCA;
2694 static const int ZZYX = 0x1A;
2695 static const int ZZYY = 0x5A;
2696 static const int ZZYZ = 0x9A;
2697 static const int ZZYW = 0xDA;
2698 static const int ZZZX = 0x2A;
2699 static const int ZZZY = 0x6A;
2700 static const int ZZZZ = 0xAA;
2701 static const int ZZZW = 0xEA;
2702 static const int ZZWX = 0x3A;
2703 static const int ZZWY = 0x7A;
2704 static const int ZZWZ = 0xBA;
2705 static const int ZZWW = 0xFA;
2706 static const int ZWXX = 0xE;
2707 static const int ZWXY = 0x4E;
2708 static const int ZWXZ = 0x8E;
2709 static const int ZWXW = 0xCE;
2710 static const int ZWYX = 0x1E;
2711 static const int ZWYY = 0x5E;
2712 static const int ZWYZ = 0x9E;
2713 static const int ZWYW = 0xDE;
2714 static const int ZWZX = 0x2E;
2715 static const int ZWZY = 0x6E;
2716 static const int ZWZZ = 0xAE;
2717 static const int ZWZW = 0xEE;
2718 static const int ZWWX = 0x3E;
2719 static const int ZWWY = 0x7E;
2720 static const int ZWWZ = 0xBE;
2721 static const int ZWWW = 0xFE;
2722 static const int WXXX = 0x3;
2723 static const int WXXY = 0x43;
2724 static const int WXXZ = 0x83;
2725 static const int WXXW = 0xC3;
2726 static const int WXYX = 0x13;
2727 static const int WXYY = 0x53;
2728 static const int WXYZ = 0x93;
2729 static const int WXYW = 0xD3;
2730 static const int WXZX = 0x23;
2731 static const int WXZY = 0x63;
2732 static const int WXZZ = 0xA3;
2733 static const int WXZW = 0xE3;
2734 static const int WXWX = 0x33;
2735 static const int WXWY = 0x73;
2736 static const int WXWZ = 0xB3;
2737 static const int WXWW = 0xF3;
2738 static const int WYXX = 0x7;
2739 static const int WYXY = 0x47;
2740 static const int WYXZ = 0x87;
2741 static const int WYXW = 0xC7;
2742 static const int WYYX = 0x17;
2743 static const int WYYY = 0x57;
2744 static const int WYYZ = 0x97;
2745 static const int WYYW = 0xD7;
2746 static const int WYZX = 0x27;
2747 static const int WYZY = 0x67;
2748 static const int WYZZ = 0xA7;
2749 static const int WYZW = 0xE7;
2750 static const int WYWX = 0x37;
2751 static const int WYWY = 0x77;
2752 static const int WYWZ = 0xB7;
2753 static const int WYWW = 0xF7;
2754 static const int WZXX = 0xB;
2755 static const int WZXY = 0x4B;
2756 static const int WZXZ = 0x8B;
2757 static const int WZXW = 0xCB;
2758 static const int WZYX = 0x1B;
2759 static const int WZYY = 0x5B;
2760 static const int WZYZ = 0x9B;
2761 static const int WZYW = 0xDB;
2762 static const int WZZX = 0x2B;
2763 static const int WZZY = 0x6B;
2764 static const int WZZZ = 0xAB;
2765 static const int WZZW = 0xEB;
2766 static const int WZWX = 0x3B;
2767 static const int WZWY = 0x7B;
2768 static const int WZWZ = 0xBB;
2769 static const int WZWW = 0xFB;
2770 static const int WWXX = 0xF;
2771 static const int WWXY = 0x4F;
2772 static const int WWXZ = 0x8F;
2773 static const int WWXW = 0xCF;
2774 static const int WWYX = 0x1F;
2775 static const int WWYY = 0x5F;
2776 static const int WWYZ = 0x9F;
2777 static const int WWYW = 0xDF;
2778 static const int WWZX = 0x2F;
2779 static const int WWZY = 0x6F;
2780 static const int WWZZ = 0xAF;
2781 static const int WWZW = 0xEF;
2782 static const int WWWX = 0x3F;
2783 static const int WWWY = 0x7F;
2784 static const int WWWZ = 0xBF;
2785 static const int WWWW = 0xFF;
2786
2787 }
2788
2789
2790 class Int32x4 {
2791 factory Int32x4(int x, int y, int z, int w)
2792 native "Int32x4_fromInts";
2793 factory Int32x4.bool(bool x, bool y, bool z, bool w)
2794 native "Int32x4_fromBools";
2795 factory Int32x4.fromFloat32x4Bits(Float32x4 x)
2796 native "Int32x4_fromFloat32x4Bits";
2797 Int32x4 operator |(Int32x4 other) {
2798 return _or(other);
2799 }
2800 Int32x4 _or(Int32x4 other) native "Int32x4_or";
2801 Int32x4 operator &(Int32x4 other) {
2802 return _and(other);
2803 }
2804 Int32x4 _and(Int32x4 other) native "Int32x4_and";
2805 Int32x4 operator ^(Int32x4 other) {
2806 return _xor(other);
2807 }
2808 Int32x4 _xor(Int32x4 other) native "Int32x4_xor";
2809 Int32x4 operator +(Int32x4 other) {
2810 return _add(other);
2811 }
2812 Int32x4 _add(Int32x4 other) native "Int32x4_add";
2813 Int32x4 operator -(Int32x4 other) {
2814 return _sub(other);
2815 }
2816 Int32x4 _sub(Int32x4 other) native "Int32x4_sub";
2817 int get x native "Int32x4_getX";
2818 int get y native "Int32x4_getY";
2819 int get z native "Int32x4_getZ";
2820 int get w native "Int32x4_getW";
2821 int get signMask native "Int32x4_getSignMask";
2822 Int32x4 shuffle(int mask) native "Int32x4_shuffle";
2823 Int32x4 shuffleMix(Int32x4 zw, int mask) native "Int32x4_shuffleMix";
2824 Int32x4 withX(int x) native "Int32x4_setX";
2825 Int32x4 withY(int y) native "Int32x4_setY";
2826 Int32x4 withZ(int z) native "Int32x4_setZ";
2827 Int32x4 withW(int w) native "Int32x4_setW";
2828 bool get flagX native "Int32x4_getFlagX";
2829 bool get flagY native "Int32x4_getFlagY";
2830 bool get flagZ native "Int32x4_getFlagZ";
2831 bool get flagW native "Int32x4_getFlagW";
2832 Int32x4 withFlagX(bool x) native "Int32x4_setFlagX";
2833 Int32x4 withFlagY(bool y) native "Int32x4_setFlagY";
2834 Int32x4 withFlagZ(bool z) native "Int32x4_setFlagZ";
2835 Int32x4 withFlagW(bool w) native "Int32x4_setFlagW";
2836 Float32x4 select(Float32x4 trueValue, Float32x4 falseValue) {
2837 return _select(trueValue, falseValue);
2838 }
2839 Float32x4 _select(Float32x4 trueValue, Float32x4 falseValue)
2840 native "Int32x4_select";
2841
2842 /// Mask passed to [shuffle] or [shuffleMix].
2843 static const int XXXX = 0x0;
2844 static const int XXXY = 0x40;
2845 static const int XXXZ = 0x80;
2846 static const int XXXW = 0xC0;
2847 static const int XXYX = 0x10;
2848 static const int XXYY = 0x50;
2849 static const int XXYZ = 0x90;
2850 static const int XXYW = 0xD0;
2851 static const int XXZX = 0x20;
2852 static const int XXZY = 0x60;
2853 static const int XXZZ = 0xA0;
2854 static const int XXZW = 0xE0;
2855 static const int XXWX = 0x30;
2856 static const int XXWY = 0x70;
2857 static const int XXWZ = 0xB0;
2858 static const int XXWW = 0xF0;
2859 static const int XYXX = 0x4;
2860 static const int XYXY = 0x44;
2861 static const int XYXZ = 0x84;
2862 static const int XYXW = 0xC4;
2863 static const int XYYX = 0x14;
2864 static const int XYYY = 0x54;
2865 static const int XYYZ = 0x94;
2866 static const int XYYW = 0xD4;
2867 static const int XYZX = 0x24;
2868 static const int XYZY = 0x64;
2869 static const int XYZZ = 0xA4;
2870 static const int XYZW = 0xE4;
2871 static const int XYWX = 0x34;
2872 static const int XYWY = 0x74;
2873 static const int XYWZ = 0xB4;
2874 static const int XYWW = 0xF4;
2875 static const int XZXX = 0x8;
2876 static const int XZXY = 0x48;
2877 static const int XZXZ = 0x88;
2878 static const int XZXW = 0xC8;
2879 static const int XZYX = 0x18;
2880 static const int XZYY = 0x58;
2881 static const int XZYZ = 0x98;
2882 static const int XZYW = 0xD8;
2883 static const int XZZX = 0x28;
2884 static const int XZZY = 0x68;
2885 static const int XZZZ = 0xA8;
2886 static const int XZZW = 0xE8;
2887 static const int XZWX = 0x38;
2888 static const int XZWY = 0x78;
2889 static const int XZWZ = 0xB8;
2890 static const int XZWW = 0xF8;
2891 static const int XWXX = 0xC;
2892 static const int XWXY = 0x4C;
2893 static const int XWXZ = 0x8C;
2894 static const int XWXW = 0xCC;
2895 static const int XWYX = 0x1C;
2896 static const int XWYY = 0x5C;
2897 static const int XWYZ = 0x9C;
2898 static const int XWYW = 0xDC;
2899 static const int XWZX = 0x2C;
2900 static const int XWZY = 0x6C;
2901 static const int XWZZ = 0xAC;
2902 static const int XWZW = 0xEC;
2903 static const int XWWX = 0x3C;
2904 static const int XWWY = 0x7C;
2905 static const int XWWZ = 0xBC;
2906 static const int XWWW = 0xFC;
2907 static const int YXXX = 0x1;
2908 static const int YXXY = 0x41;
2909 static const int YXXZ = 0x81;
2910 static const int YXXW = 0xC1;
2911 static const int YXYX = 0x11;
2912 static const int YXYY = 0x51;
2913 static const int YXYZ = 0x91;
2914 static const int YXYW = 0xD1;
2915 static const int YXZX = 0x21;
2916 static const int YXZY = 0x61;
2917 static const int YXZZ = 0xA1;
2918 static const int YXZW = 0xE1;
2919 static const int YXWX = 0x31;
2920 static const int YXWY = 0x71;
2921 static const int YXWZ = 0xB1;
2922 static const int YXWW = 0xF1;
2923 static const int YYXX = 0x5;
2924 static const int YYXY = 0x45;
2925 static const int YYXZ = 0x85;
2926 static const int YYXW = 0xC5;
2927 static const int YYYX = 0x15;
2928 static const int YYYY = 0x55;
2929 static const int YYYZ = 0x95;
2930 static const int YYYW = 0xD5;
2931 static const int YYZX = 0x25;
2932 static const int YYZY = 0x65;
2933 static const int YYZZ = 0xA5;
2934 static const int YYZW = 0xE5;
2935 static const int YYWX = 0x35;
2936 static const int YYWY = 0x75;
2937 static const int YYWZ = 0xB5;
2938 static const int YYWW = 0xF5;
2939 static const int YZXX = 0x9;
2940 static const int YZXY = 0x49;
2941 static const int YZXZ = 0x89;
2942 static const int YZXW = 0xC9;
2943 static const int YZYX = 0x19;
2944 static const int YZYY = 0x59;
2945 static const int YZYZ = 0x99;
2946 static const int YZYW = 0xD9;
2947 static const int YZZX = 0x29;
2948 static const int YZZY = 0x69;
2949 static const int YZZZ = 0xA9;
2950 static const int YZZW = 0xE9;
2951 static const int YZWX = 0x39;
2952 static const int YZWY = 0x79;
2953 static const int YZWZ = 0xB9;
2954 static const int YZWW = 0xF9;
2955 static const int YWXX = 0xD;
2956 static const int YWXY = 0x4D;
2957 static const int YWXZ = 0x8D;
2958 static const int YWXW = 0xCD;
2959 static const int YWYX = 0x1D;
2960 static const int YWYY = 0x5D;
2961 static const int YWYZ = 0x9D;
2962 static const int YWYW = 0xDD;
2963 static const int YWZX = 0x2D;
2964 static const int YWZY = 0x6D;
2965 static const int YWZZ = 0xAD;
2966 static const int YWZW = 0xED;
2967 static const int YWWX = 0x3D;
2968 static const int YWWY = 0x7D;
2969 static const int YWWZ = 0xBD;
2970 static const int YWWW = 0xFD;
2971 static const int ZXXX = 0x2;
2972 static const int ZXXY = 0x42;
2973 static const int ZXXZ = 0x82;
2974 static const int ZXXW = 0xC2;
2975 static const int ZXYX = 0x12;
2976 static const int ZXYY = 0x52;
2977 static const int ZXYZ = 0x92;
2978 static const int ZXYW = 0xD2;
2979 static const int ZXZX = 0x22;
2980 static const int ZXZY = 0x62;
2981 static const int ZXZZ = 0xA2;
2982 static const int ZXZW = 0xE2;
2983 static const int ZXWX = 0x32;
2984 static const int ZXWY = 0x72;
2985 static const int ZXWZ = 0xB2;
2986 static const int ZXWW = 0xF2;
2987 static const int ZYXX = 0x6;
2988 static const int ZYXY = 0x46;
2989 static const int ZYXZ = 0x86;
2990 static const int ZYXW = 0xC6;
2991 static const int ZYYX = 0x16;
2992 static const int ZYYY = 0x56;
2993 static const int ZYYZ = 0x96;
2994 static const int ZYYW = 0xD6;
2995 static const int ZYZX = 0x26;
2996 static const int ZYZY = 0x66;
2997 static const int ZYZZ = 0xA6;
2998 static const int ZYZW = 0xE6;
2999 static const int ZYWX = 0x36;
3000 static const int ZYWY = 0x76;
3001 static const int ZYWZ = 0xB6;
3002 static const int ZYWW = 0xF6;
3003 static const int ZZXX = 0xA;
3004 static const int ZZXY = 0x4A;
3005 static const int ZZXZ = 0x8A;
3006 static const int ZZXW = 0xCA;
3007 static const int ZZYX = 0x1A;
3008 static const int ZZYY = 0x5A;
3009 static const int ZZYZ = 0x9A;
3010 static const int ZZYW = 0xDA;
3011 static const int ZZZX = 0x2A;
3012 static const int ZZZY = 0x6A;
3013 static const int ZZZZ = 0xAA;
3014 static const int ZZZW = 0xEA;
3015 static const int ZZWX = 0x3A;
3016 static const int ZZWY = 0x7A;
3017 static const int ZZWZ = 0xBA;
3018 static const int ZZWW = 0xFA;
3019 static const int ZWXX = 0xE;
3020 static const int ZWXY = 0x4E;
3021 static const int ZWXZ = 0x8E;
3022 static const int ZWXW = 0xCE;
3023 static const int ZWYX = 0x1E;
3024 static const int ZWYY = 0x5E;
3025 static const int ZWYZ = 0x9E;
3026 static const int ZWYW = 0xDE;
3027 static const int ZWZX = 0x2E;
3028 static const int ZWZY = 0x6E;
3029 static const int ZWZZ = 0xAE;
3030 static const int ZWZW = 0xEE;
3031 static const int ZWWX = 0x3E;
3032 static const int ZWWY = 0x7E;
3033 static const int ZWWZ = 0xBE;
3034 static const int ZWWW = 0xFE;
3035 static const int WXXX = 0x3;
3036 static const int WXXY = 0x43;
3037 static const int WXXZ = 0x83;
3038 static const int WXXW = 0xC3;
3039 static const int WXYX = 0x13;
3040 static const int WXYY = 0x53;
3041 static const int WXYZ = 0x93;
3042 static const int WXYW = 0xD3;
3043 static const int WXZX = 0x23;
3044 static const int WXZY = 0x63;
3045 static const int WXZZ = 0xA3;
3046 static const int WXZW = 0xE3;
3047 static const int WXWX = 0x33;
3048 static const int WXWY = 0x73;
3049 static const int WXWZ = 0xB3;
3050 static const int WXWW = 0xF3;
3051 static const int WYXX = 0x7;
3052 static const int WYXY = 0x47;
3053 static const int WYXZ = 0x87;
3054 static const int WYXW = 0xC7;
3055 static const int WYYX = 0x17;
3056 static const int WYYY = 0x57;
3057 static const int WYYZ = 0x97;
3058 static const int WYYW = 0xD7;
3059 static const int WYZX = 0x27;
3060 static const int WYZY = 0x67;
3061 static const int WYZZ = 0xA7;
3062 static const int WYZW = 0xE7;
3063 static const int WYWX = 0x37;
3064 static const int WYWY = 0x77;
3065 static const int WYWZ = 0xB7;
3066 static const int WYWW = 0xF7;
3067 static const int WZXX = 0xB;
3068 static const int WZXY = 0x4B;
3069 static const int WZXZ = 0x8B;
3070 static const int WZXW = 0xCB;
3071 static const int WZYX = 0x1B;
3072 static const int WZYY = 0x5B;
3073 static const int WZYZ = 0x9B;
3074 static const int WZYW = 0xDB;
3075 static const int WZZX = 0x2B;
3076 static const int WZZY = 0x6B;
3077 static const int WZZZ = 0xAB;
3078 static const int WZZW = 0xEB;
3079 static const int WZWX = 0x3B;
3080 static const int WZWY = 0x7B;
3081 static const int WZWZ = 0xBB;
3082 static const int WZWW = 0xFB;
3083 static const int WWXX = 0xF;
3084 static const int WWXY = 0x4F;
3085 static const int WWXZ = 0x8F;
3086 static const int WWXW = 0xCF;
3087 static const int WWYX = 0x1F;
3088 static const int WWYY = 0x5F;
3089 static const int WWYZ = 0x9F;
3090 static const int WWYW = 0xDF;
3091 static const int WWZX = 0x2F;
3092 static const int WWZY = 0x6F;
3093 static const int WWZZ = 0xAF;
3094 static const int WWZW = 0xEF;
3095 static const int WWWX = 0x3F;
3096 static const int WWWY = 0x7F;
3097 static const int WWWZ = 0xBF;
3098 static const int WWWW = 0xFF;
3099
3100 }
3101
3102
3103 class Float64x2 {
3104 factory Float64x2(double x, double y) native "Float64x2_fromDoubles";
3105 factory Float64x2.splat(double v) native "Float64x2_splat";
3106 factory Float64x2.zero() native "Float64x2_zero";
3107 factory Float64x2.fromFloat32x4(Float32x4 v) native "Float64x2_fromFloat32x4";
3108
3109 Float64x2 operator +(Float64x2 other) {
3110 return _add(other);
3111 }
3112 Float64x2 _add(Float64x2 other) native "Float64x2_add";
3113 Float64x2 operator -() {
3114 return _negate();
3115 }
3116 Float64x2 _negate() native "Float64x2_negate";
3117 Float64x2 operator -(Float64x2 other) {
3118 return _sub(other);
3119 }
3120 Float64x2 _sub(Float64x2 other) native "Float64x2_sub";
3121 Float64x2 operator *(Float64x2 other) {
3122 return _mul(other);
3123 }
3124 Float64x2 _mul(Float64x2 other) native "Float64x2_mul";
3125 Float64x2 operator /(Float64x2 other) {
3126 return _div(other);
3127 }
3128 Float64x2 _div(Float64x2 other) native "Float64x2_div";
3129
3130
3131 /// Returns a copy of [this] each lane being scaled by [s].
3132 Float64x2 scale(double s) native "Float64x2_scale";
3133 /// Returns the absolute value of this [Float64x2].
3134 Float64x2 abs() native "Float64x2_abs";
3135
3136 /// Clamps [this] to be in the range [lowerLimit]-[upperLimit].
3137 Float64x2 clamp(Float64x2 lowerLimit,
3138 Float64x2 upperLimit) native "Float64x2_clamp";
3139
3140 /// Extracted x value.
3141 double get x native "Float64x2_getX";
3142 /// Extracted y value.
3143 double get y native "Float64x2_getY";
3144
3145 /// Extract the sign bits from each lane return them in the first 2 bits.
3146 int get signMask native "Float64x2_getSignMask";
3147
3148 /// Returns a new [Float64x2] copied from [this] with a new x value.
3149 Float64x2 withX(double x) native "Float64x2_setX";
3150 /// Returns a new [Float64x2] copied from [this] with a new y value.
3151 Float64x2 withY(double y) native "Float64x2_setY";
3152
3153 /// Returns the lane-wise minimum value in [this] or [other].
3154 Float64x2 min(Float64x2 other) native "Float64x2_min";
3155
3156 /// Returns the lane-wise maximum value in [this] or [other].
3157 Float64x2 max(Float64x2 other) native "Float64x2_max";
3158
3159 /// Returns the lane-wise square root of [this].
3160 Float64x2 sqrt() native "Float64x2_sqrt";
3161 }
3162
3163
3164
3165 class _TypedListIterator<E> implements Iterator<E> {
3166 final List<E> _array;
3167 final int _length;
3168 int _position;
3169 E _current;
3170
3171 _TypedListIterator(List array)
3172 : _array = array, _length = array.length, _position = -1 {
3173 assert(array is _TypedList || array is _TypedListView);
3174 }
3175
3176 bool moveNext() {
3177 int nextPosition = _position + 1;
3178 if (nextPosition < _length) {
3179 _current = _array[nextPosition];
3180 _position = nextPosition;
3181 return true;
3182 }
3183 _position = _length;
3184 _current = null;
3185 return false;
3186 }
3187
3188 E get current => _current;
3189 }
3190
3191
3192 class _TypedListView extends _TypedListBase implements TypedData {
3193 _TypedListView(ByteBuffer _buffer, int _offset, int _length)
3194 : _typedData = _buffer._data,
3195 offsetInBytes = _offset,
3196 length = _length {
3197 }
3198
3199 // Method(s) implementing the TypedData interface.
3200
3201 int get lengthInBytes {
3202 return length * elementSizeInBytes;
3203 }
3204
3205 ByteBuffer get buffer {
3206 return _typedData.buffer;
3207 }
3208
3209 final _TypedList _typedData;
3210 final int offsetInBytes;
3211 final int length;
3212 }
3213
3214
3215 class _Int8ArrayView extends _TypedListView with _IntListMixin implements Int8Li st {
3216 // Constructor.
3217 _Int8ArrayView(ByteBuffer buffer, [int _offsetInBytes = 0, int _length])
3218 : super(buffer, _offsetInBytes,
3219 _defaultIfNull(_length,
3220 ((buffer.lengthInBytes - _offsetInBytes) ~/
3221 Int8List.BYTES_PER_ELEMENT))) {
3222 _rangeCheck(buffer.lengthInBytes,
3223 _offsetInBytes,
3224 length * Int8List.BYTES_PER_ELEMENT);
3225 }
3226
3227
3228 // Method(s) implementing List interface.
3229
3230 int operator[](int index) {
3231 if (index < 0 || index >= length) {
3232 throw new RangeError.index(index, this, "index");
3233 }
3234 return _typedData._getInt8(offsetInBytes +
3235 (index * Int8List.BYTES_PER_ELEMENT));
3236 }
3237
3238 void operator[]=(int index, int value) {
3239 if (index < 0 || index >= length) {
3240 throw new RangeError.index(index, this, "index");
3241 }
3242 _typedData._setInt8(offsetInBytes + (index * Int8List.BYTES_PER_ELEMENT),
3243 _toInt8(value));
3244 }
3245
3246
3247 // Method(s) implementing TypedData interface.
3248
3249 int get elementSizeInBytes {
3250 return Int8List.BYTES_PER_ELEMENT;
3251 }
3252
3253
3254 // Internal utility methods.
3255
3256 Int8List _createList(int length) {
3257 return new Int8List(length);
3258 }
3259 }
3260
3261
3262 class _Uint8ArrayView extends _TypedListView with _IntListMixin implements Uint8 List {
3263 // Constructor.
3264 _Uint8ArrayView(ByteBuffer buffer, [int _offsetInBytes = 0, int _length])
3265 : super(buffer, _offsetInBytes,
3266 _defaultIfNull(_length,
3267 ((buffer.lengthInBytes - _offsetInBytes) ~/
3268 Uint8List.BYTES_PER_ELEMENT))) {
3269 _rangeCheck(buffer.lengthInBytes,
3270 _offsetInBytes,
3271 length * Uint8List.BYTES_PER_ELEMENT);
3272 }
3273
3274
3275 // Method(s) implementing List interface.
3276
3277 int operator[](int index) {
3278 if (index < 0 || index >= length) {
3279 throw new RangeError.index(index, this, "index");
3280 }
3281 return _typedData._getUint8(offsetInBytes +
3282 (index * Uint8List.BYTES_PER_ELEMENT));
3283 }
3284
3285 void operator[]=(int index, int value) {
3286 if (index < 0 || index >= length) {
3287 throw new RangeError.index(index, this, "index");
3288 }
3289 _typedData._setUint8(offsetInBytes + (index * Uint8List.BYTES_PER_ELEMENT),
3290 _toUint8(value));
3291 }
3292
3293
3294 // Method(s) implementing TypedData interface.
3295
3296 int get elementSizeInBytes {
3297 return Uint8List.BYTES_PER_ELEMENT;
3298 }
3299
3300
3301 // Internal utility methods.
3302
3303 Uint8List _createList(int length) {
3304 return new Uint8List(length);
3305 }
3306 }
3307
3308
3309 class _Uint8ClampedArrayView extends _TypedListView with _IntListMixin implement s Uint8ClampedList {
3310 // Constructor.
3311 _Uint8ClampedArrayView(ByteBuffer buffer,
3312 [int _offsetInBytes = 0, int _length])
3313 : super(buffer, _offsetInBytes,
3314 _defaultIfNull(_length,
3315 ((buffer.lengthInBytes - _offsetInBytes) ~/
3316 Uint8List.BYTES_PER_ELEMENT))) {
3317 _rangeCheck(buffer.lengthInBytes,
3318 offsetInBytes,
3319 length * Uint8List.BYTES_PER_ELEMENT);
3320 }
3321
3322
3323 // Method(s) implementing List interface.
3324
3325 int operator[](int index) {
3326 if (index < 0 || index >= length) {
3327 throw new RangeError.index(index, this, "index");
3328 }
3329 return _typedData._getUint8(offsetInBytes +
3330 (index * Uint8List.BYTES_PER_ELEMENT));
3331 }
3332
3333 void operator[]=(int index, int value) {
3334 if (index < 0 || index >= length) {
3335 throw new RangeError.index(index, this, "index");
3336 }
3337 _typedData._setUint8(offsetInBytes + (index * Uint8List.BYTES_PER_ELEMENT),
3338 _toClampedUint8(value));
3339 }
3340
3341
3342 // Method(s) implementing TypedData interface.
3343
3344 int get elementSizeInBytes {
3345 return Uint8List.BYTES_PER_ELEMENT;
3346 }
3347
3348
3349 // Internal utility methods.
3350
3351 Uint8ClampedList _createList(int length) {
3352 return new Uint8ClampedList(length);
3353 }
3354 }
3355
3356
3357 class _Int16ArrayView extends _TypedListView with _IntListMixin implements Int16 List {
3358 // Constructor.
3359 _Int16ArrayView(ByteBuffer buffer, [int _offsetInBytes = 0, int _length])
3360 : super(buffer, _offsetInBytes,
3361 _defaultIfNull(_length,
3362 ((buffer.lengthInBytes - _offsetInBytes) ~/
3363 Int16List.BYTES_PER_ELEMENT))) {
3364 _rangeCheck(buffer.lengthInBytes,
3365 offsetInBytes,
3366 length * Int16List.BYTES_PER_ELEMENT);
3367 _offsetAlignmentCheck(_offsetInBytes, Int16List.BYTES_PER_ELEMENT);
3368 }
3369
3370
3371 // Method(s) implementing List interface.
3372
3373 int operator[](int index) {
3374 if (index < 0 || index >= length) {
3375 throw new RangeError.index(index, this, "index");
3376 }
3377 return _typedData._getInt16(offsetInBytes +
3378 (index * Int16List.BYTES_PER_ELEMENT));
3379 }
3380
3381 void operator[]=(int index, int value) {
3382 if (index < 0 || index >= length) {
3383 throw new RangeError.index(index, this, "index");
3384 }
3385 _typedData._setInt16(offsetInBytes + (index * Int16List.BYTES_PER_ELEMENT),
3386 _toInt16(value));
3387 }
3388
3389 void setRange(int start, int end, Iterable iterable, [int skipCount = 0]) {
3390 if (iterable is CodeUnits) {
3391 end = RangeError.checkValidRange(start, end, this.length);
3392 int length = end - start;
3393 int byteStart = this.offsetInBytes + start * Int16List.BYTES_PER_ELEMENT;
3394 _typedData._setCodeUnits(iterable, byteStart, length, skipCount);
3395 } else {
3396 super.setRange(start, end, iterable, skipCount);
3397 }
3398 }
3399
3400 // Method(s) implementing TypedData interface.
3401
3402 int get elementSizeInBytes {
3403 return Int16List.BYTES_PER_ELEMENT;
3404 }
3405
3406
3407 // Internal utility methods.
3408
3409 Int16List _createList(int length) {
3410 return new Int16List(length);
3411 }
3412 }
3413
3414
3415 class _Uint16ArrayView extends _TypedListView with _IntListMixin implements Uint 16List {
3416 // Constructor.
3417 _Uint16ArrayView(ByteBuffer buffer, [int _offsetInBytes = 0, int _length])
3418 : super(buffer, _offsetInBytes,
3419 _defaultIfNull(_length,
3420 ((buffer.lengthInBytes - _offsetInBytes) ~/
3421 Uint16List.BYTES_PER_ELEMENT))) {
3422 _rangeCheck(buffer.lengthInBytes,
3423 offsetInBytes,
3424 length * Uint16List.BYTES_PER_ELEMENT);
3425 _offsetAlignmentCheck(_offsetInBytes, Uint16List.BYTES_PER_ELEMENT);
3426 }
3427
3428
3429 // Method(s) implementing List interface.
3430
3431 int operator[](int index) {
3432 if (index < 0 || index >= length) {
3433 throw new RangeError.index(index, this, "index");
3434 }
3435 return _typedData._getUint16(offsetInBytes +
3436 (index * Uint16List.BYTES_PER_ELEMENT));
3437 }
3438
3439 void operator[]=(int index, int value) {
3440 if (index < 0 || index >= length) {
3441 throw new RangeError.index(index, this, "index");
3442 }
3443 _typedData._setUint16(offsetInBytes + (index * Uint16List.BYTES_PER_ELEMENT) ,
3444 _toUint16(value));
3445 }
3446
3447 void setRange(int start, int end, Iterable iterable, [int skipCount = 0]) {
3448 if (iterable is CodeUnits) {
3449 end = RangeError.checkValidRange(start, end, this.length);
3450 int length = end - start;
3451 int byteStart = this.offsetInBytes + start * Uint16List.BYTES_PER_ELEMENT;
3452 _typedData._setCodeUnits(iterable, byteStart, length, skipCount);
3453 } else {
3454 super.setRange(start, end, iterable, skipCount);
3455 }
3456 }
3457
3458 // Method(s) implementing TypedData interface.
3459
3460 int get elementSizeInBytes {
3461 return Uint16List.BYTES_PER_ELEMENT;
3462 }
3463
3464 // Internal utility methods.
3465
3466 Uint16List _createList(int length) {
3467 return new Uint16List(length);
3468 }
3469 }
3470
3471
3472 class _Int32ArrayView extends _TypedListView with _IntListMixin implements Int32 List {
3473 // Constructor.
3474 _Int32ArrayView(ByteBuffer buffer, [int _offsetInBytes = 0, int _length])
3475 : super(buffer, _offsetInBytes,
3476 _defaultIfNull(_length,
3477 ((buffer.lengthInBytes - _offsetInBytes) ~/
3478 Int32List.BYTES_PER_ELEMENT))) {
3479 _rangeCheck(buffer.lengthInBytes,
3480 offsetInBytes,
3481 length * Int32List.BYTES_PER_ELEMENT);
3482 _offsetAlignmentCheck(_offsetInBytes, Int32List.BYTES_PER_ELEMENT);
3483 }
3484
3485
3486 // Method(s) implementing List interface.
3487
3488 int operator[](int index) {
3489 if (index < 0 || index >= length) {
3490 throw new RangeError.index(index, this, "index");
3491 }
3492 return _typedData._getInt32(offsetInBytes +
3493 (index * Int32List.BYTES_PER_ELEMENT));
3494 }
3495
3496 void operator[]=(int index, int value) {
3497 if (index < 0 || index >= length) {
3498 throw new RangeError.index(index, this, "index");
3499 }
3500 _typedData._setInt32(offsetInBytes + (index * Int32List.BYTES_PER_ELEMENT),
3501 _toInt32(value));
3502 }
3503
3504
3505 // Method(s) implementing TypedData interface.
3506
3507 int get elementSizeInBytes {
3508 return Int32List.BYTES_PER_ELEMENT;
3509 }
3510
3511
3512 // Internal utility methods.
3513
3514 Int32List _createList(int length) {
3515 return new Int32List(length);
3516 }
3517 }
3518
3519
3520 class _Uint32ArrayView extends _TypedListView with _IntListMixin implements Uint 32List {
3521 // Constructor.
3522 _Uint32ArrayView(ByteBuffer buffer, [int _offsetInBytes = 0, int _length])
3523 : super(buffer, _offsetInBytes,
3524 _defaultIfNull(_length,
3525 ((buffer.lengthInBytes - _offsetInBytes) ~/
3526 Uint32List.BYTES_PER_ELEMENT))) {
3527 _rangeCheck(buffer.lengthInBytes,
3528 offsetInBytes,
3529 length * Uint32List.BYTES_PER_ELEMENT);
3530 _offsetAlignmentCheck(_offsetInBytes, Uint32List.BYTES_PER_ELEMENT);
3531 }
3532
3533
3534 // Method(s) implementing List interface.
3535
3536 int operator[](int index) {
3537 if (index < 0 || index >= length) {
3538 throw new RangeError.index(index, this, "index");
3539 }
3540 return _typedData._getUint32(offsetInBytes +
3541 (index * Uint32List.BYTES_PER_ELEMENT));
3542 }
3543
3544 void operator[]=(int index, int value) {
3545 if (index < 0 || index >= length) {
3546 throw new RangeError.index(index, this, "index");
3547 }
3548 _typedData._setUint32(offsetInBytes + (index * Uint32List.BYTES_PER_ELEMENT) ,
3549 _toUint32(value));
3550 }
3551
3552
3553 // Method(s) implementing TypedData interface.
3554
3555 int get elementSizeInBytes {
3556 return Uint32List.BYTES_PER_ELEMENT;
3557 }
3558
3559
3560 // Internal utility methods.
3561
3562 Uint32List _createList(int length) {
3563 return new Uint32List(length);
3564 }
3565 }
3566
3567
3568 class _Int64ArrayView extends _TypedListView with _IntListMixin implements Int64 List {
3569 // Constructor.
3570 _Int64ArrayView(ByteBuffer buffer, [int _offsetInBytes = 0, int _length])
3571 : super(buffer, _offsetInBytes,
3572 _defaultIfNull(_length,
3573 ((buffer.lengthInBytes - _offsetInBytes) ~/
3574 Int64List.BYTES_PER_ELEMENT))) {
3575 _rangeCheck(buffer.lengthInBytes,
3576 offsetInBytes,
3577 length * Int64List.BYTES_PER_ELEMENT);
3578 _offsetAlignmentCheck(_offsetInBytes, Int64List.BYTES_PER_ELEMENT);
3579 }
3580
3581
3582 // Method(s) implementing List interface.
3583
3584 int operator[](int index) {
3585 if (index < 0 || index >= length) {
3586 throw new RangeError.index(index, this, "index");
3587 }
3588 return _typedData._getInt64(offsetInBytes +
3589 (index * Int64List.BYTES_PER_ELEMENT));
3590 }
3591
3592 void operator[]=(int index, int value) {
3593 if (index < 0 || index >= length) {
3594 throw new RangeError.index(index, this, "index");
3595 }
3596 _typedData._setInt64(offsetInBytes + (index * Int64List.BYTES_PER_ELEMENT),
3597 _toInt64(value));
3598 }
3599
3600
3601 // Method(s) implementing TypedData interface.
3602
3603 int get elementSizeInBytes {
3604 return Int64List.BYTES_PER_ELEMENT;
3605 }
3606
3607
3608 // Internal utility methods.
3609
3610 Int64List _createList(int length) {
3611 return new Int64List(length);
3612 }
3613 }
3614
3615
3616 class _Uint64ArrayView extends _TypedListView with _IntListMixin implements Uint 64List {
3617 // Constructor.
3618 _Uint64ArrayView(ByteBuffer buffer, [int _offsetInBytes = 0, int _length])
3619 : super(buffer, _offsetInBytes,
3620 _defaultIfNull(_length,
3621 ((buffer.lengthInBytes - _offsetInBytes) ~/
3622 Uint64List.BYTES_PER_ELEMENT))) {
3623 _rangeCheck(buffer.lengthInBytes,
3624 offsetInBytes,
3625 length * Uint64List.BYTES_PER_ELEMENT);
3626 _offsetAlignmentCheck(_offsetInBytes, Uint64List.BYTES_PER_ELEMENT);
3627 }
3628
3629
3630 // Method(s) implementing List interface.
3631
3632 int operator[](int index) {
3633 if (index < 0 || index >= length) {
3634 throw new RangeError.index(index, this, "index");
3635 }
3636 return _typedData._getUint64(offsetInBytes +
3637 (index * Uint64List.BYTES_PER_ELEMENT));
3638 }
3639
3640 void operator[]=(int index, int value) {
3641 if (index < 0 || index >= length) {
3642 throw new RangeError.index(index, this, "index");
3643 }
3644 _typedData._setUint64(offsetInBytes + (index * Uint64List.BYTES_PER_ELEMENT) ,
3645 _toUint64(value));
3646 }
3647
3648
3649 // Method(s) implementing TypedData interface.
3650
3651 int get elementSizeInBytes {
3652 return Uint64List.BYTES_PER_ELEMENT;
3653 }
3654
3655
3656 // Internal utility methods.
3657
3658 Uint64List _createList(int length) {
3659 return new Uint64List(length);
3660 }
3661 }
3662
3663
3664 class _Float32ArrayView extends _TypedListView with _DoubleListMixin implements Float32List {
3665 // Constructor.
3666 _Float32ArrayView(ByteBuffer buffer, [int _offsetInBytes = 0, int _length])
3667 : super(buffer, _offsetInBytes,
3668 _defaultIfNull(_length,
3669 ((buffer.lengthInBytes - _offsetInBytes) ~/
3670 Float32List.BYTES_PER_ELEMENT))) {
3671 _rangeCheck(buffer.lengthInBytes,
3672 offsetInBytes,
3673 length * Float32List.BYTES_PER_ELEMENT);
3674 _offsetAlignmentCheck(_offsetInBytes, Float32List.BYTES_PER_ELEMENT);
3675 }
3676
3677
3678 // Method(s) implementing List interface.
3679
3680 double operator[](int index) {
3681 if (index < 0 || index >= length) {
3682 throw new RangeError.index(index, this, "index");
3683 }
3684 return _typedData._getFloat32(offsetInBytes +
3685 (index * Float32List.BYTES_PER_ELEMENT));
3686 }
3687
3688 void operator[]=(int index, double value) {
3689 if (index < 0 || index >= length) {
3690 throw new RangeError.index(index, this, "index");
3691 }
3692 _typedData._setFloat32(offsetInBytes +
3693 (index * Float32List.BYTES_PER_ELEMENT), value);
3694 }
3695
3696
3697 // Method(s) implementing TypedData interface.
3698
3699 int get elementSizeInBytes {
3700 return Float32List.BYTES_PER_ELEMENT;
3701 }
3702
3703
3704 // Internal utility methods.
3705
3706 Float32List _createList(int length) {
3707 return new Float32List(length);
3708 }
3709 }
3710
3711
3712 class _Float64ArrayView extends _TypedListView with _DoubleListMixin implements Float64List {
3713 // Constructor.
3714 _Float64ArrayView(ByteBuffer buffer, [int _offsetInBytes = 0, int _length])
3715 : super(buffer, _offsetInBytes,
3716 _defaultIfNull(_length,
3717 ((buffer.lengthInBytes - _offsetInBytes) ~/
3718 Float64List.BYTES_PER_ELEMENT))) {
3719 _rangeCheck(buffer.lengthInBytes,
3720 offsetInBytes,
3721 length * Float64List.BYTES_PER_ELEMENT);
3722 _offsetAlignmentCheck(_offsetInBytes, Float64List.BYTES_PER_ELEMENT);
3723 }
3724
3725
3726 // Method(s) implementing List interface.
3727
3728 double operator[](int index) {
3729 if (index < 0 || index >= length) {
3730 throw new RangeError.index(index, this, "index");
3731 }
3732 return _typedData._getFloat64(offsetInBytes +
3733 (index * Float64List.BYTES_PER_ELEMENT));
3734 }
3735
3736 void operator[]=(int index, double value) {
3737 if (index < 0 || index >= length) {
3738 throw new RangeError.index(index, this, "index");
3739 }
3740 _typedData._setFloat64(offsetInBytes +
3741 (index * Float64List.BYTES_PER_ELEMENT), value);
3742 }
3743
3744
3745 // Method(s) implementing TypedData interface.
3746
3747 int get elementSizeInBytes {
3748 return Float64List.BYTES_PER_ELEMENT;
3749 }
3750
3751
3752 // Internal utility methods.
3753
3754 Float64List _createList(int length) {
3755 return new Float64List(length);
3756 }
3757 }
3758
3759
3760 class _Float32x4ArrayView extends _TypedListView with _Float32x4ListMixin implem ents Float32x4List {
3761 // Constructor.
3762 _Float32x4ArrayView(ByteBuffer buffer, [int _offsetInBytes = 0, int _length])
3763 : super(buffer, _offsetInBytes,
3764 _defaultIfNull(_length,
3765 ((buffer.lengthInBytes - _offsetInBytes) ~/
3766 Float32x4List.BYTES_PER_ELEMENT))) {
3767 _rangeCheck(buffer.lengthInBytes,
3768 offsetInBytes,
3769 length * Float32x4List.BYTES_PER_ELEMENT);
3770 _offsetAlignmentCheck(_offsetInBytes, Float32x4List.BYTES_PER_ELEMENT);
3771 }
3772
3773
3774 // Method(s) implementing List interface.
3775
3776 Float32x4 operator[](int index) {
3777 if (index < 0 || index >= length) {
3778 throw new RangeError.index(index, this, "index");
3779 }
3780 return _typedData._getFloat32x4(offsetInBytes +
3781 (index * Float32x4List.BYTES_PER_ELEMENT));
3782 }
3783
3784 void operator[]=(int index, Float32x4 value) {
3785 if (index < 0 || index >= length) {
3786 throw new RangeError.index(index, this, "index");
3787 }
3788 _typedData._setFloat32x4(offsetInBytes +
3789 (index * Float32x4List.BYTES_PER_ELEMENT), value);
3790 }
3791
3792
3793 // Method(s) implementing TypedData interface.
3794
3795 int get elementSizeInBytes {
3796 return Float32x4List.BYTES_PER_ELEMENT;
3797 }
3798
3799
3800 // Internal utility methods.
3801
3802 Float32x4List _createList(int length) {
3803 return new Float32x4List(length);
3804 }
3805 }
3806
3807
3808 class _Int32x4ArrayView extends _TypedListView with _Int32x4ListMixin implements Int32x4List {
3809 // Constructor.
3810 _Int32x4ArrayView(ByteBuffer buffer, [int _offsetInBytes = 0, int _length])
3811 : super(buffer, _offsetInBytes,
3812 _defaultIfNull(_length,
3813 ((buffer.lengthInBytes - _offsetInBytes) ~/
3814 Int32x4List.BYTES_PER_ELEMENT))) {
3815 _rangeCheck(buffer.lengthInBytes,
3816 offsetInBytes,
3817 length * Int32x4List.BYTES_PER_ELEMENT);
3818 _offsetAlignmentCheck(_offsetInBytes, Int32x4List.BYTES_PER_ELEMENT);
3819 }
3820
3821
3822 // Method(s) implementing List interface.
3823
3824 Int32x4 operator[](int index) {
3825 if (index < 0 || index >= length) {
3826 throw new RangeError.index(index, this, "index");
3827 }
3828 return _typedData._getInt32x4(offsetInBytes +
3829 (index * Int32x4List.BYTES_PER_ELEMENT));
3830 }
3831
3832 void operator[]=(int index, Int32x4 value) {
3833 if (index < 0 || index >= length) {
3834 throw new RangeError.index(index, this, "index");
3835 }
3836 _typedData._setInt32x4(offsetInBytes +
3837 (index * Int32x4List.BYTES_PER_ELEMENT), value);
3838 }
3839
3840
3841 // Method(s) implementing TypedData interface.
3842
3843 int get elementSizeInBytes {
3844 return Int32x4List.BYTES_PER_ELEMENT;
3845 }
3846
3847
3848 // Internal utility methods.
3849
3850 Int32x4List _createList(int length) {
3851 return new Int32x4List(length);
3852 }
3853 }
3854
3855
3856 class _Float64x2ArrayView extends _TypedListView with _Float64x2ListMixin implem ents Float64x2List {
3857 // Constructor.
3858 _Float64x2ArrayView(ByteBuffer buffer, [int _offsetInBytes = 0, int _length])
3859 : super(buffer, _offsetInBytes,
3860 _defaultIfNull(_length,
3861 ((buffer.lengthInBytes - _offsetInBytes) ~/
3862 Float64x2List.BYTES_PER_ELEMENT))) {
3863 _rangeCheck(buffer.lengthInBytes,
3864 offsetInBytes,
3865 length * Float64x2List.BYTES_PER_ELEMENT);
3866 _offsetAlignmentCheck(_offsetInBytes, Float64x2List.BYTES_PER_ELEMENT);
3867 }
3868
3869
3870 // Method(s) implementing List interface.
3871
3872 Float64x2 operator[](int index) {
3873 if (index < 0 || index >= length) {
3874 throw new RangeError.index(index, this, "index");
3875 }
3876 return _typedData._getFloat64x2(offsetInBytes +
3877 (index * Float64x2List.BYTES_PER_ELEMENT));
3878 }
3879
3880 void operator[]=(int index, Float64x2 value) {
3881 if (index < 0 || index >= length) {
3882 throw new RangeError.index(index, this, "index");
3883 }
3884 _typedData._setFloat64x2(offsetInBytes +
3885 (index * Float64x2List.BYTES_PER_ELEMENT), value);
3886 }
3887
3888
3889 // Method(s) implementing TypedData interface.
3890
3891 int get elementSizeInBytes {
3892 return Float64x2List.BYTES_PER_ELEMENT;
3893 }
3894
3895
3896 // Internal utility methods.
3897
3898 Float64x2List _createList(int length) {
3899 return new Float64x2List(length);
3900 }
3901 }
3902
3903
3904 class _ByteDataView implements ByteData {
3905 _ByteDataView(TypedData typedData, int _offsetInBytes, int _lengthInBytes)
3906 : _typedData = typedData,
3907 _offset = _offsetInBytes,
3908 length = _lengthInBytes {
3909 _rangeCheck(_typedData.lengthInBytes, _offset, length);
3910 }
3911
3912
3913 // Method(s) implementing TypedData interface.
3914
3915 ByteBuffer get buffer {
3916 return _typedData.buffer;
3917 }
3918
3919 int get lengthInBytes {
3920 return length;
3921 }
3922
3923 int get offsetInBytes {
3924 return _offset;
3925 }
3926
3927 int get elementSizeInBytes {
3928 return 1;
3929 }
3930
3931 // Method(s) implementing ByteData interface.
3932
3933 int getInt8(int byteOffset) {
3934 if (byteOffset < 0 || byteOffset >= length) {
3935 throw new RangeError.index(byteOffset, this, "byteOffset");
3936 }
3937 return _typedData._getInt8(_offset + byteOffset);
3938 }
3939 void setInt8(int byteOffset, int value) {
3940 if (byteOffset < 0 || byteOffset >= length) {
3941 throw new RangeError.index(byteOffset, this, "byteOffset");
3942 }
3943 _typedData._setInt8(_offset + byteOffset, value);
3944 }
3945
3946 int getUint8(int byteOffset) {
3947 if (byteOffset < 0 || byteOffset >= length) {
3948 throw new RangeError.index(byteOffset, this, "byteOffset");
3949 }
3950 return _typedData._getUint8(_offset + byteOffset);
3951 }
3952 void setUint8(int byteOffset, int value) {
3953 if (byteOffset < 0 || byteOffset >= length) {
3954 throw new RangeError.index(byteOffset, this, "byteOffset");
3955 }
3956 _typedData._setUint8(_offset + byteOffset, value);
3957 }
3958
3959 int getInt16(int byteOffset, [Endianness endian = Endianness.BIG_ENDIAN]) {
3960 if (byteOffset < 0 || byteOffset + 1 >= length) {
3961 throw new RangeError.range(byteOffset, 0, length - 2, "byteOffset");
3962 }
3963 var result = _typedData._getInt16(_offset + byteOffset);
3964 if (identical(endian, Endianness.HOST_ENDIAN)) {
3965 return result;
3966 }
3967 return _byteSwap16(result).toSigned(16);
3968 }
3969 void setInt16(int byteOffset,
3970 int value,
3971 [Endianness endian = Endianness.BIG_ENDIAN]) {
3972 if (byteOffset < 0 || byteOffset + 1 >= length) {
3973 throw new RangeError.range(byteOffset, 0, length - 2, "byteOffset");
3974 }
3975 _typedData._setInt16(_offset + byteOffset,
3976 identical(endian, Endianness.HOST_ENDIAN) ? value : _byteSwap16(value));
3977 }
3978
3979 int getUint16(int byteOffset, [Endianness endian = Endianness.BIG_ENDIAN]) {
3980 if (byteOffset < 0 || byteOffset + 1 >= length) {
3981 throw new RangeError.range(byteOffset, 0, length - 2, "byteOffset");
3982 }
3983 var result = _typedData._getUint16(_offset + byteOffset);
3984 if (identical(endian, Endianness.HOST_ENDIAN)) {
3985 return result;
3986 }
3987 return _byteSwap16(result);
3988 }
3989 void setUint16(int byteOffset,
3990 int value,
3991 [Endianness endian = Endianness.BIG_ENDIAN]) {
3992 if (byteOffset < 0 || byteOffset + 1 >= length) {
3993 throw new RangeError.range(byteOffset, 0, length - 2, "byteOffset");
3994 }
3995 _typedData._setUint16(_offset + byteOffset,
3996 identical(endian, Endianness.HOST_ENDIAN) ? value : _byteSwap16(value));
3997 }
3998
3999 int getInt32(int byteOffset, [Endianness endian = Endianness.BIG_ENDIAN]) {
4000 if (byteOffset < 0 || byteOffset + 3 >= length) {
4001 throw new RangeError.range(byteOffset, 0, length - 4, "byteOffset");
4002 }
4003 var result = _typedData._getInt32(_offset + byteOffset);
4004 if (identical(endian, Endianness.HOST_ENDIAN)) {
4005 return result;
4006 }
4007 return _byteSwap32(result).toSigned(32);
4008 }
4009 void setInt32(int byteOffset,
4010 int value,
4011 [Endianness endian = Endianness.BIG_ENDIAN]) {
4012 if (byteOffset < 0 || byteOffset + 3 >= length) {
4013 throw new RangeError.range(byteOffset, 0, length - 4, "byteOffset");
4014 }
4015 _typedData._setInt32(_offset + byteOffset,
4016 identical(endian, Endianness.HOST_ENDIAN) ? value : _byteSwap32(value));
4017 }
4018
4019 int getUint32(int byteOffset, [Endianness endian = Endianness.BIG_ENDIAN]) {
4020 if (byteOffset < 0 || byteOffset + 3 >= length) {
4021 throw new RangeError.range(byteOffset, 0, length - 4, "byteOffset");
4022 }
4023 var result = _typedData._getUint32(_offset + byteOffset);
4024 if (identical(endian, Endianness.HOST_ENDIAN)) {
4025 return result;
4026 }
4027 return _byteSwap32(result);
4028 }
4029 void setUint32(int byteOffset,
4030 int value,
4031 [Endianness endian = Endianness.BIG_ENDIAN]) {
4032 if (byteOffset < 0 || byteOffset + 3 >= length) {
4033 throw new RangeError.range(byteOffset, 0, length - 4, "byteOffset");
4034 }
4035 _typedData._setUint32(_offset + byteOffset,
4036 identical(endian, Endianness.HOST_ENDIAN) ? value : _byteSwap32(value));
4037 }
4038
4039 int getInt64(int byteOffset, [Endianness endian = Endianness.BIG_ENDIAN]) {
4040 if (byteOffset < 0 || byteOffset + 7 >= length) {
4041 throw new RangeError.range(byteOffset, 0, length - 8, "byteOffset");
4042 }
4043 var result = _typedData._getInt64(_offset + byteOffset);
4044 if (identical(endian, Endianness.HOST_ENDIAN)) {
4045 return result;
4046 }
4047 return _byteSwap64(result).toSigned(64);
4048 }
4049 void setInt64(int byteOffset,
4050 int value,
4051 [Endianness endian = Endianness.BIG_ENDIAN]) {
4052 if (byteOffset < 0 || byteOffset + 7 >= length) {
4053 throw new RangeError.range(byteOffset, 0, length - 8, "byteOffset");
4054 }
4055 _typedData._setInt64(_offset + byteOffset,
4056 identical(endian, Endianness.HOST_ENDIAN) ? value : _byteSwap64(value));
4057 }
4058
4059 int getUint64(int byteOffset, [Endianness endian = Endianness.BIG_ENDIAN]) {
4060 if (byteOffset < 0 || byteOffset + 7 >= length) {
4061 throw new RangeError.range(byteOffset, 0, length - 8, "byteOffset");
4062 }
4063 var result = _typedData._getUint64(_offset + byteOffset);
4064 if (identical(endian, Endianness.HOST_ENDIAN)) {
4065 return result;
4066 }
4067 return _byteSwap64(result);
4068 }
4069 void setUint64(int byteOffset,
4070 int value,
4071 [Endianness endian = Endianness.BIG_ENDIAN]) {
4072 if (byteOffset < 0 || byteOffset + 7 >= length) {
4073 throw new RangeError.range(byteOffset, 0, length - 8, "byteOffset");
4074 }
4075 _typedData._setUint64(_offset + byteOffset,
4076 identical(endian, Endianness.HOST_ENDIAN) ? value : _byteSwap64(value));
4077 }
4078
4079 double getFloat32(int byteOffset,
4080 [Endianness endian = Endianness.BIG_ENDIAN]) {
4081 if (byteOffset < 0 || byteOffset + 3 >= length) {
4082 throw new RangeError.range(byteOffset, 0, length - 4, "byteOffset");
4083 }
4084 if (identical(endian, Endianness.HOST_ENDIAN)) {
4085 return _typedData._getFloat32(_offset + byteOffset);
4086 }
4087 _convU32[0] = _byteSwap32(_typedData._getUint32(_offset + byteOffset));
4088 return _convF32[0];
4089 }
4090 void setFloat32(int byteOffset,
4091 double value,
4092 [Endianness endian = Endianness.BIG_ENDIAN]) {
4093 if (byteOffset < 0 || byteOffset + 3 >= length) {
4094 throw new RangeError.range(byteOffset, 0, length - 4, "byteOffset");
4095 }
4096 if (identical(endian, Endianness.HOST_ENDIAN)) {
4097 _typedData._setFloat32(_offset + byteOffset, value);
4098 return;
4099 }
4100 _convF32[0] = value;
4101 _typedData._setUint32(_offset + byteOffset, _byteSwap32(_convU32[0]));
4102 }
4103
4104 double getFloat64(int byteOffset,
4105 [Endianness endian = Endianness.BIG_ENDIAN]) {
4106 if (byteOffset < 0 || byteOffset + 7 >= length) {
4107 throw new RangeError.range(byteOffset, 0, length - 8, "byteOffset");
4108 }
4109 if (identical(endian, Endianness.HOST_ENDIAN)) {
4110 return _typedData._getFloat64(_offset + byteOffset);
4111 }
4112 _convU64[0] = _byteSwap64(_typedData._getUint64(_offset + byteOffset));
4113 return _convF64[0];
4114 }
4115 void setFloat64(int byteOffset,
4116 double value,
4117 [Endianness endian = Endianness.BIG_ENDIAN]) {
4118 if (byteOffset < 0 || byteOffset + 7 >= length) {
4119 throw new RangeError.range(byteOffset, 0, length - 8, "byteOffset");
4120 }
4121 if (identical(endian, Endianness.HOST_ENDIAN)) {
4122 _typedData._setFloat64(_offset + byteOffset, value);
4123 return;
4124 }
4125 _convF64[0] = value;
4126 _typedData._setUint64(_offset + byteOffset, _byteSwap64(_convU64[0]));
4127 }
4128
4129 Float32x4 getFloat32x4(int byteOffset,
4130 [Endianness endian = Endianness.BIG_ENDIAN]) {
4131 if (byteOffset < 0 || byteOffset + 3 >= length) {
4132 throw new RangeError.range(byteOffset, 0, length - 4, "byteOffset");
4133 }
4134 // TODO(johnmccutchan) : Need to resolve this for endianity.
4135 return _typedData._getFloat32x4(_offset + byteOffset);
4136 }
4137 void setFloat32x4(int byteOffset,
4138 Float32x4 value,
4139 [Endianness endian = Endianness.BIG_ENDIAN]) {
4140 if (byteOffset < 0 || byteOffset + 3 >= length) {
4141 throw new RangeError.range(byteOffset, 0, length - 4, "byteOffset");
4142 }
4143 // TODO(johnmccutchan) : Need to resolve this for endianity.
4144 _typedData._setFloat32x4(_offset + byteOffset, value);
4145
4146 }
4147
4148 final TypedData _typedData;
4149 final int _offset;
4150 final int length;
4151 }
4152
4153 int _byteSwap16(int value) {
4154 return ((value & 0xFF00) >> 8) |
4155 ((value & 0x00FF) << 8);
4156 }
4157
4158 int _byteSwap32(int value) {
4159 value = ((value & 0xFF00FF00) >> 8) | ((value & 0x00FF00FF) << 8);
4160 value = ((value & 0xFFFF0000) >> 16) | ((value & 0x0000FFFF) << 16);
4161 return value;
4162 }
4163
4164 int _byteSwap64(int value) {
4165 return (_byteSwap32(value) << 32) | _byteSwap32(value >> 32);
4166 }
4167
4168 final _convU32 = new Uint32List(2);
4169 final _convU64 = new Uint64List.view(_convU32.buffer);
4170 final _convF32 = new Float32List.view(_convU32.buffer);
4171 final _convF64 = new Float64List.view(_convU32.buffer);
4172
4173 // Top level utility methods.
4174 int _toInt(int value, int mask) {
4175 value &= mask;
4176 if (value > (mask >> 1)) value -= mask + 1;
4177 return value;
4178 }
4179
4180
4181 int _toInt8(int value) {
4182 return _toInt(value, 0xFF);
4183 }
4184
4185
4186 int _toUint8(int value) {
4187 return value & 0xFF;
4188 }
4189
4190
4191 int _toClampedUint8(int value) {
4192 if (value < 0) return 0;
4193 if (value > 0xFF) return 0xFF;
4194 return value;
4195 }
4196
4197
4198 int _toInt16(int value) {
4199 return _toInt(value, 0xFFFF);
4200 }
4201
4202
4203 int _toUint16(int value) {
4204 return value & 0xFFFF;
4205 }
4206
4207
4208 int _toInt32(int value) {
4209 return _toInt(value, 0xFFFFFFFF);
4210 }
4211
4212
4213 int _toUint32(int value) {
4214 return value & 0xFFFFFFFF;
4215 }
4216
4217
4218 int _toInt64(int value) {
4219 // Avoid bigint mask when possible.
4220 return (ClassID.getID(value) == ClassID.cidBigint) ?
4221 _toInt(value, 0xFFFFFFFFFFFFFFFF) : value;
4222 }
4223
4224
4225 int _toUint64(int value) {
4226 // Avoid bigint mask when possible.
4227 return (ClassID.getID(value) == ClassID.cidBigint) ?
4228 _toInt(value, 0xFFFFFFFFFFFFFFFF) : value;
4229 }
4230
4231
4232 void _rangeCheck(int listLength, int start, int length) {
4233 if (length < 0) {
4234 throw new RangeError.value(length);
4235 }
4236 if (start < 0) {
4237 throw new RangeError.value(start);
4238 }
4239 if (start + length > listLength) {
4240 throw new RangeError.value(start + length);
4241 }
4242 }
4243
4244
4245 void _offsetAlignmentCheck(int offset, int alignment) {
4246 if ((offset % alignment) != 0) {
4247 throw new RangeError('Offset ($offset) must be a multiple of '
4248 'BYTES_PER_ELEMENT ($alignment)');
4249 }
4250 }
4251
4252
4253 int _defaultIfNull(object, value) {
4254 if (object == null) {
4255 return value;
4256 }
4257 return object;
4258 }
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/typed_data_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698