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

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

Issue 11437028: Added Uint8ClampedList. COmpielr optimziations to follow in next CL. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 patch class Int8List { 5 patch class Int8List {
6 /* patch */ factory Int8List(int length) { 6 /* patch */ factory Int8List(int length) {
7 return new _Int8Array(length); 7 return new _Int8Array(length);
8 } 8 }
9 9
10 /* patch */ factory Int8List.transferable(int length) { 10 /* patch */ factory Int8List.transferable(int length) {
(...skipping 16 matching lines...) Expand all
27 return new _Uint8Array.transferable(length); 27 return new _Uint8Array.transferable(length);
28 } 28 }
29 29
30 /* patch */ factory Uint8List.view(ByteArray array, 30 /* patch */ factory Uint8List.view(ByteArray array,
31 [int start = 0, int length]) { 31 [int start = 0, int length]) {
32 return new _Uint8ArrayView(array, start, length); 32 return new _Uint8ArrayView(array, start, length);
33 } 33 }
34 } 34 }
35 35
36 36
37 patch class Uint8ClampedList {
38 /* patch */ factory Uint8ClampedList(int length) {
39 return new _Uint8ClampedArray(length);
40 }
41
42 /* patch */ factory Uint8ClampedList.transferable(int length) {
43 return new _Uint8ClampedArray.transferable(length);
44 }
45
46 /* patch */ factory Uint8ClampedList.view(ByteArray array,
47 [int start = 0, int length]) {
cshapiro 2012/12/05 23:01:49 Is this indented correctly? I would assume the op
srdjan 2012/12/06 19:23:14 Done.
48 return new _Uint8ClampedArrayView(array, start, length);
49 }
50 }
51
52
37 patch class Int16List { 53 patch class Int16List {
38 /* patch */ factory Int16List(int length) { 54 /* patch */ factory Int16List(int length) {
39 return new _Int16Array(length); 55 return new _Int16Array(length);
40 } 56 }
41 57
42 /* patch */ factory Int16List.transferable(int length) { 58 /* patch */ factory Int16List.transferable(int length) {
43 return new _Int16Array.transferable(length); 59 return new _Int16Array.transferable(length);
44 } 60 }
45 61
46 /* patch */ factory Int16List.view(ByteArray array, [int start = 0, int length ]) { 62 /* patch */ factory Int16List.view(ByteArray array, [int start = 0, int length ]) {
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 454
439 int lengthInBytes() { 455 int lengthInBytes() {
440 return _length() * _BYTES_PER_ELEMENT; 456 return _length() * _BYTES_PER_ELEMENT;
441 } 457 }
442 458
443 static const int _BYTES_PER_ELEMENT = 1; 459 static const int _BYTES_PER_ELEMENT = 1;
444 460
445 static _Int8Array _new(int length) native "Int8Array_new"; 461 static _Int8Array _new(int length) native "Int8Array_new";
446 static _Int8Array _newTransferable(int length) 462 static _Int8Array _newTransferable(int length)
447 native "Int8Array_newTransferable"; 463 native "Int8Array_newTransferable";
448
449 464
450 int _getIndexed(int index) native "Int8Array_getIndexed"; 465 int _getIndexed(int index) native "Int8Array_getIndexed";
451 int _setIndexed(int index, int value) native "Int8Array_setIndexed"; 466 int _setIndexed(int index, int value) native "Int8Array_setIndexed";
452 } 467 }
453 468
454 469
455 class _Uint8Array extends _ByteArrayBase implements Uint8List { 470 class _Uint8Array extends _ByteArrayBase implements Uint8List {
456 factory _Uint8Array(int length) { 471 factory _Uint8Array(int length) {
457 return _new(length); 472 return _new(length);
458 } 473 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 return _BYTES_PER_ELEMENT; 521 return _BYTES_PER_ELEMENT;
507 } 522 }
508 523
509 int lengthInBytes() { 524 int lengthInBytes() {
510 return _length() * _BYTES_PER_ELEMENT; 525 return _length() * _BYTES_PER_ELEMENT;
511 } 526 }
512 527
513 static const int _BYTES_PER_ELEMENT = 1; 528 static const int _BYTES_PER_ELEMENT = 1;
514 529
515 static _Uint8Array _new(int length) native "Uint8Array_new"; 530 static _Uint8Array _new(int length) native "Uint8Array_new";
516 static _Uint8Array _newTransferable(int length) 531 static _Uint8Array _newTransferable(int length)
517 native "Uint8Array_newTransferable"; 532 native "Uint8Array_newTransferable";
518 533
519 int _getIndexed(int index) native "Uint8Array_getIndexed"; 534 int _getIndexed(int index) native "Uint8Array_getIndexed";
520 int _setIndexed(int index, int value) native "Uint8Array_setIndexed"; 535 int _setIndexed(int index, int value) native "Uint8Array_setIndexed";
521 } 536 }
522 537
523 538
539
cshapiro 2012/12/05 23:01:49 extra vertical space?
srdjan 2012/12/06 19:23:14 Done.
540 class _Uint8ClampedArray extends _ByteArrayBase implements Uint8ClampedList {
541 factory _Uint8ClampedArray(int length) {
542 return _new(length);
543 }
544
545 factory _Uint8ClampedArray.transferable(int length) {
546 return _newTransferable(length);
547 }
548
549 factory _Uint8ClampedArray.view(ByteArray array,
550 [int start = 0, int length]) {
551 if (length == null) {
552 length = array.lengthInBytes();
553 }
554 return new _Uint8ClampedArrayView(array, start, length);
555 }
556
557 int operator[](int index) {
558 return _getIndexed(index);
559 }
560
561 int operator[]=(int index, int value) {
562 if (value < 0) {
563 value = 0;
564 } else if (value > 0xFF) {
565 value = 0xFF;
566 }
567 _setIndexed(index, _toUint8(value));
cshapiro 2012/12/05 23:01:49 Why not replace lines 562-566 with a new function
srdjan 2012/12/06 19:23:14 Done.
568 }
569
570 Iterator<int> iterator() {
571 return new _ByteArrayIterator<int>(this);
572 }
573
574 List<int> getRange(int start, int length) {
575 _rangeCheck(this.length, start, length);
576 List<int> result = _new(length);
577 result.setRange(0, length, this, start);
578 return result;
579 }
580
581 void setRange(int start, int length, List<int> from, [int startFrom = 0]) {
582 if (from is _Uint8ClampedArray || from is _ExternalUint8ClampedArray) {
cshapiro 2012/12/05 23:01:49 I think _Uint8Array and _ExternalUint8Array are va
srdjan 2012/12/06 19:23:14 We need to talk more about that.
583 _setRange(start * _BYTES_PER_ELEMENT,
584 length * _BYTES_PER_ELEMENT,
585 from,
586 startFrom * _BYTES_PER_ELEMENT);
587 } else {
588 Arrays.copy(from, startFrom, this, start, length);
589 }
590 }
591
592 String toString() {
593 return Collections.collectionToString(this);
594 }
595
596 int bytesPerElement() {
597 return _BYTES_PER_ELEMENT;
598 }
599
600 int lengthInBytes() {
601 return _length() * _BYTES_PER_ELEMENT;
602 }
603
604 static const int _BYTES_PER_ELEMENT = 1;
605
606 static _Uint8ClampedArray _new(int length) native "Uint8ClampedArray_new";
607 static _Uint8ClampedArray _newTransferable(int length)
608 native "Uint8ClampedArray_newTransferable";
609
610 int _getIndexed(int index) native "Uint8ClampedArray_getIndexed";
611 int _setIndexed(int index, int value) native "Uint8ClampedArray_setIndexed";
612 }
613
614
524 class _Int16Array extends _ByteArrayBase implements Int16List { 615 class _Int16Array extends _ByteArrayBase implements Int16List {
525 factory _Int16Array(int length) { 616 factory _Int16Array(int length) {
526 return _new(length); 617 return _new(length);
527 } 618 }
528 619
529 factory _Int16Array.transferable(int length) { 620 factory _Int16Array.transferable(int length) {
530 return _newTransferable(length); 621 return _newTransferable(length);
531 } 622 }
532 623
533 factory _Int16Array.view(ByteArray array, [int start = 0, int length]) { 624 factory _Int16Array.view(ByteArray array, [int start = 0, int length]) {
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 806
716 int lengthInBytes() { 807 int lengthInBytes() {
717 return _length() * _BYTES_PER_ELEMENT; 808 return _length() * _BYTES_PER_ELEMENT;
718 } 809 }
719 810
720 static const int _BYTES_PER_ELEMENT = 4; 811 static const int _BYTES_PER_ELEMENT = 4;
721 812
722 static _Int32Array _new(int length) native "Int32Array_new"; 813 static _Int32Array _new(int length) native "Int32Array_new";
723 static _Int32Array _newTransferable(int length) 814 static _Int32Array _newTransferable(int length)
724 native "Int32Array_newTransferable"; 815 native "Int32Array_newTransferable";
725 816
726 817
727 int _getIndexed(int index) native "Int32Array_getIndexed"; 818 int _getIndexed(int index) native "Int32Array_getIndexed";
728 int _setIndexed(int index, int value) native "Int32Array_setIndexed"; 819 int _setIndexed(int index, int value) native "Int32Array_setIndexed";
729 } 820 }
730 821
731 822
732 class _Uint32Array extends _ByteArrayBase implements Uint32List { 823 class _Uint32Array extends _ByteArrayBase implements Uint32List {
733 factory _Uint32Array(int length) { 824 factory _Uint32Array(int length) {
734 return _new(length); 825 return _new(length);
735 } 826 }
(...skipping 1785 matching lines...) Expand 10 before | Expand all | Expand 10 after
2521 } 2612 }
2522 _rangeCheck(this.length, start, length); 2613 _rangeCheck(this.length, start, length);
2523 return _array.subByteArray(_offset + start, length); 2614 return _array.subByteArray(_offset + start, length);
2524 } 2615 }
2525 2616
2526 static const int _BYTES_PER_ELEMENT = 8; 2617 static const int _BYTES_PER_ELEMENT = 8;
2527 final ByteArray _array; 2618 final ByteArray _array;
2528 final int _offset; 2619 final int _offset;
2529 final int _length; 2620 final int _length;
2530 } 2621 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698