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

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

Issue 11956039: Revert "Create IterableMixinWorkaround and move most of the Collections methods there." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 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 | « samples/swarm/DataSource.dart ('k') | sdk/lib/collection/collections.dart » ('j') | no next file with comments »
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 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 16 matching lines...) Expand all
27 return JS('var', r'#.splice(#, 1)[0]', this, index); 27 return JS('var', r'#.splice(#, 1)[0]', this, index);
28 } 28 }
29 29
30 E removeLast() { 30 E removeLast() {
31 checkGrowable(this, 'removeLast'); 31 checkGrowable(this, 'removeLast');
32 if (length == 0) throw new RangeError.value(-1); 32 if (length == 0) throw new RangeError.value(-1);
33 return JS('var', r'#.pop()', this); 33 return JS('var', r'#.pop()', this);
34 } 34 }
35 35
36 Iterable<E> where(bool f(E element)) { 36 Iterable<E> where(bool f(E element)) {
37 return IterableMixinWorkaround.where(this, f); 37 return new WhereIterable<E>(this, f);
38 } 38 }
39 39
40 void addAll(Collection<E> collection) { 40 void addAll(Collection<E> collection) {
41 for (E e in collection) { 41 for (E e in collection) {
42 this.add(e); 42 this.add(e);
43 } 43 }
44 } 44 }
45 45
46 void addLast(E value) { 46 void addLast(E value) {
47 checkGrowable(this, 'addLast'); 47 checkGrowable(this, 'addLast');
48 JS('void', r'#.push(#)', this, value); 48 JS('void', r'#.push(#)', this, value);
49 } 49 }
50 50
51 void clear() { 51 void clear() {
52 length = 0; 52 length = 0;
53 } 53 }
54 54
55 void forEach(void f(E element)) { 55 void forEach(void f(E element)) {
56 return IterableMixinWorkaround.forEach(this, f); 56 return Collections.forEach(this, f);
57 } 57 }
58 58
59 List mappedBy(f(E element)) { 59 List mappedBy(f(E element)) {
60 return IterableMixinWorkaround.mappedBy(this, f); 60 return new MappedList(this, f);
61 } 61 }
62 62
63 String join([String separator]) { 63 String join([String separator]) {
64 if (separator == null) separator = ""; 64 if (separator == null) separator = "";
65 var list = new List(this.length); 65 var list = new List(this.length);
66 for (int i = 0; i < this.length; i++) { 66 for (int i = 0; i < this.length; i++) {
67 list[i] = "${this[i]}"; 67 list[i] = "${this[i]}";
68 } 68 }
69 return JS('String', "#.join(#)", list, separator); 69 return JS('String', "#.join(#)", list, separator);
70 } 70 }
71 71
72 List<E> take(int n) { 72 List<E> take(int n) {
73 return IterableMixinWorkaround.takeList(this, n); 73 return new ListView<E>(this, 0, n);
74 } 74 }
75 75
76 Iterable<E> takeWhile(bool test(E value)) { 76 Iterable<E> takeWhile(bool test(E value)) {
77 return IterableMixinWorkaround.takeWhile(this, test); 77 return new TakeWhileIterable<E>(this, test);
78 } 78 }
79 79
80 List<E> skip(int n) { 80 List<E> skip(int n) {
81 return IterableMixinWorkaround.skipList(this, n); 81 return new ListView<E>(this, n, null);
82 } 82 }
83 83
84 Iterable<E> skipWhile(bool test(E value)) { 84 Iterable<E> skipWhile(bool test(E value)) {
85 return IterableMixinWorkaround.skipWhile(this, test); 85 return new SkipWhileIterable<E>(this, test);
86 } 86 }
87 87
88 reduce(initialValue, combine(previousValue, E element)) { 88 reduce(initialValue, combine(previousValue, E element)) {
89 return IterableMixinWorkaround.reduce(this, initialValue, combine); 89 return Collections.reduce(this, initialValue, combine);
90 } 90 }
91 91
92 E firstMatching(bool test(E value), {E orElse()}) { 92 E firstMatching(bool test(E value), {E orElse()}) {
93 return IterableMixinWorkaround.firstMatching(this, test, orElse); 93 return Collections.firstMatching(this, test, orElse);
94 } 94 }
95 95
96 E lastMatching(bool test(E value), {E orElse()}) { 96 E lastMatching(bool test(E value), {E orElse()}) {
97 return IterableMixinWorkaround.lastMatchingInList(this, test, orElse); 97 return Collections.lastMatchingInList(this, test, orElse);
98 } 98 }
99 99
100 E singleMatching(bool test(E value)) { 100 E singleMatching(bool test(E value)) {
101 return IterableMixinWorkaround.singleMatching(this, test); 101 return Collections.singleMatching(this, test);
102 } 102 }
103 103
104 E elementAt(int index) { 104 E elementAt(int index) {
105 return this[index]; 105 return this[index];
106 } 106 }
107 107
108 List<E> getRange(int start, int length) { 108 List<E> getRange(int start, int length) {
109 // TODO(ngeoffray): Parameterize the return value. 109 // TODO(ngeoffray): Parameterize the return value.
110 if (0 == length) return []; 110 if (0 == length) return [];
111 checkNull(start); // TODO(ahe): This is not specified but co19 tests it. 111 checkNull(start); // TODO(ahe): This is not specified but co19 tests it.
(...skipping 23 matching lines...) Expand all
135 if (length > 0) return this[length - 1]; 135 if (length > 0) return this[length - 1];
136 throw new StateError("No elements"); 136 throw new StateError("No elements");
137 } 137 }
138 138
139 E get single { 139 E get single {
140 if (length == 1) return this[0]; 140 if (length == 1) return this[0];
141 if (length == 0) throw new StateError("No elements"); 141 if (length == 0) throw new StateError("No elements");
142 throw new StateError("More than one element"); 142 throw new StateError("More than one element");
143 } 143 }
144 144
145 E min([int compare(E a, E b)]) => IterableMixinWorkaround.min(this, compare); 145 E min([int compare(E a, E b)]) => Collections.min(this, compare);
146 146
147 E max([int compare(E a, E b)]) => IterableMixinWorkaround.max(this, compare); 147 E max([int compare(E a, E b)]) => Collections.max(this, compare);
148 148
149 void removeRange(int start, int length) { 149 void removeRange(int start, int length) {
150 checkGrowable(this, 'removeRange'); 150 checkGrowable(this, 'removeRange');
151 if (length == 0) { 151 if (length == 0) {
152 return; 152 return;
153 } 153 }
154 checkNull(start); // TODO(ahe): This is not specified but co19 tests it. 154 checkNull(start); // TODO(ahe): This is not specified but co19 tests it.
155 checkNull(length); // TODO(ahe): This is not specified but co19 tests it. 155 checkNull(length); // TODO(ahe): This is not specified but co19 tests it.
156 if (start is !int) throw new ArgumentError(start); 156 if (start is !int) throw new ArgumentError(start);
157 if (length is !int) throw new ArgumentError(length); 157 if (length is !int) throw new ArgumentError(length);
(...skipping 25 matching lines...) Expand all
183 if (startFrom is !int) throw new ArgumentError(startFrom); 183 if (startFrom is !int) throw new ArgumentError(startFrom);
184 if (length < 0) throw new ArgumentError(length); 184 if (length < 0) throw new ArgumentError(length);
185 if (start < 0) throw new RangeError.value(start); 185 if (start < 0) throw new RangeError.value(start);
186 if (start + length > this.length) { 186 if (start + length > this.length) {
187 throw new RangeError.value(start + length); 187 throw new RangeError.value(start + length);
188 } 188 }
189 189
190 Arrays.copy(from, startFrom, this, start, length); 190 Arrays.copy(from, startFrom, this, start, length);
191 } 191 }
192 192
193 bool any(bool f(E element)) => IterableMixinWorkaround.any(this, f); 193 bool any(bool f(E element)) => Collections.any(this, f);
194 194
195 bool every(bool f(E element)) => IterableMixinWorkaround.every(this, f); 195 bool every(bool f(E element)) => Collections.every(this, f);
196 196
197 void sort([int compare(E a, E b)]) { 197 void sort([int compare(E a, E b)]) {
198 checkMutable(this, 'sort'); 198 checkMutable(this, 'sort');
199 if (compare == null) compare = Comparable.compare; 199 if (compare == null) compare = Comparable.compare;
200 coreSort(this, compare); 200 coreSort(this, compare);
201 } 201 }
202 202
203 int indexOf(E element, [int start = 0]) { 203 int indexOf(E element, [int start = 0]) {
204 if (start is !int) throw new ArgumentError(start); 204 if (start is !int) throw new ArgumentError(start);
205 return Arrays.indexOf(this, element, start, length); 205 return Arrays.indexOf(this, element, start, length);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 if (nextPosition < length) { 273 if (nextPosition < length) {
274 _position = nextPosition; 274 _position = nextPosition;
275 _current = _list[nextPosition]; 275 _current = _list[nextPosition];
276 return true; 276 return true;
277 } 277 }
278 _position = length; 278 _position = length;
279 _current = null; 279 _current = null;
280 return false; 280 return false;
281 } 281 }
282 } 282 }
OLDNEW
« no previous file with comments | « samples/swarm/DataSource.dart ('k') | sdk/lib/collection/collections.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698