Chromium Code Reviews| Index: runtime/lib/byte_array.dart |
| =================================================================== |
| --- runtime/lib/byte_array.dart (revision 3706) |
| +++ runtime/lib/byte_array.dart (working copy) |
| @@ -96,7 +96,12 @@ |
| } |
| void operator[]=(int index, int value) { |
| - setUint8(index, value); |
| + if (value is int && value >= 0 && value <= 255) { |
|
Ivan Posva
2012/02/01 01:05:27
Why this semantic change?
Anders Johnsen
2012/02/01 02:12:11
Are you meaning why to move the
if(!...) throw;
|
| + setUint8(index, value); |
| + } else { |
| + throw const IllegalArgumentException( |
| + "value is not an integer in byte range"); |
| + } |
| } |
| void set length(int newLength) { |
| @@ -141,9 +146,36 @@ |
| return this[length - 1]; |
| } |
| + void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
| + if (length < 0) { |
| + throw new IllegalArgumentException("negative length $length"); |
| + } |
| + if (from is ByteArray) { |
| + _setRange(from, startFrom, start, length); |
| + } else { |
| + Arrays.copy(from, startFrom, this, start, length); |
| + } |
| + } |
| + |
| + List getRange(int start, int length) { |
| + if (length == 0) return []; |
| + Arrays.rangeCheck(this, start, length); |
| + ByteArray list = new ByteArray(length); |
| + list._setRange(this, start, 0, length); |
| + return list; |
| + } |
| + |
| + |
| // Implementation |
| int _length() native "ByteArray_getLength"; |
| + |
| + void _setRange(ByteArray src, |
|
Ivan Posva
2012/02/01 01:05:27
It is very confusing to have two methods with esse
Anders Johnsen
2012/02/01 02:12:11
I absolutely agree, very good observation. I've up
|
| + int srcStart, |
| + int dstStart, |
| + int count) |
| + native "ByteArray_setRange"; |
| + |
| } |