OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 interface ByteArray extends List default _InternalByteArray { | 5 interface ByteArray extends List default _InternalByteArray { |
6 ByteArray(int length); | 6 ByteArray(int length); |
7 | 7 |
8 int get length(); | 8 int get length(); |
9 | 9 |
10 int getInt8(int byteOffset); | 10 int getInt8(int byteOffset); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
56 Iterator iterator() { | 56 Iterator iterator() { |
57 return new _ByteArrayIterator(this); | 57 return new _ByteArrayIterator(this); |
58 } | 58 } |
59 | 59 |
60 // Collection interface | 60 // Collection interface |
61 | 61 |
62 int get length() { | 62 int get length() { |
63 return _length(); | 63 return _length(); |
64 } | 64 } |
65 | 65 |
66 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
67 if (length < 0) { | |
68 throw new IllegalArgumentException("negative length $length"); | |
69 } | |
70 if (from is ByteArray) { | |
71 copy(this, start, from, startFrom, length); | |
72 } else { | |
73 Arrays.copy(from, startFrom, this, start, length); | |
74 } | |
75 } | |
76 | |
77 | |
78 List getRange(int start, int length) { | |
79 if (length == 0) return []; | |
80 Arrays.rangeCheck(this, start, length); | |
81 ByteArray list = new ByteArray(length); | |
82 copy(list, 0, this, start, length); | |
83 return list; | |
84 } | |
85 | |
86 static copy(ByteArray dst, | |
Anders Johnsen
2012/01/26 19:38:13
I'm not entirely happy with the placement of this
cshapiro
2012/01/27 23:00:04
I would create a private instance method _setRange
Anders Johnsen
2012/01/27 23:42:39
Thank you, way better! :)
| |
87 int dstStart, | |
88 ByteArray src, | |
89 int srcStart, | |
90 int length) { | |
91 dst._copyFromByteArray(src, srcStart, dstStart, length); | |
92 } | |
93 | |
94 void _copyFromByteArray(ByteArray src, | |
95 int srcStart, | |
96 int dstStart, | |
97 int count) | |
98 native "ByteArray_copyFromByteArray"; | |
99 | |
66 bool every(bool f(int element)) { | 100 bool every(bool f(int element)) { |
67 return Collections.every(this, f); | 101 return Collections.every(this, f); |
68 } | 102 } |
69 | 103 |
70 Collection map(f(int element)) { | 104 Collection map(f(int element)) { |
71 return Collections.map(this, | 105 return Collections.map(this, |
72 new GrowableObjectArray.withCapacity(length), | 106 new GrowableObjectArray.withCapacity(length), |
73 f); | 107 f); |
74 } | 108 } |
75 | 109 |
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
480 | 514 |
481 void _setFloat32(int byteOffset, double value) | 515 void _setFloat32(int byteOffset, double value) |
482 native "ExternalByteArray_setFloat32"; | 516 native "ExternalByteArray_setFloat32"; |
483 | 517 |
484 double _getFloat64(int byteOffset) | 518 double _getFloat64(int byteOffset) |
485 native "ExternalByteArray_getFloat64"; | 519 native "ExternalByteArray_getFloat64"; |
486 | 520 |
487 void _setFloat64(int byteOffset, double value) | 521 void _setFloat64(int byteOffset, double value) |
488 native "ExternalByteArray_setFloat64"; | 522 native "ExternalByteArray_setFloat64"; |
489 } | 523 } |
OLD | NEW |