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

Side by Side Diff: pkg/typed_data/lib/typed_buffers.dart

Issue 711003002: Add some ArgumentError and RangeError constructors that capture more information. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « no previous file | pkg/typed_data/pubspec.yaml » ('j') | sdk/lib/core/errors.dart » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 /** 5 /**
6 * Growable typed-data lists. 6 * Growable typed-data lists.
7 * 7 *
8 * These lists works just as a typed-data list, except that they are growable. 8 * These lists works just as a typed-data list, except that they are growable.
9 * They use an underlying buffer, and when that buffer becomes too small, it 9 * They use an underlying buffer, and when that buffer becomes too small, it
10 * is replaced by a new buffer. 10 * is replaced by a new buffer.
(...skipping 14 matching lines...) Expand all
25 /// which we don't have a type for here. 25 /// which we don't have a type for here.
26 var _buffer; 26 var _buffer;
27 /// The length of the list being built. 27 /// The length of the list being built.
28 int _length; 28 int _length;
29 29
30 _TypedDataBuffer(List<E> buffer) 30 _TypedDataBuffer(List<E> buffer)
31 : this._buffer = buffer, this._length = buffer.length; 31 : this._buffer = buffer, this._length = buffer.length;
32 32
33 int get length => _length; 33 int get length => _length;
34 E operator[](int index) { 34 E operator[](int index) {
35 if (index >= length) throw new RangeError.range(index, 0, length - 1); 35 if (index >= length) throw new RangeError.index(index, this);
36 return _buffer[index]; 36 return _buffer[index];
37 } 37 }
38 38
39 void operator[]=(int index, E value) { 39 void operator[]=(int index, E value) {
40 if (index >= length) throw new RangeError.range(index, 0, length - 1); 40 if (index >= length) throw new RangeError.index(index, this);
41 _buffer[index] = value; 41 _buffer[index] = value;
42 } 42 }
43 43
44 void set length(int newLength) { 44 void set length(int newLength) {
45 if (newLength < _length) { 45 if (newLength < _length) {
46 E defaultValue = _defaultValue; 46 E defaultValue = _defaultValue;
47 for (int i = newLength; i < _length; i++) { 47 for (int i = newLength; i < _length; i++) {
48 _buffer[i] = defaultValue; 48 _buffer[i] = defaultValue;
49 } 49 }
50 } else if (newLength > _buffer.length) { 50 } else if (newLength > _buffer.length) {
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 Int32x4 get _defaultValue => _zero; 226 Int32x4 get _defaultValue => _zero;
227 Int32x4List _createBuffer(int size) => new Int32x4List(size); 227 Int32x4List _createBuffer(int size) => new Int32x4List(size);
228 } 228 }
229 229
230 class Float32x4Buffer extends _TypedDataBuffer<Float32x4> { 230 class Float32x4Buffer extends _TypedDataBuffer<Float32x4> {
231 Float32x4Buffer([int initialLength = 0]) 231 Float32x4Buffer([int initialLength = 0])
232 : super(new Float32x4List(initialLength)); 232 : super(new Float32x4List(initialLength));
233 Float32x4 get _defaultValue => new Float32x4.zero(); 233 Float32x4 get _defaultValue => new Float32x4.zero();
234 Float32x4List _createBuffer(int size) => new Float32x4List(size); 234 Float32x4List _createBuffer(int size) => new Float32x4List(size);
235 } 235 }
OLDNEW
« no previous file with comments | « no previous file | pkg/typed_data/pubspec.yaml » ('j') | sdk/lib/core/errors.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698