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

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

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

Powered by Google App Engine
This is Rietveld 408576698