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

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

Issue 2598603002: Revert "Turn the VM's dart:typed_data into a patch" (Closed)
Patch Set: Created 3 years, 12 months 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 | « runtime/lib/typed_data.dart ('k') | runtime/lib/typed_data_sources.gypi » ('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 import "dart:_internal";
6 import "dart:collection" show ListBase;
7 import 'dart:math' show Random;
8
9 @patch
10 class ByteData implements TypedData {
11 @patch
12 factory ByteData(int length) {
13 var list = new Uint8List(length);
14 return new _ByteDataView(list, 0, length);
15 }
16
17 // Called directly from C code.
18 factory ByteData._view(TypedData typedData, int offsetInBytes, int length) {
19 return new _ByteDataView(typedData, offsetInBytes, length);
20 }
21 }
22
23 // Based class for _TypedList that provides common methods for implementing
24 // the collection and list interfaces.
25 // This class does not extend ListBase<T> since that would add type arguments
26 // to instances of _TypeListBase. Instead the subclasses use type specific
27 // mixins (like _IntListMixin, _DoubleListMixin) to implement ListBase<T>.
28 abstract class _TypedListBase {
29 // Method(s) implementing the Collection interface.
30 bool contains(element) {
31 var len = this.length;
32 for (var i = 0; i < len; ++i) {
33 if (this[i] == element) return true;
34 }
35 return false;
36 }
37
38 void forEach(void f(element)) {
39 var len = this.length;
40 for (var i = 0; i < len; i++) {
41 f(this[i]);
42 }
43 }
44
45 String join([String separator = ""]) {
46 StringBuffer buffer = new StringBuffer();
47 buffer.writeAll(this, separator);
48 return buffer.toString();
49 }
50
51 dynamic reduce(dynamic combine(value, element)) {
52 var len = this.length;
53 if (len == 0) throw IterableElementError.noElement();
54 var i = 0;
55 var value = this[0];
56 for (var i = 1; i < len; ++i) {
57 value = combine(value, this[i]);
58 }
59 return value;
60 }
61
62 dynamic fold(
63 dynamic initialValue, dynamic combine(dynamic initialValue, element)) {
64 var len = this.length;
65 for (var i = 0; i < len; ++i) {
66 initialValue = combine(initialValue, this[i]);
67 }
68 return initialValue;
69 }
70
71 Iterable map(f(element)) => new MappedIterable(this, f);
72
73 Iterable expand(Iterable f(element)) => new ExpandIterable(this, f);
74
75 bool every(bool f(element)) {
76 var len = this.length;
77 for (var i = 0; i < len; ++i) {
78 if (!f(this[i])) return false;
79 }
80 return true;
81 }
82
83 bool any(bool f(element)) {
84 var len = this.length;
85 for (var i = 0; i < len; ++i) {
86 if (f(this[i])) return true;
87 }
88 return false;
89 }
90
91 dynamic firstWhere(bool test(element), {orElse()}) {
92 var len = this.length;
93 for (var i = 0; i < len; ++i) {
94 var element = this[i];
95 if (test(element)) return element;
96 }
97 if (orElse != null) return orElse();
98 throw IterableElementError.noElement();
99 }
100
101 dynamic lastWhere(bool test(element), {orElse()}) {
102 var result = null;
103 var len = this.length;
104 for (var i = len - 1; i >= 0; --i) {
105 var element = this[i];
106 if (test(element)) {
107 return element;
108 }
109 }
110 if (orElse != null) return orElse();
111 throw IterableElementError.noElement();
112 }
113
114 dynamic singleWhere(bool test(element)) {
115 var result = null;
116 bool foundMatching = false;
117 var len = this.length;
118 for (var i = 0; i < len; ++i) {
119 var element = this[i];
120 if (test(element)) {
121 if (foundMatching) {
122 throw IterableElementError.tooMany();
123 }
124 result = element;
125 foundMatching = true;
126 }
127 }
128 if (foundMatching) return result;
129 throw IterableElementError.noElement();
130 }
131
132 dynamic elementAt(int index) {
133 return this[index];
134 }
135
136 bool get isEmpty {
137 return this.length == 0;
138 }
139
140 bool get isNotEmpty => !isEmpty;
141
142 // Method(s) implementing the List interface.
143
144 set length(newLength) {
145 throw new UnsupportedError("Cannot resize a fixed-length list");
146 }
147
148 void add(value) {
149 throw new UnsupportedError("Cannot add to a fixed-length list");
150 }
151
152 void addAll(Iterable value) {
153 throw new UnsupportedError("Cannot add to a fixed-length list");
154 }
155
156 void insert(int index, value) {
157 throw new UnsupportedError("Cannot insert into a fixed-length list");
158 }
159
160 void insertAll(int index, Iterable values) {
161 throw new UnsupportedError("Cannot insert into a fixed-length list");
162 }
163
164 void sort([int compare(a, b)]) {
165 if (compare == null) compare = Comparable.compare;
166 Sort.sort(this, compare);
167 }
168
169 void shuffle([Random random]) {
170 if (random == null) random = new Random();
171 var i = this.length;
172 while (i > 1) {
173 int pos = random.nextInt(i);
174 i -= 1;
175 var tmp = this[i];
176 this[i] = this[pos];
177 this[pos] = tmp;
178 }
179 }
180
181 int indexOf(element, [int start = 0]) {
182 return Lists.indexOf(this, element, start, this.length);
183 }
184
185 int lastIndexOf(element, [int start = null]) {
186 if (start == null) start = this.length - 1;
187 return Lists.lastIndexOf(this, element, start);
188 }
189
190 void clear() {
191 throw new UnsupportedError("Cannot remove from a fixed-length list");
192 }
193
194 int removeLast() {
195 throw new UnsupportedError("Cannot remove from a fixed-length list");
196 }
197
198 bool remove(Object element) {
199 throw new UnsupportedError("Cannot remove from a fixed-length list");
200 }
201
202 bool removeAt(int index) {
203 throw new UnsupportedError("Cannot remove from a fixed-length list");
204 }
205
206 void removeWhere(bool test(element)) {
207 throw new UnsupportedError("Cannot remove from a fixed-length list");
208 }
209
210 void retainWhere(bool test(element)) {
211 throw new UnsupportedError("Cannot remove from a fixed-length list");
212 }
213
214 dynamic get first {
215 if (length > 0) return this[0];
216 throw IterableElementError.noElement();
217 }
218
219 dynamic get last {
220 if (length > 0) return this[length - 1];
221 throw IterableElementError.noElement();
222 }
223
224 dynamic get single {
225 if (length == 1) return this[0];
226 if (length == 0) throw IterableElementError.noElement();
227 throw IterableElementError.tooMany();
228 }
229
230 void removeRange(int start, int end) {
231 throw new UnsupportedError("Cannot remove from a fixed-length list");
232 }
233
234 void replaceRange(int start, int end, Iterable iterable) {
235 throw new UnsupportedError("Cannot remove from a fixed-length list");
236 }
237
238 List toList({bool growable: true}) {
239 return new List.from(this, growable: growable);
240 }
241
242 Set toSet() {
243 return new Set.from(this);
244 }
245
246 List sublist(int start, [int end]) {
247 end = RangeError.checkValidRange(start, end, this.length);
248 var length = end - start;
249 List result = _createList(length);
250 result.setRange(0, length, this, start);
251 return result;
252 }
253
254 void setRange(int start, int end, Iterable from, [int skipCount = 0]) {
255 // Check ranges.
256 if (0 > start || start > end || end > length) {
257 RangeError.checkValidRange(start, end, length); // Always throws.
258 assert(false);
259 }
260 if (skipCount < 0) {
261 throw new ArgumentError(skipCount);
262 }
263
264 final count = end - start;
265 if ((from.length - skipCount) < count) {
266 throw IterableElementError.tooFew();
267 }
268
269 if (from is _TypedListBase) {
270 if (this.elementSizeInBytes == from.elementSizeInBytes) {
271 if ((count < 10) && (from.buffer != this.buffer)) {
272 Lists.copy(from, skipCount, this, start, count);
273 return;
274 } else if (this.buffer._data._setRange(
275 start * elementSizeInBytes + this.offsetInBytes,
276 count * elementSizeInBytes,
277 from.buffer._data,
278 skipCount * elementSizeInBytes + from.offsetInBytes,
279 ClassID.getID(this),
280 ClassID.getID(from))) {
281 return;
282 }
283 } else if (from.buffer == this.buffer) {
284 // Different element sizes, but same buffer means that we need
285 // an intermediate structure.
286 // TODO(srdjan): Optimize to skip copying if the range does not overlap.
287 final temp_buffer = new List(count);
288 for (var i = 0; i < count; i++) {
289 temp_buffer[i] = from[skipCount + i];
290 }
291 for (var i = start; i < end; i++) {
292 this[i] = temp_buffer[i - start];
293 }
294 return;
295 }
296 }
297
298 if (count == 0) return;
299 List otherList;
300 int otherStart;
301 if (from is List) {
302 otherList = from;
303 otherStart = skipCount;
304 } else {
305 otherList = from.skip(skipCount).toList(growable: false);
306 otherStart = 0;
307 }
308 if (otherStart + count > otherList.length) {
309 throw IterableElementError.tooFew();
310 }
311 Lists.copy(otherList, otherStart, this, start, count);
312 }
313
314 void setAll(int index, Iterable iterable) {
315 final end = iterable.length + index;
316 setRange(index, end, iterable);
317 }
318
319 void fillRange(int start, int end, [fillValue]) {
320 RangeError.checkValidRange(start, end, this.length);
321 for (var i = start; i < end; ++i) {
322 this[i] = fillValue;
323 }
324 }
325
326 // Method(s) implementing Object interface.
327 String toString() => ListBase.listToString(this);
328
329 // Internal utility methods.
330
331 // Returns true if operation succeeds.
332 // 'fromCid' and 'toCid' may be cid-s of the views and therefore may not
333 // match the cids of 'this' and 'from'.
334 // Uses toCid and fromCid to decide if clamping is necessary.
335 // Element size of toCid and fromCid must match (test at caller).
336 bool _setRange(int startInBytes, int lengthInBytes, _TypedListBase from,
337 int startFromInBytes, int toCid, int fromCid) native "TypedData_setRange";
338 }
339
340 class _IntListMixin {
341 Iterable<int> where(bool f(int element)) => new WhereIterable<int>(this, f);
342
343 Iterable<int> take(int n) => new SubListIterable<int>(this, 0, n);
344
345 Iterable<int> takeWhile(bool test(int element)) =>
346 new TakeWhileIterable<int>(this, test);
347
348 Iterable<int> skip(int n) => new SubListIterable<int>(this, n, null);
349
350 Iterable<int> skipWhile(bool test(element)) =>
351 new SkipWhileIterable<int>(this, test);
352
353 Iterable<int> get reversed => new ReversedListIterable<int>(this);
354
355 Map<int, int> asMap() => new ListMapView<int>(this);
356
357 Iterable<int> getRange(int start, [int end]) {
358 RangeError.checkValidRange(start, end, this.length);
359 return new SubListIterable<int>(this, start, end);
360 }
361
362 Iterator<int> get iterator => new _TypedListIterator<int>(this);
363
364 List<int> toList({bool growable: true}) {
365 return new List<int>.from(this, growable: growable);
366 }
367
368 Set<int> toSet() {
369 return new Set<int>.from(this);
370 }
371 }
372
373 class _DoubleListMixin {
374 Iterable<double> where(bool f(int element)) =>
375 new WhereIterable<double>(this, f);
376
377 Iterable<double> take(int n) => new SubListIterable<double>(this, 0, n);
378
379 Iterable<double> takeWhile(bool test(int element)) =>
380 new TakeWhileIterable<double>(this, test);
381
382 Iterable<double> skip(int n) => new SubListIterable<double>(this, n, null);
383
384 Iterable<double> skipWhile(bool test(element)) =>
385 new SkipWhileIterable<double>(this, test);
386
387 Iterable<double> get reversed => new ReversedListIterable<double>(this);
388
389 Map<int, double> asMap() => new ListMapView<double>(this);
390
391 Iterable<double> getRange(int start, [int end]) {
392 RangeError.checkValidRange(start, end, this.length);
393 return new SubListIterable<double>(this, start, end);
394 }
395
396 Iterator<double> get iterator => new _TypedListIterator<double>(this);
397
398 List<double> toList({bool growable: true}) {
399 return new List<double>.from(this, growable: growable);
400 }
401
402 Set<double> toSet() {
403 return new Set<double>.from(this);
404 }
405 }
406
407 class _Float32x4ListMixin {
408 Iterable<Float32x4> where(bool f(int element)) =>
409 new WhereIterable<Float32x4>(this, f);
410
411 Iterable<Float32x4> take(int n) => new SubListIterable<Float32x4>(this, 0, n);
412
413 Iterable<Float32x4> takeWhile(bool test(int element)) =>
414 new TakeWhileIterable<Float32x4>(this, test);
415
416 Iterable<Float32x4> skip(int n) =>
417 new SubListIterable<Float32x4>(this, n, null);
418
419 Iterable<Float32x4> skipWhile(bool test(element)) =>
420 new SkipWhileIterable<Float32x4>(this, test);
421
422 Iterable<Float32x4> get reversed => new ReversedListIterable<Float32x4>(this);
423
424 Map<int, Float32x4> asMap() => new ListMapView<Float32x4>(this);
425
426 Iterable<Float32x4> getRange(int start, [int end]) {
427 RangeError.checkValidRange(start, end, this.length);
428 return new SubListIterable<Float32x4>(this, start, end);
429 }
430
431 Iterator<Float32x4> get iterator => new _TypedListIterator<Float32x4>(this);
432
433 List<Float32x4> toList({bool growable: true}) {
434 return new List<Float32x4>.from(this, growable: growable);
435 }
436
437 Set<Float32x4> toSet() {
438 return new Set<Float32x4>.from(this);
439 }
440 }
441
442 class _Int32x4ListMixin {
443 Iterable<Int32x4> where(bool f(int element)) =>
444 new WhereIterable<Int32x4>(this, f);
445
446 Iterable<Int32x4> take(int n) => new SubListIterable<Int32x4>(this, 0, n);
447
448 Iterable<Int32x4> takeWhile(bool test(int element)) =>
449 new TakeWhileIterable<Int32x4>(this, test);
450
451 Iterable<Int32x4> skip(int n) => new SubListIterable<Int32x4>(this, n, null);
452
453 Iterable<Int32x4> skipWhile(bool test(element)) =>
454 new SkipWhileIterable<Int32x4>(this, test);
455
456 Iterable<Int32x4> get reversed => new ReversedListIterable<Int32x4>(this);
457
458 Map<int, Int32x4> asMap() => new ListMapView<Int32x4>(this);
459
460 Iterable<Int32x4> getRange(int start, [int end]) {
461 RangeError.checkValidRange(start, end, this.length);
462 return new SubListIterable<Int32x4>(this, start, end);
463 }
464
465 Iterator<Int32x4> get iterator => new _TypedListIterator<Int32x4>(this);
466
467 List<Int32x4> toList({bool growable: true}) {
468 return new List<Int32x4>.from(this, growable: growable);
469 }
470
471 Set<Int32x4> toSet() {
472 return new Set<Int32x4>.from(this);
473 }
474 }
475
476 class _Float64x2ListMixin {
477 Iterable<Float64x2> where(bool f(int element)) =>
478 new WhereIterable<Float64x2>(this, f);
479
480 Iterable<Float64x2> take(int n) => new SubListIterable<Float64x2>(this, 0, n);
481
482 Iterable<Float64x2> takeWhile(bool test(int element)) =>
483 new TakeWhileIterable<Float64x2>(this, test);
484
485 Iterable<Float64x2> skip(int n) =>
486 new SubListIterable<Float64x2>(this, n, null);
487
488 Iterable<Float64x2> skipWhile(bool test(element)) =>
489 new SkipWhileIterable<Float64x2>(this, test);
490
491 Iterable<Float64x2> get reversed => new ReversedListIterable<Float64x2>(this);
492
493 Map<int, Float64x2> asMap() => new ListMapView<Float64x2>(this);
494
495 Iterable<Float64x2> getRange(int start, [int end]) {
496 RangeError.checkValidRange(start, end, this.length);
497 return new SubListIterable<Float64x2>(this, start, end);
498 }
499
500 Iterator<Float64x2> get iterator => new _TypedListIterator<Float64x2>(this);
501
502 List<Float64x2> toList({bool growable: true}) {
503 return new List<Float64x2>.from(this, growable: growable);
504 }
505
506 Set<Float64x2> toSet() {
507 return new Set<Float64x2>.from(this);
508 }
509 }
510
511 class _ByteBuffer implements ByteBuffer {
512 final _TypedList _data;
513
514 _ByteBuffer(this._data);
515
516 factory _ByteBuffer._New(data) => new _ByteBuffer(data);
517
518 // Forward calls to _data.
519 int get lengthInBytes => _data.lengthInBytes;
520 int get hashCode => _data.hashCode;
521 bool operator ==(Object other) =>
522 (other is _ByteBuffer) && identical(_data, other._data);
523
524 ByteData asByteData([int offsetInBytes = 0, int length]) {
525 if (length == null) {
526 length = this.lengthInBytes - offsetInBytes;
527 }
528 return new _ByteDataView(this._data, offsetInBytes, length);
529 }
530
531 Int8List asInt8List([int offsetInBytes = 0, int length]) {
532 if (length == null) {
533 length = this.lengthInBytes - offsetInBytes;
534 }
535 return new _Int8ArrayView(this, offsetInBytes, length);
536 }
537
538 Uint8List asUint8List([int offsetInBytes = 0, int length]) {
539 if (length == null) {
540 length = this.lengthInBytes - offsetInBytes;
541 }
542 return new _Uint8ArrayView(this, offsetInBytes, length);
543 }
544
545 Uint8ClampedList asUint8ClampedList([int offsetInBytes = 0, int length]) {
546 if (length == null) {
547 length = this.lengthInBytes - offsetInBytes;
548 }
549 return new _Uint8ClampedArrayView(this, offsetInBytes, length);
550 }
551
552 Int16List asInt16List([int offsetInBytes = 0, int length]) {
553 if (length == null) {
554 length =
555 (this.lengthInBytes - offsetInBytes) ~/ Int16List.BYTES_PER_ELEMENT;
556 }
557 return new _Int16ArrayView(this, offsetInBytes, length);
558 }
559
560 Uint16List asUint16List([int offsetInBytes = 0, int length]) {
561 if (length == null) {
562 length =
563 (this.lengthInBytes - offsetInBytes) ~/ Uint16List.BYTES_PER_ELEMENT;
564 }
565 return new _Uint16ArrayView(this, offsetInBytes, length);
566 }
567
568 Int32List asInt32List([int offsetInBytes = 0, int length]) {
569 if (length == null) {
570 length =
571 (this.lengthInBytes - offsetInBytes) ~/ Int32List.BYTES_PER_ELEMENT;
572 }
573 return new _Int32ArrayView(this, offsetInBytes, length);
574 }
575
576 Uint32List asUint32List([int offsetInBytes = 0, int length]) {
577 if (length == null) {
578 length =
579 (this.lengthInBytes - offsetInBytes) ~/ Uint32List.BYTES_PER_ELEMENT;
580 }
581 return new _Uint32ArrayView(this, offsetInBytes, length);
582 }
583
584 Int64List asInt64List([int offsetInBytes = 0, int length]) {
585 if (length == null) {
586 length =
587 (this.lengthInBytes - offsetInBytes) ~/ Int64List.BYTES_PER_ELEMENT;
588 }
589 return new _Int64ArrayView(this, offsetInBytes, length);
590 }
591
592 Uint64List asUint64List([int offsetInBytes = 0, int length]) {
593 if (length == null) {
594 length =
595 (this.lengthInBytes - offsetInBytes) ~/ Uint64List.BYTES_PER_ELEMENT;
596 }
597 return new _Uint64ArrayView(this, offsetInBytes, length);
598 }
599
600 Float32List asFloat32List([int offsetInBytes = 0, int length]) {
601 if (length == null) {
602 length =
603 (this.lengthInBytes - offsetInBytes) ~/ Float32List.BYTES_PER_ELEMENT;
604 }
605 return new _Float32ArrayView(this, offsetInBytes, length);
606 }
607
608 Float64List asFloat64List([int offsetInBytes = 0, int length]) {
609 if (length == null) {
610 length =
611 (this.lengthInBytes - offsetInBytes) ~/ Float64List.BYTES_PER_ELEMENT;
612 }
613 return new _Float64ArrayView(this, offsetInBytes, length);
614 }
615
616 Float32x4List asFloat32x4List([int offsetInBytes = 0, int length]) {
617 if (length == null) {
618 length = (this.lengthInBytes - offsetInBytes) ~/
619 Float32x4List.BYTES_PER_ELEMENT;
620 }
621 return new _Float32x4ArrayView(this, offsetInBytes, length);
622 }
623
624 Int32x4List asInt32x4List([int offsetInBytes = 0, int length]) {
625 if (length == null) {
626 length =
627 (this.lengthInBytes - offsetInBytes) ~/ Int32x4List.BYTES_PER_ELEMENT;
628 }
629 return new _Int32x4ArrayView(this, offsetInBytes, length);
630 }
631
632 Float64x2List asFloat64x2List([int offsetInBytes = 0, int length]) {
633 if (length == null) {
634 length = (this.lengthInBytes - offsetInBytes) ~/
635 Float64x2List.BYTES_PER_ELEMENT;
636 }
637 return new _Float64x2ArrayView(this, offsetInBytes, length);
638 }
639 }
640
641 abstract class _TypedList extends _TypedListBase {
642 // Default method implementing parts of the TypedData interface.
643 int get offsetInBytes {
644 return 0;
645 }
646
647 int get lengthInBytes {
648 return length * elementSizeInBytes;
649 }
650
651 _ByteBuffer get buffer => new _ByteBuffer(this);
652
653 // Methods implementing the collection interface.
654
655 int get length native "TypedData_length";
656
657 // Internal utility methods.
658
659 int _getInt8(int offsetInBytes) native "TypedData_GetInt8";
660 void _setInt8(int offsetInBytes, int value) native "TypedData_SetInt8";
661
662 int _getUint8(int offsetInBytes) native "TypedData_GetUint8";
663 void _setUint8(int offsetInBytes, int value) native "TypedData_SetUint8";
664
665 int _getInt16(int offsetInBytes) native "TypedData_GetInt16";
666 void _setInt16(int offsetInBytes, int value) native "TypedData_SetInt16";
667
668 int _getUint16(int offsetInBytes) native "TypedData_GetUint16";
669 void _setUint16(int offsetInBytes, int value) native "TypedData_SetUint16";
670
671 int _getInt32(int offsetInBytes) native "TypedData_GetInt32";
672 void _setInt32(int offsetInBytes, int value) native "TypedData_SetInt32";
673
674 int _getUint32(int offsetInBytes) native "TypedData_GetUint32";
675 void _setUint32(int offsetInBytes, int value) native "TypedData_SetUint32";
676
677 int _getInt64(int offsetInBytes) native "TypedData_GetInt64";
678 void _setInt64(int offsetInBytes, int value) native "TypedData_SetInt64";
679
680 int _getUint64(int offsetInBytes) native "TypedData_GetUint64";
681 void _setUint64(int offsetInBytes, int value) native "TypedData_SetUint64";
682
683 double _getFloat32(int offsetInBytes) native "TypedData_GetFloat32";
684 void _setFloat32(int offsetInBytes, double value)
685 native "TypedData_SetFloat32";
686
687 double _getFloat64(int offsetInBytes) native "TypedData_GetFloat64";
688 void _setFloat64(int offsetInBytes, double value)
689 native "TypedData_SetFloat64";
690
691 Float32x4 _getFloat32x4(int offsetInBytes) native "TypedData_GetFloat32x4";
692 void _setFloat32x4(int offsetInBytes, Float32x4 value)
693 native "TypedData_SetFloat32x4";
694
695 Int32x4 _getInt32x4(int offsetInBytes) native "TypedData_GetInt32x4";
696 void _setInt32x4(int offsetInBytes, Int32x4 value)
697 native "TypedData_SetInt32x4";
698
699 Float64x2 _getFloat64x2(int offsetInBytes) native "TypedData_GetFloat64x2";
700 void _setFloat64x2(int offsetInBytes, Float64x2 value)
701 native "TypedData_SetFloat64x2";
702
703 /**
704 * Stores the [CodeUnits] as UTF-16 units into this TypedData at
705 * positions [start]..[end] (uint16 indices).
706 */
707 void _setCodeUnits(
708 CodeUnits units, int byteStart, int length, int skipCount) {
709 assert(byteStart + length * Uint16List.BYTES_PER_ELEMENT <= lengthInBytes);
710 String string = CodeUnits.stringOf(units);
711 int sliceEnd = skipCount + length;
712 RangeError.checkValidRange(
713 skipCount, sliceEnd, string.length, "skipCount", "skipCount + length");
714 for (int i = 0; i < length; i++) {
715 _setUint16(byteStart + i * Uint16List.BYTES_PER_ELEMENT,
716 string.codeUnitAt(skipCount + i));
717 }
718 }
719 }
720
721 @patch
722 class Int8List {
723 @patch
724 factory Int8List(int length) native "TypedData_Int8Array_new";
725
726 @patch
727 factory Int8List.fromList(List<int> elements) {
728 return new Int8List(elements.length)
729 ..setRange(0, elements.length, elements);
730 }
731 }
732
733 class _Int8List extends _TypedList with _IntListMixin implements Int8List {
734 Type get runtimeType => Int8List;
735
736 // Method(s) implementing List interface.
737 int operator [](int index) {
738 if (index < 0 || index >= length) {
739 throw new RangeError.index(index, this, "index");
740 }
741 return _getInt8(index);
742 }
743
744 void operator []=(int index, int value) {
745 if (index < 0 || index >= length) {
746 throw new RangeError.index(index, this, "index");
747 }
748 _setInt8(index, _toInt8(value));
749 }
750
751 // Method(s) implementing TypedData interface.
752 int get elementSizeInBytes {
753 return Int8List.BYTES_PER_ELEMENT;
754 }
755
756 // Internal utility methods.
757 Int8List _createList(int length) {
758 return new Int8List(length);
759 }
760 }
761
762 @patch
763 class Uint8List {
764 @patch
765 factory Uint8List(int length) native "TypedData_Uint8Array_new";
766
767 @patch
768 factory Uint8List.fromList(List<int> elements) {
769 return new Uint8List(elements.length)
770 ..setRange(0, elements.length, elements);
771 }
772 }
773
774 class _Uint8List extends _TypedList with _IntListMixin implements Uint8List {
775 Type get runtimeType => Uint8List;
776
777 // Methods implementing List interface.
778 int operator [](int index) {
779 if (index < 0 || index >= length) {
780 throw new RangeError.index(index, this, "index");
781 }
782 return _getUint8(index);
783 }
784
785 void operator []=(int index, int value) {
786 if (index < 0 || index >= length) {
787 throw new RangeError.index(index, this, "index");
788 }
789 _setUint8(index, _toUint8(value));
790 }
791
792 // Methods implementing TypedData interface.
793 int get elementSizeInBytes {
794 return Uint8List.BYTES_PER_ELEMENT;
795 }
796
797 // Internal utility methods.
798 Uint8List _createList(int length) {
799 return new Uint8List(length);
800 }
801 }
802
803 @patch
804 class Uint8ClampedList {
805 @patch
806 factory Uint8ClampedList(int length) native "TypedData_Uint8ClampedArray_new";
807
808 @patch
809 factory Uint8ClampedList.fromList(List<int> elements) {
810 return new Uint8ClampedList(elements.length)
811 ..setRange(0, elements.length, elements);
812 }
813 }
814
815 class _Uint8ClampedList extends _TypedList
816 with _IntListMixin
817 implements Uint8ClampedList {
818 Type get runtimeType => Uint8ClampedList;
819
820 // Methods implementing List interface.
821 int operator [](int index) {
822 if (index < 0 || index >= length) {
823 throw new RangeError.index(index, this, "index");
824 }
825 return _getUint8(index);
826 }
827
828 void operator []=(int index, int value) {
829 if (index < 0 || index >= length) {
830 throw new RangeError.index(index, this, "index");
831 }
832 _setUint8(index, _toClampedUint8(value));
833 }
834
835 // Methods implementing TypedData interface.
836 int get elementSizeInBytes {
837 return Uint8List.BYTES_PER_ELEMENT;
838 }
839
840 // Internal utility methods.
841 Uint8ClampedList _createList(int length) {
842 return new Uint8ClampedList(length);
843 }
844 }
845
846 @patch
847 class Int16List {
848 @patch
849 factory Int16List(int length) native "TypedData_Int16Array_new";
850
851 @patch
852 factory Int16List.fromList(List<int> elements) {
853 return new Int16List(elements.length)
854 ..setRange(0, elements.length, elements);
855 }
856 }
857
858 class _Int16List extends _TypedList with _IntListMixin implements Int16List {
859 Type get runtimeType => Int16List;
860
861 // Method(s) implementing List interface.
862 int operator [](int index) {
863 if (index < 0 || index >= length) {
864 throw new RangeError.index(index, this, "index");
865 }
866 return _getIndexedInt16(index);
867 }
868
869 void operator []=(int index, int value) {
870 if (index < 0 || index >= length) {
871 throw new RangeError.index(index, this, "index");
872 }
873 _setIndexedInt16(index, _toInt16(value));
874 }
875
876 void setRange(int start, int end, Iterable iterable, [int skipCount = 0]) {
877 if (iterable is CodeUnits) {
878 end = RangeError.checkValidRange(start, end, this.length);
879 int length = end - start;
880 int byteStart = this.offsetInBytes + start * Int16List.BYTES_PER_ELEMENT;
881 _setCodeUnits(iterable, byteStart, length, skipCount);
882 } else {
883 super.setRange(start, end, iterable, skipCount);
884 }
885 }
886
887 // Method(s) implementing TypedData interface.
888 int get elementSizeInBytes {
889 return Int16List.BYTES_PER_ELEMENT;
890 }
891
892 // Internal utility methods.
893 Int16List _createList(int length) {
894 return new Int16List(length);
895 }
896
897 int _getIndexedInt16(int index) {
898 return _getInt16(index * Int16List.BYTES_PER_ELEMENT);
899 }
900
901 void _setIndexedInt16(int index, int value) {
902 _setInt16(index * Int16List.BYTES_PER_ELEMENT, value);
903 }
904 }
905
906 @patch
907 class Uint16List {
908 @patch
909 factory Uint16List(int length) native "TypedData_Uint16Array_new";
910
911 @patch
912 factory Uint16List.fromList(List<int> elements) {
913 return new Uint16List(elements.length)
914 ..setRange(0, elements.length, elements);
915 }
916 }
917
918 class _Uint16List extends _TypedList with _IntListMixin implements Uint16List {
919 Type get runtimeType => Uint16List;
920
921 // Method(s) implementing the List interface.
922 int operator [](int index) {
923 if (index < 0 || index >= length) {
924 throw new RangeError.index(index, this, "index");
925 }
926 return _getIndexedUint16(index);
927 }
928
929 void operator []=(int index, int value) {
930 if (index < 0 || index >= length) {
931 throw new RangeError.index(index, this, "index");
932 }
933 _setIndexedUint16(index, _toUint16(value));
934 }
935
936 void setRange(int start, int end, Iterable iterable, [int skipCount = 0]) {
937 if (iterable is CodeUnits) {
938 end = RangeError.checkValidRange(start, end, this.length);
939 int length = end - start;
940 int byteStart = this.offsetInBytes + start * Uint16List.BYTES_PER_ELEMENT;
941 _setCodeUnits(iterable, byteStart, length, skipCount);
942 } else {
943 super.setRange(start, end, iterable, skipCount);
944 }
945 }
946
947 // Method(s) implementing the TypedData interface.
948 int get elementSizeInBytes {
949 return Uint16List.BYTES_PER_ELEMENT;
950 }
951
952 // Internal utility methods.
953 Uint16List _createList(int length) {
954 return new Uint16List(length);
955 }
956
957 int _getIndexedUint16(int index) {
958 return _getUint16(index * Uint16List.BYTES_PER_ELEMENT);
959 }
960
961 void _setIndexedUint16(int index, int value) {
962 _setUint16(index * Uint16List.BYTES_PER_ELEMENT, value);
963 }
964 }
965
966 @patch
967 class Int32List {
968 @patch
969 factory Int32List(int length) native "TypedData_Int32Array_new";
970
971 @patch
972 factory Int32List.fromList(List<int> elements) {
973 return new Int32List(elements.length)
974 ..setRange(0, elements.length, elements);
975 }
976 }
977
978 class _Int32List extends _TypedList with _IntListMixin implements Int32List {
979 Type get runtimeType => Int32List;
980
981 // Method(s) implementing the List interface.
982 int operator [](int index) {
983 if (index < 0 || index >= length) {
984 throw new RangeError.index(index, this, "index");
985 }
986 return _getIndexedInt32(index);
987 }
988
989 void operator []=(int index, int value) {
990 if (index < 0 || index >= length) {
991 throw new RangeError.index(index, this, "index");
992 }
993 _setIndexedInt32(index, _toInt32(value));
994 }
995
996 // Method(s) implementing TypedData interface.
997 int get elementSizeInBytes {
998 return Int32List.BYTES_PER_ELEMENT;
999 }
1000
1001 // Internal utility methods.
1002 Int32List _createList(int length) {
1003 return new Int32List(length);
1004 }
1005
1006 int _getIndexedInt32(int index) {
1007 return _getInt32(index * Int32List.BYTES_PER_ELEMENT);
1008 }
1009
1010 void _setIndexedInt32(int index, int value) {
1011 _setInt32(index * Int32List.BYTES_PER_ELEMENT, value);
1012 }
1013 }
1014
1015 @patch
1016 class Uint32List {
1017 @patch
1018 factory Uint32List(int length) native "TypedData_Uint32Array_new";
1019
1020 @patch
1021 factory Uint32List.fromList(List<int> elements) {
1022 return new Uint32List(elements.length)
1023 ..setRange(0, elements.length, elements);
1024 }
1025 }
1026
1027 class _Uint32List extends _TypedList with _IntListMixin implements Uint32List {
1028 Type get runtimeType => Uint32List;
1029
1030 // Method(s) implementing the List interface.
1031 int operator [](int index) {
1032 if (index < 0 || index >= length) {
1033 throw new RangeError.index(index, this, "index");
1034 }
1035 return _getIndexedUint32(index);
1036 }
1037
1038 void operator []=(int index, int value) {
1039 if (index < 0 || index >= length) {
1040 throw new RangeError.index(index, this, "index");
1041 }
1042 _setIndexedUint32(index, _toUint32(value));
1043 }
1044
1045 // Method(s) implementing the TypedData interface.
1046 int get elementSizeInBytes {
1047 return Uint32List.BYTES_PER_ELEMENT;
1048 }
1049
1050 // Internal utility methods.
1051 Uint32List _createList(int length) {
1052 return new Uint32List(length);
1053 }
1054
1055 int _getIndexedUint32(int index) {
1056 return _getUint32(index * Uint32List.BYTES_PER_ELEMENT);
1057 }
1058
1059 void _setIndexedUint32(int index, int value) {
1060 _setUint32(index * Uint32List.BYTES_PER_ELEMENT, value);
1061 }
1062 }
1063
1064 @patch
1065 class Int64List {
1066 @patch
1067 factory Int64List(int length) native "TypedData_Int64Array_new";
1068
1069 @patch
1070 factory Int64List.fromList(List<int> elements) {
1071 return new Int64List(elements.length)
1072 ..setRange(0, elements.length, elements);
1073 }
1074 }
1075
1076 class _Int64List extends _TypedList with _IntListMixin implements Int64List {
1077 Type get runtimeType => Int64List;
1078
1079 // Method(s) implementing the List interface.
1080 int operator [](int index) {
1081 if (index < 0 || index >= length) {
1082 throw new RangeError.index(index, this, "index");
1083 }
1084 return _getIndexedInt64(index);
1085 }
1086
1087 void operator []=(int index, int value) {
1088 if (index < 0 || index >= length) {
1089 throw new RangeError.index(index, this, "index");
1090 }
1091 _setIndexedInt64(index, _toInt64(value));
1092 }
1093
1094 // Method(s) implementing the TypedData interface.
1095 int get elementSizeInBytes {
1096 return Int64List.BYTES_PER_ELEMENT;
1097 }
1098
1099 // Internal utility methods.
1100 Int64List _createList(int length) {
1101 return new Int64List(length);
1102 }
1103
1104 int _getIndexedInt64(int index) {
1105 return _getInt64(index * Int64List.BYTES_PER_ELEMENT);
1106 }
1107
1108 void _setIndexedInt64(int index, int value) {
1109 _setInt64(index * Int64List.BYTES_PER_ELEMENT, value);
1110 }
1111 }
1112
1113 @patch
1114 class Uint64List {
1115 @patch
1116 factory Uint64List(int length) native "TypedData_Uint64Array_new";
1117
1118 @patch
1119 factory Uint64List.fromList(List<int> elements) {
1120 return new Uint64List(elements.length)
1121 ..setRange(0, elements.length, elements);
1122 }
1123 }
1124
1125 class _Uint64List extends _TypedList with _IntListMixin implements Uint64List {
1126 Type get runtimeType => Uint64List;
1127
1128 // Method(s) implementing the List interface.
1129 int operator [](int index) {
1130 if (index < 0 || index >= length) {
1131 throw new RangeError.index(index, this, "index");
1132 }
1133 return _getIndexedUint64(index);
1134 }
1135
1136 void operator []=(int index, int value) {
1137 if (index < 0 || index >= length) {
1138 throw new RangeError.index(index, this, "index");
1139 }
1140 _setIndexedUint64(index, _toUint64(value));
1141 }
1142
1143 // Method(s) implementing the TypedData interface.
1144 int get elementSizeInBytes {
1145 return Uint64List.BYTES_PER_ELEMENT;
1146 }
1147
1148 // Internal utility methods.
1149 Uint64List _createList(int length) {
1150 return new Uint64List(length);
1151 }
1152
1153 int _getIndexedUint64(int index) {
1154 return _getUint64(index * Uint64List.BYTES_PER_ELEMENT);
1155 }
1156
1157 void _setIndexedUint64(int index, int value) {
1158 _setUint64(index * Uint64List.BYTES_PER_ELEMENT, value);
1159 }
1160 }
1161
1162 @patch
1163 class Float32List {
1164 @patch
1165 factory Float32List(int length) native "TypedData_Float32Array_new";
1166
1167 @patch
1168 factory Float32List.fromList(List<double> elements) {
1169 return new Float32List(elements.length)
1170 ..setRange(0, elements.length, elements);
1171 }
1172 }
1173
1174 class _Float32List extends _TypedList
1175 with _DoubleListMixin
1176 implements Float32List {
1177 Type get runtimeType => Float32List;
1178
1179 // Method(s) implementing the List interface.
1180 double operator [](int index) {
1181 if (index < 0 || index >= length) {
1182 throw new RangeError.index(index, this, "index");
1183 }
1184 return _getIndexedFloat32(index);
1185 }
1186
1187 void operator []=(int index, double value) {
1188 if (index < 0 || index >= length) {
1189 throw new RangeError.index(index, this, "index");
1190 }
1191 _setIndexedFloat32(index, value);
1192 }
1193
1194 // Method(s) implementing the TypedData interface.
1195 int get elementSizeInBytes {
1196 return Float32List.BYTES_PER_ELEMENT;
1197 }
1198
1199 // Internal utility methods.
1200 Float32List _createList(int length) {
1201 return new Float32List(length);
1202 }
1203
1204 double _getIndexedFloat32(int index) {
1205 return _getFloat32(index * Float32List.BYTES_PER_ELEMENT);
1206 }
1207
1208 void _setIndexedFloat32(int index, double value) {
1209 _setFloat32(index * Float32List.BYTES_PER_ELEMENT, value);
1210 }
1211 }
1212
1213 @patch
1214 class Float64List {
1215 @patch
1216 factory Float64List(int length) native "TypedData_Float64Array_new";
1217
1218 @patch
1219 factory Float64List.fromList(List<double> elements) {
1220 return new Float64List(elements.length)
1221 ..setRange(0, elements.length, elements);
1222 }
1223 }
1224
1225 class _Float64List extends _TypedList
1226 with _DoubleListMixin
1227 implements Float64List {
1228 Type get runtimeType => Float64List;
1229
1230 // Method(s) implementing the List interface.
1231 double operator [](int index) {
1232 if (index < 0 || index >= length) {
1233 throw new RangeError.index(index, this, "index");
1234 }
1235 return _getIndexedFloat64(index);
1236 }
1237
1238 void operator []=(int index, double value) {
1239 if (index < 0 || index >= length) {
1240 throw new RangeError.index(index, this, "index");
1241 }
1242 _setIndexedFloat64(index, value);
1243 }
1244
1245 // Method(s) implementing the TypedData interface.
1246 int get elementSizeInBytes {
1247 return Float64List.BYTES_PER_ELEMENT;
1248 }
1249
1250 // Internal utility methods.
1251 Float64List _createList(int length) {
1252 return new Float64List(length);
1253 }
1254
1255 double _getIndexedFloat64(int index) {
1256 return _getFloat64(index * Float64List.BYTES_PER_ELEMENT);
1257 }
1258
1259 void _setIndexedFloat64(int index, double value) {
1260 _setFloat64(index * Float64List.BYTES_PER_ELEMENT, value);
1261 }
1262 }
1263
1264 @patch
1265 class Float32x4List {
1266 @patch
1267 factory Float32x4List(int length) native "TypedData_Float32x4Array_new";
1268
1269 @patch
1270 factory Float32x4List.fromList(List<Float32x4> elements) {
1271 return new Float32x4List(elements.length)
1272 ..setRange(0, elements.length, elements);
1273 }
1274 }
1275
1276 class _Float32x4List extends _TypedList
1277 with _Float32x4ListMixin
1278 implements Float32x4List {
1279 Type get runtimeType => Float32x4List;
1280
1281 Float32x4 operator [](int index) {
1282 if (index < 0 || index >= length) {
1283 throw new RangeError.index(index, this, "index");
1284 }
1285 return _getIndexedFloat32x4(index);
1286 }
1287
1288 void operator []=(int index, Float32x4 value) {
1289 if (index < 0 || index >= length) {
1290 throw new RangeError.index(index, this, "index");
1291 }
1292 _setIndexedFloat32x4(index, value);
1293 }
1294
1295 // Method(s) implementing the TypedData interface.
1296 int get elementSizeInBytes {
1297 return Float32x4List.BYTES_PER_ELEMENT;
1298 }
1299
1300 // Internal utility methods.
1301 Float32x4List _createList(int length) {
1302 return new Float32x4List(length);
1303 }
1304
1305 Float32x4 _getIndexedFloat32x4(int index) {
1306 return _getFloat32x4(index * Float32x4List.BYTES_PER_ELEMENT);
1307 }
1308
1309 void _setIndexedFloat32x4(int index, Float32x4 value) {
1310 _setFloat32x4(index * Float32x4List.BYTES_PER_ELEMENT, value);
1311 }
1312 }
1313
1314 @patch
1315 class Int32x4List {
1316 @patch
1317 factory Int32x4List(int length) native "TypedData_Int32x4Array_new";
1318
1319 @patch
1320 factory Int32x4List.fromList(List<Int32x4> elements) {
1321 return new Int32x4List(elements.length)
1322 ..setRange(0, elements.length, elements);
1323 }
1324 }
1325
1326 class _Int32x4List extends _TypedList
1327 with _Int32x4ListMixin
1328 implements Int32x4List {
1329 Type get runtimeType => Int32x4List;
1330
1331 Int32x4 operator [](int index) {
1332 if (index < 0 || index >= length) {
1333 throw new RangeError.index(index, this, "index");
1334 }
1335 return _getIndexedInt32x4(index);
1336 }
1337
1338 void operator []=(int index, Int32x4 value) {
1339 if (index < 0 || index >= length) {
1340 throw new RangeError.index(index, this, "index");
1341 }
1342 _setIndexedInt32x4(index, value);
1343 }
1344
1345 // Method(s) implementing the TypedData interface.
1346 int get elementSizeInBytes {
1347 return Int32x4List.BYTES_PER_ELEMENT;
1348 }
1349
1350 // Internal utility methods.
1351 Int32x4List _createList(int length) {
1352 return new Int32x4List(length);
1353 }
1354
1355 Int32x4 _getIndexedInt32x4(int index) {
1356 return _getInt32x4(index * Int32x4List.BYTES_PER_ELEMENT);
1357 }
1358
1359 void _setIndexedInt32x4(int index, Int32x4 value) {
1360 _setInt32x4(index * Int32x4List.BYTES_PER_ELEMENT, value);
1361 }
1362 }
1363
1364 @patch
1365 class Float64x2List {
1366 @patch
1367 factory Float64x2List(int length) native "TypedData_Float64x2Array_new";
1368
1369 @patch
1370 factory Float64x2List.fromList(List<Float64x2> elements) {
1371 return new Float64x2List(elements.length)
1372 ..setRange(0, elements.length, elements);
1373 }
1374 }
1375
1376 class _Float64x2List extends _TypedList
1377 with _Float64x2ListMixin
1378 implements Float64x2List {
1379 Type get runtimeType => Float64x2List;
1380
1381 Float64x2 operator [](int index) {
1382 if (index < 0 || index >= length) {
1383 throw new RangeError.index(index, this, "index");
1384 }
1385 return _getIndexedFloat64x2(index);
1386 }
1387
1388 void operator []=(int index, Float64x2 value) {
1389 if (index < 0 || index >= length) {
1390 throw new RangeError.index(index, this, "index");
1391 }
1392 _setIndexedFloat64x2(index, value);
1393 }
1394
1395 // Method(s) implementing the TypedData interface.
1396 int get elementSizeInBytes {
1397 return Float64x2List.BYTES_PER_ELEMENT;
1398 }
1399
1400 // Internal utility methods.
1401 Float64x2List _createList(int length) {
1402 return new Float64x2List(length);
1403 }
1404
1405 Float64x2 _getIndexedFloat64x2(int index) {
1406 return _getFloat64x2(index * Float64x2List.BYTES_PER_ELEMENT);
1407 }
1408
1409 void _setIndexedFloat64x2(int index, Float64x2 value) {
1410 _setFloat64x2(index * Float64x2List.BYTES_PER_ELEMENT, value);
1411 }
1412 }
1413
1414 class _ExternalInt8Array extends _TypedList
1415 with _IntListMixin
1416 implements Int8List {
1417 // Method(s) implementing the List interface.
1418 int operator [](int index) {
1419 if (index < 0 || index >= length) {
1420 throw new RangeError.index(index, this, "index");
1421 }
1422 return _getInt8(index);
1423 }
1424
1425 void operator []=(int index, int value) {
1426 if (index < 0 || index >= length) {
1427 throw new RangeError.index(index, this, "index");
1428 }
1429 _setInt8(index, value);
1430 }
1431
1432 // Method(s) implementing the TypedData interface.
1433 int get elementSizeInBytes {
1434 return Int8List.BYTES_PER_ELEMENT;
1435 }
1436
1437 // Internal utility methods.
1438 Int8List _createList(int length) {
1439 return new Int8List(length);
1440 }
1441 }
1442
1443 class _ExternalUint8Array extends _TypedList
1444 with _IntListMixin
1445 implements Uint8List {
1446 // Method(s) implementing the List interface.
1447 int operator [](int index) {
1448 if (index < 0 || index >= length) {
1449 throw new RangeError.index(index, this, "index");
1450 }
1451 return _getUint8(index);
1452 }
1453
1454 void operator []=(int index, int value) {
1455 if (index < 0 || index >= length) {
1456 throw new RangeError.index(index, this, "index");
1457 }
1458 _setUint8(index, _toUint8(value));
1459 }
1460
1461 // Method(s) implementing the TypedData interface.
1462 int get elementSizeInBytes {
1463 return Uint8List.BYTES_PER_ELEMENT;
1464 }
1465
1466 // Internal utility methods.
1467 Uint8List _createList(int length) {
1468 return new Uint8List(length);
1469 }
1470 }
1471
1472 class _ExternalUint8ClampedArray extends _TypedList
1473 with _IntListMixin
1474 implements Uint8ClampedList {
1475 // Method(s) implementing the List interface.
1476 int operator [](int index) {
1477 if (index < 0 || index >= length) {
1478 throw new RangeError.index(index, this, "index");
1479 }
1480 return _getUint8(index);
1481 }
1482
1483 void operator []=(int index, int value) {
1484 if (index < 0 || index >= length) {
1485 throw new RangeError.index(index, this, "index");
1486 }
1487 _setUint8(index, _toClampedUint8(value));
1488 }
1489
1490 // Method(s) implementing the TypedData interface.
1491 int get elementSizeInBytes {
1492 return Uint8List.BYTES_PER_ELEMENT;
1493 }
1494
1495 // Internal utility methods.
1496 Uint8ClampedList _createList(int length) {
1497 return new Uint8ClampedList(length);
1498 }
1499 }
1500
1501 class _ExternalInt16Array extends _TypedList
1502 with _IntListMixin
1503 implements Int16List {
1504 // Method(s) implementing the List interface.
1505
1506 int operator [](int index) {
1507 if (index < 0 || index >= length) {
1508 throw new RangeError.index(index, this, "index");
1509 }
1510 return _getIndexedInt16(index);
1511 }
1512
1513 void operator []=(int index, int value) {
1514 if (index < 0 || index >= length) {
1515 throw new RangeError.index(index, this, "index");
1516 }
1517 _setIndexedInt16(index, _toInt16(value));
1518 }
1519
1520 // Method(s) implementing the TypedData interface.
1521 int get elementSizeInBytes {
1522 return Int16List.BYTES_PER_ELEMENT;
1523 }
1524
1525 // Internal utility methods.
1526 Int16List _createList(int length) {
1527 return new Int16List(length);
1528 }
1529
1530 int _getIndexedInt16(int index) {
1531 return _getInt16(index * Int16List.BYTES_PER_ELEMENT);
1532 }
1533
1534 void _setIndexedInt16(int index, int value) {
1535 _setInt16(index * Int16List.BYTES_PER_ELEMENT, value);
1536 }
1537 }
1538
1539 class _ExternalUint16Array extends _TypedList
1540 with _IntListMixin
1541 implements Uint16List {
1542 // Method(s) implementing the List interface.
1543
1544 int operator [](int index) {
1545 if (index < 0 || index >= length) {
1546 throw new RangeError.index(index, this, "index");
1547 }
1548 return _getIndexedUint16(index);
1549 }
1550
1551 void operator []=(int index, int value) {
1552 if (index < 0 || index >= length) {
1553 throw new RangeError.index(index, this, "index");
1554 }
1555 _setIndexedUint16(index, _toUint16(value));
1556 }
1557
1558 // Method(s) implementing the TypedData interface.
1559 int get elementSizeInBytes {
1560 return Uint16List.BYTES_PER_ELEMENT;
1561 }
1562
1563 // Internal utility methods.
1564 Uint16List _createList(int length) {
1565 return new Uint16List(length);
1566 }
1567
1568 int _getIndexedUint16(int index) {
1569 return _getUint16(index * Uint16List.BYTES_PER_ELEMENT);
1570 }
1571
1572 void _setIndexedUint16(int index, int value) {
1573 _setUint16(index * Uint16List.BYTES_PER_ELEMENT, value);
1574 }
1575 }
1576
1577 class _ExternalInt32Array extends _TypedList
1578 with _IntListMixin
1579 implements Int32List {
1580 // Method(s) implementing the List interface.
1581 int operator [](int index) {
1582 if (index < 0 || index >= length) {
1583 throw new RangeError.index(index, this, "index");
1584 }
1585 return _getIndexedInt32(index);
1586 }
1587
1588 void operator []=(int index, int value) {
1589 if (index < 0 || index >= length) {
1590 throw new RangeError.index(index, this, "index");
1591 }
1592 _setIndexedInt32(index, _toInt32(value));
1593 }
1594
1595 // Method(s) implementing the TypedData interface.
1596 int get elementSizeInBytes {
1597 return Int32List.BYTES_PER_ELEMENT;
1598 }
1599
1600 // Internal utility methods.
1601 Int32List _createList(int length) {
1602 return new Int32List(length);
1603 }
1604
1605 int _getIndexedInt32(int index) {
1606 return _getInt32(index * Int32List.BYTES_PER_ELEMENT);
1607 }
1608
1609 void _setIndexedInt32(int index, int value) {
1610 _setInt32(index * Int32List.BYTES_PER_ELEMENT, value);
1611 }
1612 }
1613
1614 class _ExternalUint32Array extends _TypedList
1615 with _IntListMixin
1616 implements Uint32List {
1617 // Method(s) implementing the List interface.
1618
1619 int operator [](int index) {
1620 if (index < 0 || index >= length) {
1621 throw new RangeError.index(index, this, "index");
1622 }
1623 return _getIndexedUint32(index);
1624 }
1625
1626 void operator []=(int index, int value) {
1627 if (index < 0 || index >= length) {
1628 throw new RangeError.index(index, this, "index");
1629 }
1630 _setIndexedUint32(index, _toUint32(value));
1631 }
1632
1633 // Method(s) implementing the TypedData interface.
1634 int get elementSizeInBytes {
1635 return Uint32List.BYTES_PER_ELEMENT;
1636 }
1637
1638 // Internal utility methods.
1639 Uint32List _createList(int length) {
1640 return new Uint32List(length);
1641 }
1642
1643 int _getIndexedUint32(int index) {
1644 return _getUint32(index * Uint32List.BYTES_PER_ELEMENT);
1645 }
1646
1647 void _setIndexedUint32(int index, int value) {
1648 _setUint32(index * Uint32List.BYTES_PER_ELEMENT, value);
1649 }
1650 }
1651
1652 class _ExternalInt64Array extends _TypedList
1653 with _IntListMixin
1654 implements Int64List {
1655 // Method(s) implementing the List interface.
1656
1657 int operator [](int index) {
1658 if (index < 0 || index >= length) {
1659 throw new RangeError.index(index, this, "index");
1660 }
1661 return _getIndexedInt64(index);
1662 }
1663
1664 void operator []=(int index, int value) {
1665 if (index < 0 || index >= length) {
1666 throw new RangeError.index(index, this, "index");
1667 }
1668 _setIndexedInt64(index, _toInt64(value));
1669 }
1670
1671 // Method(s) implementing the TypedData interface.
1672 int get elementSizeInBytes {
1673 return Int64List.BYTES_PER_ELEMENT;
1674 }
1675
1676 // Internal utility methods.
1677 Int64List _createList(int length) {
1678 return new Int64List(length);
1679 }
1680
1681 int _getIndexedInt64(int index) {
1682 return _getInt64(index * Int64List.BYTES_PER_ELEMENT);
1683 }
1684
1685 void _setIndexedInt64(int index, int value) {
1686 _setInt64(index * Int64List.BYTES_PER_ELEMENT, value);
1687 }
1688 }
1689
1690 class _ExternalUint64Array extends _TypedList
1691 with _IntListMixin
1692 implements Uint64List {
1693 // Method(s) implementing the List interface.
1694
1695 int operator [](int index) {
1696 if (index < 0 || index >= length) {
1697 throw new RangeError.index(index, this, "index");
1698 }
1699 return _getIndexedUint64(index);
1700 }
1701
1702 void operator []=(int index, int value) {
1703 if (index < 0 || index >= length) {
1704 throw new RangeError.index(index, this, "index");
1705 }
1706 _setIndexedUint64(index, _toUint64(value));
1707 }
1708
1709 // Method(s) implementing the TypedData interface.
1710 int get elementSizeInBytes {
1711 return Uint64List.BYTES_PER_ELEMENT;
1712 }
1713
1714 // Internal utility methods.
1715 Uint64List _createList(int length) {
1716 return new Uint64List(length);
1717 }
1718
1719 int _getIndexedUint64(int index) {
1720 return _getUint64(index * Uint64List.BYTES_PER_ELEMENT);
1721 }
1722
1723 void _setIndexedUint64(int index, int value) {
1724 _setUint64(index * Uint64List.BYTES_PER_ELEMENT, value);
1725 }
1726 }
1727
1728 class _ExternalFloat32Array extends _TypedList
1729 with _DoubleListMixin
1730 implements Float32List {
1731 // Method(s) implementing the List interface.
1732
1733 double operator [](int index) {
1734 if (index < 0 || index >= length) {
1735 throw new RangeError.index(index, this, "index");
1736 }
1737 return _getIndexedFloat32(index);
1738 }
1739
1740 void operator []=(int index, double value) {
1741 if (index < 0 || index >= length) {
1742 throw new RangeError.index(index, this, "index");
1743 }
1744 _setIndexedFloat32(index, value);
1745 }
1746
1747 // Method(s) implementing the TypedData interface.
1748 int get elementSizeInBytes {
1749 return Float32List.BYTES_PER_ELEMENT;
1750 }
1751
1752 // Internal utility methods.
1753 Float32List _createList(int length) {
1754 return new Float32List(length);
1755 }
1756
1757 double _getIndexedFloat32(int index) {
1758 return _getFloat32(index * Float32List.BYTES_PER_ELEMENT);
1759 }
1760
1761 void _setIndexedFloat32(int index, double value) {
1762 _setFloat32(index * Float32List.BYTES_PER_ELEMENT, value);
1763 }
1764 }
1765
1766 class _ExternalFloat64Array extends _TypedList
1767 with _DoubleListMixin
1768 implements Float64List {
1769 // Method(s) implementing the List interface.
1770
1771 double operator [](int index) {
1772 if (index < 0 || index >= length) {
1773 throw new RangeError.index(index, this, "index");
1774 }
1775 return _getIndexedFloat64(index);
1776 }
1777
1778 void operator []=(int index, double value) {
1779 if (index < 0 || index >= length) {
1780 throw new RangeError.index(index, this, "index");
1781 }
1782 _setIndexedFloat64(index, value);
1783 }
1784
1785 // Method(s) implementing the TypedData interface.
1786 int get elementSizeInBytes {
1787 return Float64List.BYTES_PER_ELEMENT;
1788 }
1789
1790 // Internal utility methods.
1791 Float64List _createList(int length) {
1792 return new Float64List(length);
1793 }
1794
1795 double _getIndexedFloat64(int index) {
1796 return _getFloat64(index * Float64List.BYTES_PER_ELEMENT);
1797 }
1798
1799 void _setIndexedFloat64(int index, double value) {
1800 _setFloat64(index * Float64List.BYTES_PER_ELEMENT, value);
1801 }
1802 }
1803
1804 class _ExternalFloat32x4Array extends _TypedList
1805 with _Float32x4ListMixin
1806 implements Float32x4List {
1807 // Method(s) implementing the List interface.
1808
1809 Float32x4 operator [](int index) {
1810 if (index < 0 || index >= length) {
1811 throw new RangeError.index(index, this, "index");
1812 }
1813 return _getIndexedFloat32x4(index);
1814 }
1815
1816 void operator []=(int index, Float32x4 value) {
1817 if (index < 0 || index >= length) {
1818 throw new RangeError.index(index, this, "index");
1819 }
1820 _setIndexedFloat32x4(index, value);
1821 }
1822
1823 // Method(s) implementing the TypedData interface.
1824 int get elementSizeInBytes {
1825 return Float32x4List.BYTES_PER_ELEMENT;
1826 }
1827
1828 // Internal utility methods.
1829 Float32x4List _createList(int length) {
1830 return new Float32x4List(length);
1831 }
1832
1833 Float32x4 _getIndexedFloat32x4(int index) {
1834 return _getFloat32x4(index * Float32x4List.BYTES_PER_ELEMENT);
1835 }
1836
1837 void _setIndexedFloat32x4(int index, Float32x4 value) {
1838 _setFloat32x4(index * Float32x4List.BYTES_PER_ELEMENT, value);
1839 }
1840 }
1841
1842 class _ExternalInt32x4Array extends _TypedList
1843 with _Int32x4ListMixin
1844 implements Int32x4List {
1845 // Method(s) implementing the List interface.
1846
1847 Int32x4 operator [](int index) {
1848 if (index < 0 || index >= length) {
1849 throw new RangeError.index(index, this, "index");
1850 }
1851 return _getIndexedInt32x4(index);
1852 }
1853
1854 void operator []=(int index, Int32x4 value) {
1855 if (index < 0 || index >= length) {
1856 throw new RangeError.index(index, this, "index");
1857 }
1858 _setIndexedInt32x4(index, value);
1859 }
1860
1861 // Method(s) implementing the TypedData interface.
1862 int get elementSizeInBytes {
1863 return Int32x4List.BYTES_PER_ELEMENT;
1864 }
1865
1866 // Internal utility methods.
1867 Int32x4List _createList(int length) {
1868 return new Int32x4List(length);
1869 }
1870
1871 Int32x4 _getIndexedInt32x4(int index) {
1872 return _getInt32x4(index * Int32x4List.BYTES_PER_ELEMENT);
1873 }
1874
1875 void _setIndexedInt32x4(int index, Int32x4 value) {
1876 _setInt32x4(index * Int32x4List.BYTES_PER_ELEMENT, value);
1877 }
1878 }
1879
1880 class _ExternalFloat64x2Array extends _TypedList
1881 with _Float64x2ListMixin
1882 implements Float64x2List {
1883 // Method(s) implementing the List interface.
1884 Float64x2 operator [](int index) {
1885 if (index < 0 || index >= length) {
1886 throw new RangeError.index(index, this, "index");
1887 }
1888 return _getIndexedFloat64x2(index);
1889 }
1890
1891 void operator []=(int index, Float64x2 value) {
1892 if (index < 0 || index >= length) {
1893 throw new RangeError.index(index, this, "index");
1894 }
1895 _setIndexedFloat64x2(index, value);
1896 }
1897
1898 // Method(s) implementing the TypedData interface.
1899 int get elementSizeInBytes {
1900 return Float64x2List.BYTES_PER_ELEMENT;
1901 }
1902
1903 // Internal utility methods.
1904 Float64x2List _createList(int length) {
1905 return new Float64x2List(length);
1906 }
1907
1908 Float64x2 _getIndexedFloat64x2(int index) {
1909 return _getFloat64x2(index * Float64x2List.BYTES_PER_ELEMENT);
1910 }
1911
1912 void _setIndexedFloat64x2(int index, Float64x2 value) {
1913 _setFloat64x2(index * Float64x2List.BYTES_PER_ELEMENT, value);
1914 }
1915 }
1916
1917 @patch
1918 class Float32x4 {
1919 @patch
1920 factory Float32x4(double x, double y, double z, double w)
1921 native "Float32x4_fromDoubles";
1922
1923 @patch
1924 factory Float32x4.splat(double v) native "Float32x4_splat";
1925
1926 @patch
1927 factory Float32x4.zero() native "Float32x4_zero";
1928
1929 @patch
1930 factory Float32x4.fromInt32x4Bits(Int32x4 x)
1931 native "Float32x4_fromInt32x4Bits";
1932
1933 @patch
1934 factory Float32x4.fromFloat64x2(Float64x2 v) native "Float32x4_fromFloat64x2";
1935 }
1936
1937 class _Float32x4 implements Float32x4 {
1938 Float32x4 operator +(Float32x4 other) native "Float32x4_add";
1939 Float32x4 operator -() native "Float32x4_negate";
1940 Float32x4 operator -(Float32x4 other) native "Float32x4_sub";
1941 Float32x4 operator *(Float32x4 other) native "Float32x4_mul";
1942 Float32x4 operator /(Float32x4 other) native "Float32x4_div";
1943 Int32x4 lessThan(Float32x4 other) native "Float32x4_cmplt";
1944 Int32x4 lessThanOrEqual(Float32x4 other) native "Float32x4_cmplte";
1945 Int32x4 greaterThan(Float32x4 other) native "Float32x4_cmpgt";
1946 Int32x4 greaterThanOrEqual(Float32x4 other) native "Float32x4_cmpgte";
1947 Int32x4 equal(Float32x4 other) native "Float32x4_cmpequal";
1948 Int32x4 notEqual(Float32x4 other) native "Float32x4_cmpnequal";
1949 Float32x4 scale(double s) native "Float32x4_scale";
1950 Float32x4 abs() native "Float32x4_abs";
1951 Float32x4 clamp(Float32x4 lowerLimit, Float32x4 upperLimit)
1952 native "Float32x4_clamp";
1953 double get x native "Float32x4_getX";
1954 double get y native "Float32x4_getY";
1955 double get z native "Float32x4_getZ";
1956 double get w native "Float32x4_getW";
1957 int get signMask native "Float32x4_getSignMask";
1958
1959 Float32x4 shuffle(int mask) native "Float32x4_shuffle";
1960 Float32x4 shuffleMix(Float32x4 zw, int mask) native "Float32x4_shuffleMix";
1961
1962 Float32x4 withX(double x) native "Float32x4_setX";
1963 Float32x4 withY(double y) native "Float32x4_setY";
1964 Float32x4 withZ(double z) native "Float32x4_setZ";
1965 Float32x4 withW(double w) native "Float32x4_setW";
1966 Float32x4 min(Float32x4 other) native "Float32x4_min";
1967 Float32x4 max(Float32x4 other) native "Float32x4_max";
1968 Float32x4 sqrt() native "Float32x4_sqrt";
1969 Float32x4 reciprocal() native "Float32x4_reciprocal";
1970 Float32x4 reciprocalSqrt() native "Float32x4_reciprocalSqrt";
1971 }
1972
1973 @patch
1974 class Int32x4 {
1975 @patch
1976 factory Int32x4(int x, int y, int z, int w) native "Int32x4_fromInts";
1977
1978 @patch
1979 factory Int32x4.bool(bool x, bool y, bool z, bool w)
1980 native "Int32x4_fromBools";
1981
1982 @patch
1983 factory Int32x4.fromFloat32x4Bits(Float32x4 x)
1984 native "Int32x4_fromFloat32x4Bits";
1985 }
1986
1987 class _Int32x4 implements Int32x4 {
1988 Int32x4 operator |(Int32x4 other) native "Int32x4_or";
1989 Int32x4 operator &(Int32x4 other) native "Int32x4_and";
1990 Int32x4 operator ^(Int32x4 other) native "Int32x4_xor";
1991 Int32x4 operator +(Int32x4 other) native "Int32x4_add";
1992 Int32x4 operator -(Int32x4 other) native "Int32x4_sub";
1993 int get x native "Int32x4_getX";
1994 int get y native "Int32x4_getY";
1995 int get z native "Int32x4_getZ";
1996 int get w native "Int32x4_getW";
1997 int get signMask native "Int32x4_getSignMask";
1998 Int32x4 shuffle(int mask) native "Int32x4_shuffle";
1999 Int32x4 shuffleMix(Int32x4 zw, int mask) native "Int32x4_shuffleMix";
2000 Int32x4 withX(int x) native "Int32x4_setX";
2001 Int32x4 withY(int y) native "Int32x4_setY";
2002 Int32x4 withZ(int z) native "Int32x4_setZ";
2003 Int32x4 withW(int w) native "Int32x4_setW";
2004 bool get flagX native "Int32x4_getFlagX";
2005 bool get flagY native "Int32x4_getFlagY";
2006 bool get flagZ native "Int32x4_getFlagZ";
2007 bool get flagW native "Int32x4_getFlagW";
2008 Int32x4 withFlagX(bool x) native "Int32x4_setFlagX";
2009 Int32x4 withFlagY(bool y) native "Int32x4_setFlagY";
2010 Int32x4 withFlagZ(bool z) native "Int32x4_setFlagZ";
2011 Int32x4 withFlagW(bool w) native "Int32x4_setFlagW";
2012 Float32x4 select(Float32x4 trueValue, Float32x4 falseValue)
2013 native "Int32x4_select";
2014 }
2015
2016 @patch
2017 class Float64x2 {
2018 @patch
2019 factory Float64x2(double x, double y) native "Float64x2_fromDoubles";
2020
2021 @patch
2022 factory Float64x2.splat(double v) native "Float64x2_splat";
2023
2024 @patch
2025 factory Float64x2.zero() native "Float64x2_zero";
2026
2027 @patch
2028 factory Float64x2.fromFloat32x4(Float32x4 v) native "Float64x2_fromFloat32x4";
2029 }
2030
2031 class _Float64x2 implements Float64x2 {
2032 Float64x2 operator +(Float64x2 other) native "Float64x2_add";
2033 Float64x2 operator -() native "Float64x2_negate";
2034 Float64x2 operator -(Float64x2 other) native "Float64x2_sub";
2035 Float64x2 operator *(Float64x2 other) native "Float64x2_mul";
2036 Float64x2 operator /(Float64x2 other) native "Float64x2_div";
2037 Float64x2 scale(double s) native "Float64x2_scale";
2038 Float64x2 abs() native "Float64x2_abs";
2039 Float64x2 clamp(Float64x2 lowerLimit, Float64x2 upperLimit)
2040 native "Float64x2_clamp";
2041 double get x native "Float64x2_getX";
2042 double get y native "Float64x2_getY";
2043 int get signMask native "Float64x2_getSignMask";
2044 Float64x2 withX(double x) native "Float64x2_setX";
2045 Float64x2 withY(double y) native "Float64x2_setY";
2046 Float64x2 min(Float64x2 other) native "Float64x2_min";
2047 Float64x2 max(Float64x2 other) native "Float64x2_max";
2048 Float64x2 sqrt() native "Float64x2_sqrt";
2049 }
2050
2051 class _TypedListIterator<E> implements Iterator<E> {
2052 final List<E> _array;
2053 final int _length;
2054 int _position;
2055 E _current;
2056
2057 _TypedListIterator(List array)
2058 : _array = array,
2059 _length = array.length,
2060 _position = -1 {
2061 assert(array is _TypedList || array is _TypedListView);
2062 }
2063
2064 bool moveNext() {
2065 int nextPosition = _position + 1;
2066 if (nextPosition < _length) {
2067 _current = _array[nextPosition];
2068 _position = nextPosition;
2069 return true;
2070 }
2071 _position = _length;
2072 _current = null;
2073 return false;
2074 }
2075
2076 E get current => _current;
2077 }
2078
2079 class _TypedListView extends _TypedListBase implements TypedData {
2080 _TypedListView(_ByteBuffer _buffer, int _offset, int _length)
2081 : _typedData = _buffer._data,
2082 offsetInBytes = _offset,
2083 length = _length {}
2084
2085 // Method(s) implementing the TypedData interface.
2086
2087 int get lengthInBytes {
2088 return length * elementSizeInBytes;
2089 }
2090
2091 _ByteBuffer get buffer {
2092 return _typedData.buffer;
2093 }
2094
2095 final _TypedList _typedData;
2096 final int offsetInBytes;
2097 final int length;
2098 }
2099
2100 class _Int8ArrayView extends _TypedListView
2101 with _IntListMixin
2102 implements Int8List {
2103 // Constructor.
2104 _Int8ArrayView(_ByteBuffer buffer, [int _offsetInBytes = 0, int _length])
2105 : super(
2106 buffer,
2107 _offsetInBytes,
2108 _defaultIfNull(
2109 _length,
2110 ((buffer.lengthInBytes - _offsetInBytes) ~/
2111 Int8List.BYTES_PER_ELEMENT))) {
2112 _rangeCheck(buffer.lengthInBytes, _offsetInBytes,
2113 length * Int8List.BYTES_PER_ELEMENT);
2114 }
2115
2116 // Method(s) implementing List interface.
2117 int operator [](int index) {
2118 if (index < 0 || index >= length) {
2119 throw new RangeError.index(index, this, "index");
2120 }
2121 return _typedData
2122 ._getInt8(offsetInBytes + (index * Int8List.BYTES_PER_ELEMENT));
2123 }
2124
2125 void operator []=(int index, int value) {
2126 if (index < 0 || index >= length) {
2127 throw new RangeError.index(index, this, "index");
2128 }
2129 _typedData._setInt8(
2130 offsetInBytes + (index * Int8List.BYTES_PER_ELEMENT), _toInt8(value));
2131 }
2132
2133 // Method(s) implementing TypedData interface.
2134 int get elementSizeInBytes {
2135 return Int8List.BYTES_PER_ELEMENT;
2136 }
2137
2138 // Internal utility methods.
2139 Int8List _createList(int length) {
2140 return new Int8List(length);
2141 }
2142 }
2143
2144 class _Uint8ArrayView extends _TypedListView
2145 with _IntListMixin
2146 implements Uint8List {
2147 // Constructor.
2148 _Uint8ArrayView(_ByteBuffer buffer, [int _offsetInBytes = 0, int _length])
2149 : super(
2150 buffer,
2151 _offsetInBytes,
2152 _defaultIfNull(
2153 _length,
2154 ((buffer.lengthInBytes - _offsetInBytes) ~/
2155 Uint8List.BYTES_PER_ELEMENT))) {
2156 _rangeCheck(buffer.lengthInBytes, _offsetInBytes,
2157 length * Uint8List.BYTES_PER_ELEMENT);
2158 }
2159
2160 // Method(s) implementing List interface.
2161 int operator [](int index) {
2162 if (index < 0 || index >= length) {
2163 throw new RangeError.index(index, this, "index");
2164 }
2165 return _typedData
2166 ._getUint8(offsetInBytes + (index * Uint8List.BYTES_PER_ELEMENT));
2167 }
2168
2169 void operator []=(int index, int value) {
2170 if (index < 0 || index >= length) {
2171 throw new RangeError.index(index, this, "index");
2172 }
2173 _typedData._setUint8(
2174 offsetInBytes + (index * Uint8List.BYTES_PER_ELEMENT), _toUint8(value));
2175 }
2176
2177 // Method(s) implementing TypedData interface.
2178 int get elementSizeInBytes {
2179 return Uint8List.BYTES_PER_ELEMENT;
2180 }
2181
2182 // Internal utility methods.
2183 Uint8List _createList(int length) {
2184 return new Uint8List(length);
2185 }
2186 }
2187
2188 class _Uint8ClampedArrayView extends _TypedListView
2189 with _IntListMixin
2190 implements Uint8ClampedList {
2191 // Constructor.
2192 _Uint8ClampedArrayView(_ByteBuffer buffer,
2193 [int _offsetInBytes = 0, int _length])
2194 : super(
2195 buffer,
2196 _offsetInBytes,
2197 _defaultIfNull(
2198 _length,
2199 ((buffer.lengthInBytes - _offsetInBytes) ~/
2200 Uint8List.BYTES_PER_ELEMENT))) {
2201 _rangeCheck(buffer.lengthInBytes, offsetInBytes,
2202 length * Uint8List.BYTES_PER_ELEMENT);
2203 }
2204
2205 // Method(s) implementing List interface.
2206 int operator [](int index) {
2207 if (index < 0 || index >= length) {
2208 throw new RangeError.index(index, this, "index");
2209 }
2210 return _typedData
2211 ._getUint8(offsetInBytes + (index * Uint8List.BYTES_PER_ELEMENT));
2212 }
2213
2214 void operator []=(int index, int value) {
2215 if (index < 0 || index >= length) {
2216 throw new RangeError.index(index, this, "index");
2217 }
2218 _typedData._setUint8(offsetInBytes + (index * Uint8List.BYTES_PER_ELEMENT),
2219 _toClampedUint8(value));
2220 }
2221
2222 // Method(s) implementing TypedData interface.
2223 int get elementSizeInBytes {
2224 return Uint8List.BYTES_PER_ELEMENT;
2225 }
2226
2227 // Internal utility methods.
2228 Uint8ClampedList _createList(int length) {
2229 return new Uint8ClampedList(length);
2230 }
2231 }
2232
2233 class _Int16ArrayView extends _TypedListView
2234 with _IntListMixin
2235 implements Int16List {
2236 // Constructor.
2237 _Int16ArrayView(_ByteBuffer buffer, [int _offsetInBytes = 0, int _length])
2238 : super(
2239 buffer,
2240 _offsetInBytes,
2241 _defaultIfNull(
2242 _length,
2243 ((buffer.lengthInBytes - _offsetInBytes) ~/
2244 Int16List.BYTES_PER_ELEMENT))) {
2245 _rangeCheck(buffer.lengthInBytes, offsetInBytes,
2246 length * Int16List.BYTES_PER_ELEMENT);
2247 _offsetAlignmentCheck(_offsetInBytes, Int16List.BYTES_PER_ELEMENT);
2248 }
2249
2250 // Method(s) implementing List interface.
2251 int operator [](int index) {
2252 if (index < 0 || index >= length) {
2253 throw new RangeError.index(index, this, "index");
2254 }
2255 return _typedData
2256 ._getInt16(offsetInBytes + (index * Int16List.BYTES_PER_ELEMENT));
2257 }
2258
2259 void operator []=(int index, int value) {
2260 if (index < 0 || index >= length) {
2261 throw new RangeError.index(index, this, "index");
2262 }
2263 _typedData._setInt16(
2264 offsetInBytes + (index * Int16List.BYTES_PER_ELEMENT), _toInt16(value));
2265 }
2266
2267 void setRange(int start, int end, Iterable iterable, [int skipCount = 0]) {
2268 if (iterable is CodeUnits) {
2269 end = RangeError.checkValidRange(start, end, this.length);
2270 int length = end - start;
2271 int byteStart = this.offsetInBytes + start * Int16List.BYTES_PER_ELEMENT;
2272 _typedData._setCodeUnits(iterable, byteStart, length, skipCount);
2273 } else {
2274 super.setRange(start, end, iterable, skipCount);
2275 }
2276 }
2277
2278 // Method(s) implementing TypedData interface.
2279
2280 int get elementSizeInBytes {
2281 return Int16List.BYTES_PER_ELEMENT;
2282 }
2283
2284 // Internal utility methods.
2285 Int16List _createList(int length) {
2286 return new Int16List(length);
2287 }
2288 }
2289
2290 class _Uint16ArrayView extends _TypedListView
2291 with _IntListMixin
2292 implements Uint16List {
2293 // Constructor.
2294 _Uint16ArrayView(_ByteBuffer buffer, [int _offsetInBytes = 0, int _length])
2295 : super(
2296 buffer,
2297 _offsetInBytes,
2298 _defaultIfNull(
2299 _length,
2300 ((buffer.lengthInBytes - _offsetInBytes) ~/
2301 Uint16List.BYTES_PER_ELEMENT))) {
2302 _rangeCheck(buffer.lengthInBytes, offsetInBytes,
2303 length * Uint16List.BYTES_PER_ELEMENT);
2304 _offsetAlignmentCheck(_offsetInBytes, Uint16List.BYTES_PER_ELEMENT);
2305 }
2306
2307 // Method(s) implementing List interface.
2308 int operator [](int index) {
2309 if (index < 0 || index >= length) {
2310 throw new RangeError.index(index, this, "index");
2311 }
2312 return _typedData
2313 ._getUint16(offsetInBytes + (index * Uint16List.BYTES_PER_ELEMENT));
2314 }
2315
2316 void operator []=(int index, int value) {
2317 if (index < 0 || index >= length) {
2318 throw new RangeError.index(index, this, "index");
2319 }
2320 _typedData._setUint16(
2321 offsetInBytes + (index * Uint16List.BYTES_PER_ELEMENT),
2322 _toUint16(value));
2323 }
2324
2325 void setRange(int start, int end, Iterable iterable, [int skipCount = 0]) {
2326 if (iterable is CodeUnits) {
2327 end = RangeError.checkValidRange(start, end, this.length);
2328 int length = end - start;
2329 int byteStart = this.offsetInBytes + start * Uint16List.BYTES_PER_ELEMENT;
2330 _typedData._setCodeUnits(iterable, byteStart, length, skipCount);
2331 } else {
2332 super.setRange(start, end, iterable, skipCount);
2333 }
2334 }
2335
2336 // Method(s) implementing TypedData interface.
2337
2338 int get elementSizeInBytes {
2339 return Uint16List.BYTES_PER_ELEMENT;
2340 }
2341
2342 // Internal utility methods.
2343
2344 Uint16List _createList(int length) {
2345 return new Uint16List(length);
2346 }
2347 }
2348
2349 class _Int32ArrayView extends _TypedListView
2350 with _IntListMixin
2351 implements Int32List {
2352 // Constructor.
2353 _Int32ArrayView(_ByteBuffer buffer, [int _offsetInBytes = 0, int _length])
2354 : super(
2355 buffer,
2356 _offsetInBytes,
2357 _defaultIfNull(
2358 _length,
2359 ((buffer.lengthInBytes - _offsetInBytes) ~/
2360 Int32List.BYTES_PER_ELEMENT))) {
2361 _rangeCheck(buffer.lengthInBytes, offsetInBytes,
2362 length * Int32List.BYTES_PER_ELEMENT);
2363 _offsetAlignmentCheck(_offsetInBytes, Int32List.BYTES_PER_ELEMENT);
2364 }
2365
2366 // Method(s) implementing List interface.
2367 int operator [](int index) {
2368 if (index < 0 || index >= length) {
2369 throw new RangeError.index(index, this, "index");
2370 }
2371 return _typedData
2372 ._getInt32(offsetInBytes + (index * Int32List.BYTES_PER_ELEMENT));
2373 }
2374
2375 void operator []=(int index, int value) {
2376 if (index < 0 || index >= length) {
2377 throw new RangeError.index(index, this, "index");
2378 }
2379 _typedData._setInt32(
2380 offsetInBytes + (index * Int32List.BYTES_PER_ELEMENT), _toInt32(value));
2381 }
2382
2383 // Method(s) implementing TypedData interface.
2384 int get elementSizeInBytes {
2385 return Int32List.BYTES_PER_ELEMENT;
2386 }
2387
2388 // Internal utility methods.
2389 Int32List _createList(int length) {
2390 return new Int32List(length);
2391 }
2392 }
2393
2394 class _Uint32ArrayView extends _TypedListView
2395 with _IntListMixin
2396 implements Uint32List {
2397 // Constructor.
2398 _Uint32ArrayView(_ByteBuffer buffer, [int _offsetInBytes = 0, int _length])
2399 : super(
2400 buffer,
2401 _offsetInBytes,
2402 _defaultIfNull(
2403 _length,
2404 ((buffer.lengthInBytes - _offsetInBytes) ~/
2405 Uint32List.BYTES_PER_ELEMENT))) {
2406 _rangeCheck(buffer.lengthInBytes, offsetInBytes,
2407 length * Uint32List.BYTES_PER_ELEMENT);
2408 _offsetAlignmentCheck(_offsetInBytes, Uint32List.BYTES_PER_ELEMENT);
2409 }
2410
2411 // Method(s) implementing List interface.
2412 int operator [](int index) {
2413 if (index < 0 || index >= length) {
2414 throw new RangeError.index(index, this, "index");
2415 }
2416 return _typedData
2417 ._getUint32(offsetInBytes + (index * Uint32List.BYTES_PER_ELEMENT));
2418 }
2419
2420 void operator []=(int index, int value) {
2421 if (index < 0 || index >= length) {
2422 throw new RangeError.index(index, this, "index");
2423 }
2424 _typedData._setUint32(
2425 offsetInBytes + (index * Uint32List.BYTES_PER_ELEMENT),
2426 _toUint32(value));
2427 }
2428
2429 // Method(s) implementing TypedData interface.
2430 int get elementSizeInBytes {
2431 return Uint32List.BYTES_PER_ELEMENT;
2432 }
2433
2434 // Internal utility methods.
2435 Uint32List _createList(int length) {
2436 return new Uint32List(length);
2437 }
2438 }
2439
2440 class _Int64ArrayView extends _TypedListView
2441 with _IntListMixin
2442 implements Int64List {
2443 // Constructor.
2444 _Int64ArrayView(_ByteBuffer buffer, [int _offsetInBytes = 0, int _length])
2445 : super(
2446 buffer,
2447 _offsetInBytes,
2448 _defaultIfNull(
2449 _length,
2450 ((buffer.lengthInBytes - _offsetInBytes) ~/
2451 Int64List.BYTES_PER_ELEMENT))) {
2452 _rangeCheck(buffer.lengthInBytes, offsetInBytes,
2453 length * Int64List.BYTES_PER_ELEMENT);
2454 _offsetAlignmentCheck(_offsetInBytes, Int64List.BYTES_PER_ELEMENT);
2455 }
2456
2457 // Method(s) implementing List interface.
2458 int operator [](int index) {
2459 if (index < 0 || index >= length) {
2460 throw new RangeError.index(index, this, "index");
2461 }
2462 return _typedData
2463 ._getInt64(offsetInBytes + (index * Int64List.BYTES_PER_ELEMENT));
2464 }
2465
2466 void operator []=(int index, int value) {
2467 if (index < 0 || index >= length) {
2468 throw new RangeError.index(index, this, "index");
2469 }
2470 _typedData._setInt64(
2471 offsetInBytes + (index * Int64List.BYTES_PER_ELEMENT), _toInt64(value));
2472 }
2473
2474 // Method(s) implementing TypedData interface.
2475 int get elementSizeInBytes {
2476 return Int64List.BYTES_PER_ELEMENT;
2477 }
2478
2479 // Internal utility methods.
2480 Int64List _createList(int length) {
2481 return new Int64List(length);
2482 }
2483 }
2484
2485 class _Uint64ArrayView extends _TypedListView
2486 with _IntListMixin
2487 implements Uint64List {
2488 // Constructor.
2489 _Uint64ArrayView(_ByteBuffer buffer, [int _offsetInBytes = 0, int _length])
2490 : super(
2491 buffer,
2492 _offsetInBytes,
2493 _defaultIfNull(
2494 _length,
2495 ((buffer.lengthInBytes - _offsetInBytes) ~/
2496 Uint64List.BYTES_PER_ELEMENT))) {
2497 _rangeCheck(buffer.lengthInBytes, offsetInBytes,
2498 length * Uint64List.BYTES_PER_ELEMENT);
2499 _offsetAlignmentCheck(_offsetInBytes, Uint64List.BYTES_PER_ELEMENT);
2500 }
2501
2502 // Method(s) implementing List interface.
2503 int operator [](int index) {
2504 if (index < 0 || index >= length) {
2505 throw new RangeError.index(index, this, "index");
2506 }
2507 return _typedData
2508 ._getUint64(offsetInBytes + (index * Uint64List.BYTES_PER_ELEMENT));
2509 }
2510
2511 void operator []=(int index, int value) {
2512 if (index < 0 || index >= length) {
2513 throw new RangeError.index(index, this, "index");
2514 }
2515 _typedData._setUint64(
2516 offsetInBytes + (index * Uint64List.BYTES_PER_ELEMENT),
2517 _toUint64(value));
2518 }
2519
2520 // Method(s) implementing TypedData interface.
2521 int get elementSizeInBytes {
2522 return Uint64List.BYTES_PER_ELEMENT;
2523 }
2524
2525 // Internal utility methods.
2526 Uint64List _createList(int length) {
2527 return new Uint64List(length);
2528 }
2529 }
2530
2531 class _Float32ArrayView extends _TypedListView
2532 with _DoubleListMixin
2533 implements Float32List {
2534 // Constructor.
2535 _Float32ArrayView(_ByteBuffer buffer, [int _offsetInBytes = 0, int _length])
2536 : super(
2537 buffer,
2538 _offsetInBytes,
2539 _defaultIfNull(
2540 _length,
2541 ((buffer.lengthInBytes - _offsetInBytes) ~/
2542 Float32List.BYTES_PER_ELEMENT))) {
2543 _rangeCheck(buffer.lengthInBytes, offsetInBytes,
2544 length * Float32List.BYTES_PER_ELEMENT);
2545 _offsetAlignmentCheck(_offsetInBytes, Float32List.BYTES_PER_ELEMENT);
2546 }
2547
2548 // Method(s) implementing List interface.
2549 double operator [](int index) {
2550 if (index < 0 || index >= length) {
2551 throw new RangeError.index(index, this, "index");
2552 }
2553 return _typedData
2554 ._getFloat32(offsetInBytes + (index * Float32List.BYTES_PER_ELEMENT));
2555 }
2556
2557 void operator []=(int index, double value) {
2558 if (index < 0 || index >= length) {
2559 throw new RangeError.index(index, this, "index");
2560 }
2561 _typedData._setFloat32(
2562 offsetInBytes + (index * Float32List.BYTES_PER_ELEMENT), value);
2563 }
2564
2565 // Method(s) implementing TypedData interface.
2566 int get elementSizeInBytes {
2567 return Float32List.BYTES_PER_ELEMENT;
2568 }
2569
2570 // Internal utility methods.
2571 Float32List _createList(int length) {
2572 return new Float32List(length);
2573 }
2574 }
2575
2576 class _Float64ArrayView extends _TypedListView
2577 with _DoubleListMixin
2578 implements Float64List {
2579 // Constructor.
2580 _Float64ArrayView(_ByteBuffer buffer, [int _offsetInBytes = 0, int _length])
2581 : super(
2582 buffer,
2583 _offsetInBytes,
2584 _defaultIfNull(
2585 _length,
2586 ((buffer.lengthInBytes - _offsetInBytes) ~/
2587 Float64List.BYTES_PER_ELEMENT))) {
2588 _rangeCheck(buffer.lengthInBytes, offsetInBytes,
2589 length * Float64List.BYTES_PER_ELEMENT);
2590 _offsetAlignmentCheck(_offsetInBytes, Float64List.BYTES_PER_ELEMENT);
2591 }
2592
2593 // Method(s) implementing List interface.
2594 double operator [](int index) {
2595 if (index < 0 || index >= length) {
2596 throw new RangeError.index(index, this, "index");
2597 }
2598 return _typedData
2599 ._getFloat64(offsetInBytes + (index * Float64List.BYTES_PER_ELEMENT));
2600 }
2601
2602 void operator []=(int index, double value) {
2603 if (index < 0 || index >= length) {
2604 throw new RangeError.index(index, this, "index");
2605 }
2606 _typedData._setFloat64(
2607 offsetInBytes + (index * Float64List.BYTES_PER_ELEMENT), value);
2608 }
2609
2610 // Method(s) implementing TypedData interface.
2611 int get elementSizeInBytes {
2612 return Float64List.BYTES_PER_ELEMENT;
2613 }
2614
2615 // Internal utility methods.
2616 Float64List _createList(int length) {
2617 return new Float64List(length);
2618 }
2619 }
2620
2621 class _Float32x4ArrayView extends _TypedListView
2622 with _Float32x4ListMixin
2623 implements Float32x4List {
2624 // Constructor.
2625 _Float32x4ArrayView(_ByteBuffer buffer, [int _offsetInBytes = 0, int _length])
2626 : super(
2627 buffer,
2628 _offsetInBytes,
2629 _defaultIfNull(
2630 _length,
2631 ((buffer.lengthInBytes - _offsetInBytes) ~/
2632 Float32x4List.BYTES_PER_ELEMENT))) {
2633 _rangeCheck(buffer.lengthInBytes, offsetInBytes,
2634 length * Float32x4List.BYTES_PER_ELEMENT);
2635 _offsetAlignmentCheck(_offsetInBytes, Float32x4List.BYTES_PER_ELEMENT);
2636 }
2637
2638 // Method(s) implementing List interface.
2639 Float32x4 operator [](int index) {
2640 if (index < 0 || index >= length) {
2641 throw new RangeError.index(index, this, "index");
2642 }
2643 return _typedData._getFloat32x4(
2644 offsetInBytes + (index * Float32x4List.BYTES_PER_ELEMENT));
2645 }
2646
2647 void operator []=(int index, Float32x4 value) {
2648 if (index < 0 || index >= length) {
2649 throw new RangeError.index(index, this, "index");
2650 }
2651 _typedData._setFloat32x4(
2652 offsetInBytes + (index * Float32x4List.BYTES_PER_ELEMENT), value);
2653 }
2654
2655 // Method(s) implementing TypedData interface.
2656 int get elementSizeInBytes {
2657 return Float32x4List.BYTES_PER_ELEMENT;
2658 }
2659
2660 // Internal utility methods.
2661 Float32x4List _createList(int length) {
2662 return new Float32x4List(length);
2663 }
2664 }
2665
2666 class _Int32x4ArrayView extends _TypedListView
2667 with _Int32x4ListMixin
2668 implements Int32x4List {
2669 // Constructor.
2670 _Int32x4ArrayView(_ByteBuffer buffer, [int _offsetInBytes = 0, int _length])
2671 : super(
2672 buffer,
2673 _offsetInBytes,
2674 _defaultIfNull(
2675 _length,
2676 ((buffer.lengthInBytes - _offsetInBytes) ~/
2677 Int32x4List.BYTES_PER_ELEMENT))) {
2678 _rangeCheck(buffer.lengthInBytes, offsetInBytes,
2679 length * Int32x4List.BYTES_PER_ELEMENT);
2680 _offsetAlignmentCheck(_offsetInBytes, Int32x4List.BYTES_PER_ELEMENT);
2681 }
2682
2683 // Method(s) implementing List interface.
2684 Int32x4 operator [](int index) {
2685 if (index < 0 || index >= length) {
2686 throw new RangeError.index(index, this, "index");
2687 }
2688 return _typedData
2689 ._getInt32x4(offsetInBytes + (index * Int32x4List.BYTES_PER_ELEMENT));
2690 }
2691
2692 void operator []=(int index, Int32x4 value) {
2693 if (index < 0 || index >= length) {
2694 throw new RangeError.index(index, this, "index");
2695 }
2696 _typedData._setInt32x4(
2697 offsetInBytes + (index * Int32x4List.BYTES_PER_ELEMENT), value);
2698 }
2699
2700 // Method(s) implementing TypedData interface.
2701 int get elementSizeInBytes {
2702 return Int32x4List.BYTES_PER_ELEMENT;
2703 }
2704
2705 // Internal utility methods.
2706 Int32x4List _createList(int length) {
2707 return new Int32x4List(length);
2708 }
2709 }
2710
2711 class _Float64x2ArrayView extends _TypedListView
2712 with _Float64x2ListMixin
2713 implements Float64x2List {
2714 // Constructor.
2715 _Float64x2ArrayView(_ByteBuffer buffer, [int _offsetInBytes = 0, int _length])
2716 : super(
2717 buffer,
2718 _offsetInBytes,
2719 _defaultIfNull(
2720 _length,
2721 ((buffer.lengthInBytes - _offsetInBytes) ~/
2722 Float64x2List.BYTES_PER_ELEMENT))) {
2723 _rangeCheck(buffer.lengthInBytes, offsetInBytes,
2724 length * Float64x2List.BYTES_PER_ELEMENT);
2725 _offsetAlignmentCheck(_offsetInBytes, Float64x2List.BYTES_PER_ELEMENT);
2726 }
2727
2728 // Method(s) implementing List interface.
2729 Float64x2 operator [](int index) {
2730 if (index < 0 || index >= length) {
2731 throw new RangeError.index(index, this, "index");
2732 }
2733 return _typedData._getFloat64x2(
2734 offsetInBytes + (index * Float64x2List.BYTES_PER_ELEMENT));
2735 }
2736
2737 void operator []=(int index, Float64x2 value) {
2738 if (index < 0 || index >= length) {
2739 throw new RangeError.index(index, this, "index");
2740 }
2741 _typedData._setFloat64x2(
2742 offsetInBytes + (index * Float64x2List.BYTES_PER_ELEMENT), value);
2743 }
2744
2745 // Method(s) implementing TypedData interface.
2746 int get elementSizeInBytes {
2747 return Float64x2List.BYTES_PER_ELEMENT;
2748 }
2749
2750 // Internal utility methods.
2751 Float64x2List _createList(int length) {
2752 return new Float64x2List(length);
2753 }
2754 }
2755
2756 class _ByteDataView implements ByteData {
2757 _ByteDataView(TypedData typedData, int _offsetInBytes, int _lengthInBytes)
2758 : _typedData = typedData,
2759 _offset = _offsetInBytes,
2760 length = _lengthInBytes {
2761 _rangeCheck(_typedData.lengthInBytes, _offset, length);
2762 }
2763
2764 // Method(s) implementing TypedData interface.
2765 _ByteBuffer get buffer {
2766 return _typedData.buffer;
2767 }
2768
2769 int get lengthInBytes {
2770 return length;
2771 }
2772
2773 int get offsetInBytes {
2774 return _offset;
2775 }
2776
2777 int get elementSizeInBytes {
2778 return 1;
2779 }
2780
2781 // Method(s) implementing ByteData interface.
2782
2783 int getInt8(int byteOffset) {
2784 if (byteOffset < 0 || byteOffset >= length) {
2785 throw new RangeError.index(byteOffset, this, "byteOffset");
2786 }
2787 return _typedData._getInt8(_offset + byteOffset);
2788 }
2789
2790 void setInt8(int byteOffset, int value) {
2791 if (byteOffset < 0 || byteOffset >= length) {
2792 throw new RangeError.index(byteOffset, this, "byteOffset");
2793 }
2794 _typedData._setInt8(_offset + byteOffset, value);
2795 }
2796
2797 int getUint8(int byteOffset) {
2798 if (byteOffset < 0 || byteOffset >= length) {
2799 throw new RangeError.index(byteOffset, this, "byteOffset");
2800 }
2801 return _typedData._getUint8(_offset + byteOffset);
2802 }
2803
2804 void setUint8(int byteOffset, int value) {
2805 if (byteOffset < 0 || byteOffset >= length) {
2806 throw new RangeError.index(byteOffset, this, "byteOffset");
2807 }
2808 _typedData._setUint8(_offset + byteOffset, value);
2809 }
2810
2811 int getInt16(int byteOffset, [Endianness endian = Endianness.BIG_ENDIAN]) {
2812 if (byteOffset < 0 || byteOffset + 1 >= length) {
2813 throw new RangeError.range(byteOffset, 0, length - 2, "byteOffset");
2814 }
2815 var result = _typedData._getInt16(_offset + byteOffset);
2816 if (identical(endian, Endianness.HOST_ENDIAN)) {
2817 return result;
2818 }
2819 return _byteSwap16(result).toSigned(16);
2820 }
2821
2822 void setInt16(int byteOffset, int value,
2823 [Endianness endian = Endianness.BIG_ENDIAN]) {
2824 if (byteOffset < 0 || byteOffset + 1 >= length) {
2825 throw new RangeError.range(byteOffset, 0, length - 2, "byteOffset");
2826 }
2827 _typedData._setInt16(_offset + byteOffset,
2828 identical(endian, Endianness.HOST_ENDIAN) ? value : _byteSwap16(value));
2829 }
2830
2831 int getUint16(int byteOffset, [Endianness endian = Endianness.BIG_ENDIAN]) {
2832 if (byteOffset < 0 || byteOffset + 1 >= length) {
2833 throw new RangeError.range(byteOffset, 0, length - 2, "byteOffset");
2834 }
2835 var result = _typedData._getUint16(_offset + byteOffset);
2836 if (identical(endian, Endianness.HOST_ENDIAN)) {
2837 return result;
2838 }
2839 return _byteSwap16(result);
2840 }
2841
2842 void setUint16(int byteOffset, int value,
2843 [Endianness endian = Endianness.BIG_ENDIAN]) {
2844 if (byteOffset < 0 || byteOffset + 1 >= length) {
2845 throw new RangeError.range(byteOffset, 0, length - 2, "byteOffset");
2846 }
2847 _typedData._setUint16(_offset + byteOffset,
2848 identical(endian, Endianness.HOST_ENDIAN) ? value : _byteSwap16(value));
2849 }
2850
2851 int getInt32(int byteOffset, [Endianness endian = Endianness.BIG_ENDIAN]) {
2852 if (byteOffset < 0 || byteOffset + 3 >= length) {
2853 throw new RangeError.range(byteOffset, 0, length - 4, "byteOffset");
2854 }
2855 var result = _typedData._getInt32(_offset + byteOffset);
2856 if (identical(endian, Endianness.HOST_ENDIAN)) {
2857 return result;
2858 }
2859 return _byteSwap32(result).toSigned(32);
2860 }
2861
2862 void setInt32(int byteOffset, int value,
2863 [Endianness endian = Endianness.BIG_ENDIAN]) {
2864 if (byteOffset < 0 || byteOffset + 3 >= length) {
2865 throw new RangeError.range(byteOffset, 0, length - 4, "byteOffset");
2866 }
2867 _typedData._setInt32(_offset + byteOffset,
2868 identical(endian, Endianness.HOST_ENDIAN) ? value : _byteSwap32(value));
2869 }
2870
2871 int getUint32(int byteOffset, [Endianness endian = Endianness.BIG_ENDIAN]) {
2872 if (byteOffset < 0 || byteOffset + 3 >= length) {
2873 throw new RangeError.range(byteOffset, 0, length - 4, "byteOffset");
2874 }
2875 var result = _typedData._getUint32(_offset + byteOffset);
2876 if (identical(endian, Endianness.HOST_ENDIAN)) {
2877 return result;
2878 }
2879 return _byteSwap32(result);
2880 }
2881
2882 void setUint32(int byteOffset, int value,
2883 [Endianness endian = Endianness.BIG_ENDIAN]) {
2884 if (byteOffset < 0 || byteOffset + 3 >= length) {
2885 throw new RangeError.range(byteOffset, 0, length - 4, "byteOffset");
2886 }
2887 _typedData._setUint32(_offset + byteOffset,
2888 identical(endian, Endianness.HOST_ENDIAN) ? value : _byteSwap32(value));
2889 }
2890
2891 int getInt64(int byteOffset, [Endianness endian = Endianness.BIG_ENDIAN]) {
2892 if (byteOffset < 0 || byteOffset + 7 >= length) {
2893 throw new RangeError.range(byteOffset, 0, length - 8, "byteOffset");
2894 }
2895 var result = _typedData._getInt64(_offset + byteOffset);
2896 if (identical(endian, Endianness.HOST_ENDIAN)) {
2897 return result;
2898 }
2899 return _byteSwap64(result).toSigned(64);
2900 }
2901
2902 void setInt64(int byteOffset, int value,
2903 [Endianness endian = Endianness.BIG_ENDIAN]) {
2904 if (byteOffset < 0 || byteOffset + 7 >= length) {
2905 throw new RangeError.range(byteOffset, 0, length - 8, "byteOffset");
2906 }
2907 _typedData._setInt64(_offset + byteOffset,
2908 identical(endian, Endianness.HOST_ENDIAN) ? value : _byteSwap64(value));
2909 }
2910
2911 int getUint64(int byteOffset, [Endianness endian = Endianness.BIG_ENDIAN]) {
2912 if (byteOffset < 0 || byteOffset + 7 >= length) {
2913 throw new RangeError.range(byteOffset, 0, length - 8, "byteOffset");
2914 }
2915 var result = _typedData._getUint64(_offset + byteOffset);
2916 if (identical(endian, Endianness.HOST_ENDIAN)) {
2917 return result;
2918 }
2919 return _byteSwap64(result);
2920 }
2921
2922 void setUint64(int byteOffset, int value,
2923 [Endianness endian = Endianness.BIG_ENDIAN]) {
2924 if (byteOffset < 0 || byteOffset + 7 >= length) {
2925 throw new RangeError.range(byteOffset, 0, length - 8, "byteOffset");
2926 }
2927 _typedData._setUint64(_offset + byteOffset,
2928 identical(endian, Endianness.HOST_ENDIAN) ? value : _byteSwap64(value));
2929 }
2930
2931 double getFloat32(int byteOffset,
2932 [Endianness endian = Endianness.BIG_ENDIAN]) {
2933 if (byteOffset < 0 || byteOffset + 3 >= length) {
2934 throw new RangeError.range(byteOffset, 0, length - 4, "byteOffset");
2935 }
2936 if (identical(endian, Endianness.HOST_ENDIAN)) {
2937 return _typedData._getFloat32(_offset + byteOffset);
2938 }
2939 _convU32[0] = _byteSwap32(_typedData._getUint32(_offset + byteOffset));
2940 return _convF32[0];
2941 }
2942
2943 void setFloat32(int byteOffset, double value,
2944 [Endianness endian = Endianness.BIG_ENDIAN]) {
2945 if (byteOffset < 0 || byteOffset + 3 >= length) {
2946 throw new RangeError.range(byteOffset, 0, length - 4, "byteOffset");
2947 }
2948 if (identical(endian, Endianness.HOST_ENDIAN)) {
2949 _typedData._setFloat32(_offset + byteOffset, value);
2950 return;
2951 }
2952 _convF32[0] = value;
2953 _typedData._setUint32(_offset + byteOffset, _byteSwap32(_convU32[0]));
2954 }
2955
2956 double getFloat64(int byteOffset,
2957 [Endianness endian = Endianness.BIG_ENDIAN]) {
2958 if (byteOffset < 0 || byteOffset + 7 >= length) {
2959 throw new RangeError.range(byteOffset, 0, length - 8, "byteOffset");
2960 }
2961 if (identical(endian, Endianness.HOST_ENDIAN)) {
2962 return _typedData._getFloat64(_offset + byteOffset);
2963 }
2964 _convU64[0] = _byteSwap64(_typedData._getUint64(_offset + byteOffset));
2965 return _convF64[0];
2966 }
2967
2968 void setFloat64(int byteOffset, double value,
2969 [Endianness endian = Endianness.BIG_ENDIAN]) {
2970 if (byteOffset < 0 || byteOffset + 7 >= length) {
2971 throw new RangeError.range(byteOffset, 0, length - 8, "byteOffset");
2972 }
2973 if (identical(endian, Endianness.HOST_ENDIAN)) {
2974 _typedData._setFloat64(_offset + byteOffset, value);
2975 return;
2976 }
2977 _convF64[0] = value;
2978 _typedData._setUint64(_offset + byteOffset, _byteSwap64(_convU64[0]));
2979 }
2980
2981 Float32x4 getFloat32x4(int byteOffset,
2982 [Endianness endian = Endianness.BIG_ENDIAN]) {
2983 if (byteOffset < 0 || byteOffset + 3 >= length) {
2984 throw new RangeError.range(byteOffset, 0, length - 4, "byteOffset");
2985 }
2986 // TODO(johnmccutchan) : Need to resolve this for endianity.
2987 return _typedData._getFloat32x4(_offset + byteOffset);
2988 }
2989
2990 void setFloat32x4(int byteOffset, Float32x4 value,
2991 [Endianness endian = Endianness.BIG_ENDIAN]) {
2992 if (byteOffset < 0 || byteOffset + 3 >= length) {
2993 throw new RangeError.range(byteOffset, 0, length - 4, "byteOffset");
2994 }
2995 // TODO(johnmccutchan) : Need to resolve this for endianity.
2996 _typedData._setFloat32x4(_offset + byteOffset, value);
2997 }
2998
2999 final TypedData _typedData;
3000 final int _offset;
3001 final int length;
3002 }
3003
3004 int _byteSwap16(int value) {
3005 return ((value & 0xFF00) >> 8) | ((value & 0x00FF) << 8);
3006 }
3007
3008 int _byteSwap32(int value) {
3009 value = ((value & 0xFF00FF00) >> 8) | ((value & 0x00FF00FF) << 8);
3010 value = ((value & 0xFFFF0000) >> 16) | ((value & 0x0000FFFF) << 16);
3011 return value;
3012 }
3013
3014 int _byteSwap64(int value) {
3015 return (_byteSwap32(value) << 32) | _byteSwap32(value >> 32);
3016 }
3017
3018 final _convU32 = new Uint32List(2);
3019 final _convU64 = new Uint64List.view(_convU32.buffer);
3020 final _convF32 = new Float32List.view(_convU32.buffer);
3021 final _convF64 = new Float64List.view(_convU32.buffer);
3022
3023 // Top level utility methods.
3024 int _toInt(int value, int mask) {
3025 value &= mask;
3026 if (value > (mask >> 1)) value -= mask + 1;
3027 return value;
3028 }
3029
3030 int _toInt8(int value) {
3031 return _toInt(value, 0xFF);
3032 }
3033
3034 int _toUint8(int value) {
3035 return value & 0xFF;
3036 }
3037
3038 int _toClampedUint8(int value) {
3039 if (value < 0) return 0;
3040 if (value > 0xFF) return 0xFF;
3041 return value;
3042 }
3043
3044 int _toInt16(int value) {
3045 return _toInt(value, 0xFFFF);
3046 }
3047
3048 int _toUint16(int value) {
3049 return value & 0xFFFF;
3050 }
3051
3052 int _toInt32(int value) {
3053 return _toInt(value, 0xFFFFFFFF);
3054 }
3055
3056 int _toUint32(int value) {
3057 return value & 0xFFFFFFFF;
3058 }
3059
3060 int _toInt64(int value) {
3061 // Avoid bigint mask when possible.
3062 return (ClassID.getID(value) == ClassID.cidBigint)
3063 ? _toInt(value, 0xFFFFFFFFFFFFFFFF)
3064 : value;
3065 }
3066
3067 int _toUint64(int value) {
3068 // Avoid bigint mask when possible.
3069 return (ClassID.getID(value) == ClassID.cidBigint)
3070 ? _toInt(value, 0xFFFFFFFFFFFFFFFF)
3071 : value;
3072 }
3073
3074 void _rangeCheck(int listLength, int start, int length) {
3075 if (length < 0) {
3076 throw new RangeError.value(length);
3077 }
3078 if (start < 0) {
3079 throw new RangeError.value(start);
3080 }
3081 if (start + length > listLength) {
3082 throw new RangeError.value(start + length);
3083 }
3084 }
3085
3086 void _offsetAlignmentCheck(int offset, int alignment) {
3087 if ((offset % alignment) != 0) {
3088 throw new RangeError('Offset ($offset) must be a multiple of '
3089 'BYTES_PER_ELEMENT ($alignment)');
3090 }
3091 }
3092
3093 int _defaultIfNull(object, value) {
3094 if (object == null) {
3095 return value;
3096 }
3097 return object;
3098 }
OLDNEW
« no previous file with comments | « runtime/lib/typed_data.dart ('k') | runtime/lib/typed_data_sources.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698