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

Side by Side Diff: compiler/lib/implementation/array.dart

Issue 8424012: Add optional arguments to our indexOf/lastIndexOf methods. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 9 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
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 ListFactory { 5 class ListFactory {
6 factory List<E>.from(Iterable<E> other) { 6 factory List<E>.from(Iterable<E> other) {
7 List<E> list = new List<E>(); 7 List<E> list = new List<E>();
8 for (final e in other) { 8 for (final e in other) {
9 list.add(e); 9 list.add(e);
10 } 10 }
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 140
141 List<T> getRange(int start, int length) { 141 List<T> getRange(int start, int length) {
142 if (length == 0) return []; 142 if (length == 0) return [];
143 Arrays.rangeCheck(this, start, length); 143 Arrays.rangeCheck(this, start, length);
144 List list = new List<T>(); 144 List list = new List<T>();
145 list.length = length; 145 list.length = length;
146 Arrays.copy(this, start, list, 0, length); 146 Arrays.copy(this, start, list, 0, length);
147 return list; 147 return list;
148 } 148 }
149 149
150 int indexOf(T element, int startIndex) { 150 int indexOf(T element, [int start = 0]) {
151 return Arrays.indexOf(this, element, startIndex, this.length); 151 return Arrays.indexOf(this, element, start, this.length);
152 } 152 }
153 153
154 int lastIndexOf(T element, int startIndex) { 154 int lastIndexOf(T element, [int start = null]) {
155 return Arrays.lastIndexOf(this, element, startIndex); 155 if (start === null) start = length - 1;
156 return Arrays.lastIndexOf(this, element, start);
156 } 157 }
157 158
158 void add(T element) { 159 void add(T element) {
159 if (_isFixed) { 160 if (_isFixed) {
160 throw const UnsupportedOperationException( 161 throw const UnsupportedOperationException(
161 "Cannot add to a non-extendable list"); 162 "Cannot add to a non-extendable list");
162 } else { 163 } else {
163 _add(element); 164 _add(element);
164 } 165 }
165 } 166 }
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 } 259 }
259 260
260 static List _newList(int len) native { 261 static List _newList(int len) native {
261 return new List(len); 262 return new List(len);
262 } 263 }
263 264
264 static void _throwIndexOutOfRangeException(int index) native { 265 static void _throwIndexOutOfRangeException(int index) native {
265 throw new IndexOutOfRangeException(index); 266 throw new IndexOutOfRangeException(index);
266 } 267 }
267 } 268 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698