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

Side by Side Diff: lib/growable_array.dart

Issue 12218082: - Remove redundant type parameters for internal data. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 7 years, 10 months 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 | vm/intrinsifier.h » ('j') | vm/object.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 class _GrowableObjectArray<T> implements List<T> { 5 class _GrowableObjectArray<T> implements List<T> {
6 factory _GrowableObjectArray._uninstantiable() { 6 factory _GrowableObjectArray._uninstantiable() {
7 throw new UnsupportedError( 7 throw new UnsupportedError(
8 "GrowableObjectArray can only be allocated by the VM"); 8 "GrowableObjectArray can only be allocated by the VM");
9 } 9 }
10 10
11 T removeAt(int index) { 11 T removeAt(int index) {
12 if (index is! int) throw new ArgumentError(index); 12 if (index is! int) throw new ArgumentError(index);
13 T result = this[index]; 13 T result = this[index];
siva 2013/02/08 23:13:34 can this just be: var result = this[index]; (the t
Ivan Posva 2013/02/08 23:27:32 Agree with you that we should rip out ALL of the t
14 int newLength = this.length - 1; 14 int newLength = this.length - 1;
15 Arrays.copy(this, 15 Arrays.copy(this,
16 index + 1, 16 index + 1,
17 this, 17 this,
18 index, 18 index,
19 newLength - index); 19 newLength - index);
20 this.length = newLength; 20 this.length = newLength;
21 return result; 21 return result;
22 } 22 }
23 23
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 List<T> getRange(int start, int length) { 92 List<T> getRange(int start, int length) {
93 if (length == 0) return []; 93 if (length == 0) return [];
94 Arrays.rangeCheck(this, start, length); 94 Arrays.rangeCheck(this, start, length);
95 List list = new _GrowableObjectArray<T>.withCapacity(length); 95 List list = new _GrowableObjectArray<T>.withCapacity(length);
96 list.length = length; 96 list.length = length;
97 Arrays.copy(this, start, list, 0, length); 97 Arrays.copy(this, start, list, 0, length);
98 return list; 98 return list;
99 } 99 }
100 100
101 factory _GrowableObjectArray(int length) { 101 factory _GrowableObjectArray(int length) {
102 var data = new _ObjectArray<T>((length == 0) ? 4 : length); 102 var data = new _ObjectArray((length == 0) ? 4 : length);
103 var result = new _GrowableObjectArray<T>.withData(data); 103 var result = new _GrowableObjectArray<T>.withData(data);
104 result._setLength(length); 104 result._setLength(length);
105 return result; 105 return result;
106 } 106 }
107 107
108 factory _GrowableObjectArray.withCapacity(int capacity) { 108 factory _GrowableObjectArray.withCapacity(int capacity) {
109 var data = new _ObjectArray<T>((capacity == 0)? 4 : capacity); 109 var data = new _ObjectArray((capacity == 0)? 4 : capacity);
110 return new _GrowableObjectArray<T>.withData(data); 110 return new _GrowableObjectArray<T>.withData(data);
111 } 111 }
112 112
113 factory _GrowableObjectArray.from(Collection<T> other) { 113 factory _GrowableObjectArray.from(Collection<T> other) {
114 List<T> result = new _GrowableObjectArray<T>(); 114 List<T> result = new _GrowableObjectArray<T>();
siva 2013/02/08 23:13:34 var result = new ... just like how it is done in f
Ivan Posva 2013/02/08 23:27:32 Again, as above the removal of types in the bodies
115 result.addAll(other); 115 result.addAll(other);
116 return result; 116 return result;
117 } 117 }
118 118
119 factory _GrowableObjectArray.withData(_ObjectArray<T> data) 119 factory _GrowableObjectArray.withData(_ObjectArray data)
120 native "GrowableObjectArray_allocate"; 120 native "GrowableObjectArray_allocate";
121 121
122 int get length native "GrowableObjectArray_getLength"; 122 int get length native "GrowableObjectArray_getLength";
123 123
124 int get _capacity native "GrowableObjectArray_getCapacity"; 124 int get _capacity native "GrowableObjectArray_getCapacity";
125 125
126 void set length(int new_length) { 126 void set length(int new_length) {
127 if (new_length > _capacity) { 127 if (new_length > _capacity) {
128 _grow(new_length); 128 _grow(new_length);
129 } else { 129 } else {
130 for (int i = new_length; i < length; i++) { 130 for (int i = new_length; i < length; i++) {
131 this[i] = null; 131 this[i] = null;
132 } 132 }
133 } 133 }
134 _setLength(new_length); 134 _setLength(new_length);
135 } 135 }
136 136
137 void _setLength(int new_length) native "GrowableObjectArray_setLength"; 137 void _setLength(int new_length) native "GrowableObjectArray_setLength";
138 138
139 void _setData(_ObjectArray<T> array) native "GrowableObjectArray_setData"; 139 void _setData(_ObjectArray array) native "GrowableObjectArray_setData";
140 140
141 T operator [](int index) native "GrowableObjectArray_getIndexed"; 141 T operator [](int index) native "GrowableObjectArray_getIndexed";
142 142
143 void operator []=(int index, T value) native "GrowableObjectArray_setIndexed"; 143 void operator []=(int index, T value) native "GrowableObjectArray_setIndexed";
144 144
145 // The length of this growable array. It is always less than or equal to the 145 // The length of this growable array. It is always less than or equal to the
146 // length of the object array, which itself is always greater than 0, so that 146 // length of the object array, which itself is always greater than 0, so that
147 // grow() does not have to check for a zero length object array before 147 // grow() does not have to check for a zero length object array before
148 // doubling its size. 148 // doubling its size.
149 void add(T value) { 149 void add(T value) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 int indexOf(T element, [int start = 0]) { 196 int indexOf(T element, [int start = 0]) {
197 return Arrays.indexOf(this, element, start, length); 197 return Arrays.indexOf(this, element, start, length);
198 } 198 }
199 199
200 int lastIndexOf(T element, [int start = null]) { 200 int lastIndexOf(T element, [int start = null]) {
201 if (start == null) start = length - 1; 201 if (start == null) start = length - 1;
202 return Arrays.lastIndexOf(this, element, start); 202 return Arrays.lastIndexOf(this, element, start);
203 } 203 }
204 204
205 void _grow(int new_length) { 205 void _grow(int new_length) {
206 var new_data = new _ObjectArray<T>(new_length); 206 var new_data = new _ObjectArray(new_length);
207 for (int i = 0; i < length; i++) { 207 for (int i = 0; i < length; i++) {
208 new_data[i] = this[i]; 208 new_data[i] = this[i];
209 } 209 }
210 _setData(new_data); 210 _setData(new_data);
211 } 211 }
212 212
213 // Collection interface. 213 // Collection interface.
214 214
215 bool contains(T element) { 215 bool contains(T element) {
216 return IterableMixinWorkaround.contains(this, element); 216 return IterableMixinWorkaround.contains(this, element);
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 } 325 }
326 326
327 List<T> toList() { 327 List<T> toList() {
328 return new List<T>.from(this); 328 return new List<T>.from(this);
329 } 329 }
330 330
331 Set<T> toSet() { 331 Set<T> toSet() {
332 return new Set<T>.from(this); 332 return new Set<T>.from(this);
333 } 333 }
334 } 334 }
OLDNEW
« no previous file with comments | « no previous file | vm/intrinsifier.h » ('j') | vm/object.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698