Chromium Code Reviews| Index: runtime/lib/typed_data.dart |
| diff --git a/runtime/lib/typed_data.dart b/runtime/lib/typed_data.dart |
| index b1845732b7df58203cae4084736826644c89f0e1..7cd2419a986b8b8f143a3766b319b114f44d8ed6 100644 |
| --- a/runtime/lib/typed_data.dart |
| +++ b/runtime/lib/typed_data.dart |
| @@ -299,7 +299,7 @@ patch class Float64x2 { |
| patch class ByteData { |
| /* patch */ factory ByteData(int length) { |
| var list = new _Uint8Array(length); |
| - return new _ByteDataView(list.buffer, 0, length); |
| + return new _ByteDataView(list, 0, length); |
| } |
| /* patch */ factory ByteData.view(ByteBuffer buffer, |
| @@ -307,7 +307,12 @@ patch class ByteData { |
| if (length == null) { |
| length = buffer.lengthInBytes - offsetInBytes; |
| } |
| - return new _ByteDataView(buffer, offsetInBytes, length); |
| + return new _ByteDataView(buffer._data, offsetInBytes, length); |
| + } |
| + |
| + // Called directly from C code. |
| + factory ByteData._view(TypedData typedData, int offsetInBytes, int length) { |
| + return new _ByteDataView(typedData, offsetInBytes, length); |
| } |
| } |
| @@ -551,10 +556,10 @@ abstract class _TypedListBase { |
| if ((count < 10) && (from.buffer != this.buffer)) { |
| Lists.copy(from, skipCount, this, start, count); |
| return; |
| - } else if (this.buffer._setRange( |
| + } else if (this.buffer._data._setRange( |
| start * elementSizeInBytes + this.offsetInBytes, |
| count * elementSizeInBytes, |
| - from.buffer, |
| + from.buffer._data, |
| skipCount * elementSizeInBytes + from.offsetInBytes, |
| this._cid, from._cid)) { |
| return; |
| @@ -608,7 +613,19 @@ abstract class _TypedListBase { |
| } |
| -abstract class _TypedList extends _TypedListBase implements ByteBuffer { |
| +class _ByteBuffer implements ByteBuffer { |
| + final _TypedList _data; |
| + |
| + _ByteBuffer(this._data); |
| + |
| + // Forward calls to _data. |
| + int get lengthInBytes => _data.lengthInBytes; |
| + int get hashCode => _data.hashCode; |
| + bool operator==(Object other) => identical(_data, other._data); |
|
siva
2014/06/17 01:09:57
shouldn't this say
other is _ByteBuffer && identic
Cutch
2014/06/17 14:31:17
Done.
|
| +} |
| + |
| + |
| +abstract class _TypedList extends _TypedListBase { |
| // Default method implementing parts of the TypedData interface. |
| int get offsetInBytes { |
| return 0; |
| @@ -618,9 +635,7 @@ abstract class _TypedList extends _TypedListBase implements ByteBuffer { |
| return length * elementSizeInBytes; |
| } |
| - ByteBuffer get buffer { |
| - return this; |
| - } |
| + ByteBuffer get buffer => new _ByteBuffer(this); |
| // Methods implementing the collection interface. |
| @@ -2514,8 +2529,8 @@ class _TypedListIterator<E> implements Iterator<E> { |
| class _TypedListView extends _TypedListBase implements TypedData { |
| - _TypedListView(ByteBuffer _buffer, int _offset, int _length) |
| - : _typedData = _buffer, // This assignment is type safe. |
| + _TypedListView(_ByteBuffer _buffer, int _offset, int _length) |
| + : _typedData = _buffer._data, // This assignment is type safe. |
|
Ivan Posva
2014/06/17 01:07:02
You can drop the assignment comment now.
Cutch
2014/06/17 14:31:17
Done.
|
| offsetInBytes = _offset, |
| length = _length { |
| } |
| @@ -3263,11 +3278,11 @@ class _Float64x2ArrayView extends _TypedListView implements Float64x2List { |
| class _ByteDataView implements ByteData { |
| - _ByteDataView(ByteBuffer _buffer, int _offsetInBytes, int _lengthInBytes) |
| - : _typedData = _buffer, // _buffer is guaranteed to be a TypedData here. |
| + _ByteDataView(TypedData typedData, int _offsetInBytes, int _lengthInBytes) |
| + : _typedData = typedData, |
| _offset = _offsetInBytes, |
| length = _lengthInBytes { |
| - _rangeCheck(_buffer.lengthInBytes, _offset, length); |
| + _rangeCheck(_typedData.lengthInBytes, _offset, length); |
| } |