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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/lib/js_array.dart

Issue 13956006: Remove insertRange. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebuild DOM (unrelated CL) and update status files. Created 7 years, 8 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
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 part of _interceptors; 5 part of _interceptors;
6 6
7 /** 7 /**
8 * The interceptor class for [List]. The compiler recognizes this 8 * The interceptor class for [List]. The compiler recognizes this
9 * class as an interceptor, and changes references to [:this:] to 9 * class as an interceptor, and changes references to [:this:] to
10 * actually use the receiver of the method, which is generated as an extra 10 * actually use the receiver of the method, which is generated as an extra
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 // TODO(ngeoffray): Parameterize the return value. 153 // TODO(ngeoffray): Parameterize the return value.
154 if (start == end) return []; 154 if (start == end) return [];
155 return JS('=List', r'#.slice(#, #)', this, start, end); 155 return JS('=List', r'#.slice(#, #)', this, start, end);
156 } 156 }
157 157
158 158
159 Iterable<E> getRange(int start, int end) { 159 Iterable<E> getRange(int start, int end) {
160 return IterableMixinWorkaround.getRangeList(this, start, end); 160 return IterableMixinWorkaround.getRangeList(this, start, end);
161 } 161 }
162 162
163 void insertRange(int start, int length, [E initialValue]) {
164 checkGrowable(this, 'insertRange');
165 if (length == 0) {
166 return;
167 }
168 if (length is !int) throw new ArgumentError(length);
169 if (length < 0) throw new ArgumentError(length);
170 if (start is !int) throw new ArgumentError(start);
171
172 var receiver = this;
173 var receiverLength = receiver.length;
174 if (start < 0 || start > receiverLength) {
175 throw new RangeError.value(start);
176 }
177 receiver.length = receiverLength + length;
178 Arrays.copy(receiver,
179 start,
180 receiver,
181 start + length,
182 receiverLength - start);
183 if (initialValue != null) {
184 for (int i = start; i < start + length; i++) {
185 receiver[i] = initialValue;
186 }
187 }
188 receiver.length = receiverLength + length;
189 }
190
191 E get first { 163 E get first {
192 if (length > 0) return this[0]; 164 if (length > 0) return this[0];
193 throw new StateError("No elements"); 165 throw new StateError("No elements");
194 } 166 }
195 167
196 E get last { 168 E get last {
197 if (length > 0) return this[length - 1]; 169 if (length > 0) return this[length - 1];
198 throw new StateError("No elements"); 170 throw new StateError("No elements");
199 } 171 }
200 172
201 E get single { 173 E get single {
202 if (length == 1) return this[0]; 174 if (length == 1) return this[0];
203 if (length == 0) throw new StateError("No elements"); 175 if (length == 0) throw new StateError("No elements");
204 throw new StateError("More than one element"); 176 throw new StateError("More than one element");
205 } 177 }
206 178
207 void removeRange(int start, int length) { 179 void removeRange(int start, int end) {
208 checkGrowable(this, 'removeRange'); 180 checkGrowable(this, 'removeRange');
209 if (length == 0) { 181 int receiverLength = this.length;
210 return; 182 if (start < 0 || start > receiverLength) {
183 throw new RangeError.range(start, 0, receiverLength);
211 } 184 }
212 checkNull(start); // TODO(ahe): This is not specified but co19 tests it. 185 if (end < start || end > receiverLength) {
213 checkNull(length); // TODO(ahe): This is not specified but co19 tests it. 186 throw new RangeError.range(end, start, receiverLength);
214 if (start is !int) throw new ArgumentError(start);
215 if (length is !int) throw new ArgumentError(length);
216 if (length < 0) throw new ArgumentError(length);
217 var receiverLength = this.length;
218 if (start < 0 || start >= receiverLength) {
219 throw new RangeError.value(start);
220 }
221 if (start + length > receiverLength) {
222 throw new RangeError.value(start + length);
223 } 187 }
224 Arrays.copy(this, 188 Arrays.copy(this,
225 start + length, 189 end,
226 this, 190 this,
227 start, 191 start,
228 receiverLength - length - start); 192 receiverLength - end);
229 this.length = receiverLength - length; 193 this.length = receiverLength - (end - start);
230 } 194 }
231 195
232 void setRange(int start, int end, Iterable<E> iterable, [int skipCount = 0]) { 196 void setRange(int start, int end, Iterable<E> iterable, [int skipCount = 0]) {
233 checkMutable(this, 'set range'); 197 checkMutable(this, 'set range');
234 IterableMixinWorkaround.setRangeList(this, start, end, iterable, skipCount); 198 IterableMixinWorkaround.setRangeList(this, start, end, iterable, skipCount);
235 } 199 }
236 200
237 bool any(bool f(E element)) => IterableMixinWorkaround.any(this, f); 201 bool any(bool f(E element)) => IterableMixinWorkaround.any(this, f);
238 202
239 bool every(bool f(E element)) => IterableMixinWorkaround.every(this, f); 203 bool every(bool f(E element)) => IterableMixinWorkaround.every(this, f);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 } 269 }
306 } 270 }
307 271
308 /** 272 /**
309 * Dummy subclasses that allow the backend to track more precise 273 * Dummy subclasses that allow the backend to track more precise
310 * information about arrays through their type. 274 * information about arrays through their type.
311 */ 275 */
312 class JSMutableArray extends JSArray {} 276 class JSMutableArray extends JSArray {}
313 class JSFixedArray extends JSMutableArray {} 277 class JSFixedArray extends JSMutableArray {}
314 class JSExtendableArray extends JSMutableArray {} 278 class JSExtendableArray extends JSMutableArray {}
OLDNEW
« no previous file with comments | « sdk/lib/_collection_dev/list.dart ('k') | sdk/lib/_internal/compiler/implementation/ssa/codegen.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698