Chromium Code Reviews| Index: runtime/lib/typed_data.dart |
| diff --git a/runtime/lib/typed_data.dart b/runtime/lib/typed_data.dart |
| index 84905ef08c751aa4dba7f396f2d8e182614fb240..f4ae012d46913b4c9b81cbb5cd5af1d599dc58c7 100644 |
| --- a/runtime/lib/typed_data.dart |
| +++ b/runtime/lib/typed_data.dart |
| @@ -829,6 +829,29 @@ abstract class _TypedList extends _TypedListBase { |
| Float64x2 _getFloat64x2(int offsetInBytes) native "TypedData_GetFloat64x2"; |
| void _setFloat64x2(int offsetInBytes, Float64x2 value) |
| native "TypedData_SetFloat64x2"; |
| + |
| + /** Writes the code units of `string.substring(start, end)` as Uint16. */ |
| + void _setStringAt(int byteOffset, String string, int start, int end) { |
| + // This can be optimized to a mem-move if string is two-byte. |
| + int length = end - start; |
| + assert(byteOffset + length * Uint16List.BYTES_PER_ELEMENT <= |
| + this.lengthInBytes); |
| + for (int i = 0; i < length; i++) { |
| + _setUint16(byteOffset + i * Uint16List.BYTES_PER_ELEMENT, |
| + string.codeUnitAt(start + i)); |
| + } |
| + } |
| + |
| + void _setCodeUnits(CodeUnits units, int start, int end, int skipCount) { |
| + String string = CodeUnits.stringOf(units); |
| + end = RangeError.checkValidRange(start, end, length); |
| + int sliceLength = end - start; |
| + int sliceEnd = skipCount + sliceLength; |
| + RangeError.checkValidRange(skipCount, sliceEnd, |
| + string.length, |
| + "skipCount", "skipCount + length"); |
| + this._setStringAt(start * elementSizeInBytes, string, skipCount, sliceEnd); |
| + } |
| } |
| @@ -1029,6 +1052,13 @@ class _Uint16Array extends _TypedList with _IntListMixin implements Uint16List { |
| _setIndexedUint16(index, _toUint16(value)); |
| } |
| + void setRange(int start, int end, Iterable iterable, [int skipCount = 0]) { |
| + if (ClassID.getID(iterable) != CodeUnits.cid) { |
| + super.setRange(start, end, iterable, skipCount); |
| + } else { |
| + _setCodeUnits(iterable, start, end, skipCount); |
|
Vyacheslav Egorov (Google)
2015/01/29 13:04:54
Maybe we should also have an optimization for Int8
Lasse Reichstein Nielsen
2015/01/29 13:13:27
I was planning to do that in a later CL.
|
| + } |
| + } |
| // Method(s) implementing the TypedData interface. |
| @@ -2453,7 +2483,7 @@ class _TypedListView extends _TypedListBase implements TypedData { |
| return _typedData.buffer; |
| } |
| - final TypedData _typedData; |
| + final _TypedList _typedData; |
| final int offsetInBytes; |
| final int length; |
| } |
| @@ -2681,6 +2711,13 @@ class _Uint16ArrayView extends _TypedListView with _IntListMixin implements Uint |
| _toUint16(value)); |
| } |
| + void setRange(int start, int end, Iterable iterable, [int skipCount = 0]) { |
| + if (ClassID.getID(iterable) != CodeUnits.cid) { |
| + super.setRange(start, end, iterable, skipCount); |
| + } else { |
| + _typed_Data._setCodeUnits(iterable, start, end, skipCount); |
| + } |
| + } |
| // Method(s) implementing TypedData interface. |
| @@ -2688,7 +2725,6 @@ class _Uint16ArrayView extends _TypedListView with _IntListMixin implements Uint |
| return Uint16List.BYTES_PER_ELEMENT; |
| } |
| - |
| // Internal utility methods. |
| Uint16List _createList(int length) { |