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

Side by Side Diff: packages/html/lib/src/list_proxy.dart

Issue 2990843002: Removed fixed dependencies (Closed)
Patch Set: Created 3 years, 4 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
« no previous file with comments | « packages/html/lib/src/encoding_parser.dart ('k') | packages/html/lib/src/query_selector.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 // TODO(jmesserly): remove this once we have a subclassable growable list 1 // TODO(jmesserly): remove this once we have a subclassable growable list
2 // in our libraries. 2 // in our libraries.
3 3
4 /// A [List] proxy that you can subclass. 4 /// A [List] proxy that you can subclass.
5 library list_proxy; 5 library list_proxy;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import 'dart:math' show Random; 8 import 'dart:math' show Random;
9 9
10 // TOOD(jmesserly): this needs to be removed, but fixing NodeList is tricky. 10 // TOOD(jmesserly): this needs to be removed, but fixing NodeList is tricky.
11 class ListProxy<E> extends IterableBase<E> implements List<E> { 11 class ListProxy<E> extends IterableBase<E> implements List<E> {
12 12
13 /// The inner [List<T>] with the actual storage. 13 /// The inner [List<T>] with the actual storage.
14 final List<E> _list; 14 final List<E> _list;
15 15
16 /// Creates a list proxy. 16 /// Creates a list proxy.
17 /// You can optionally specify the list to use for [storage] of the items, 17 /// You can optionally specify the list to use for [storage] of the items,
18 /// otherwise this will create a [List<E>]. 18 /// otherwise this will create a [List<E>].
19 ListProxy([List<E> storage]) : _list = storage != null ? storage : <E>[]; 19 ListProxy([List<E> storage]) : _list = storage != null ? storage : <E>[];
20 20
21 // TODO(jmesserly): This should be on List. 21 // TODO(jmesserly): This should be on List.
22 // See http://code.google.com/p/dart/issues/detail?id=947 22 // See http://code.google.com/p/dart/issues/detail?id=947
23 bool remove(E item) { 23 bool remove(Object item) {
24 int i = indexOf(item); 24 if (item is E) {
25 if (i == -1) return false; 25 int i = indexOf(item);
26 removeAt(i); 26 if (i == -1) return false;
27 return true; 27 removeAt(i);
28 return true;
29 }
30 return false;
28 } 31 }
29 32
30 void insert(int index, E item) => _list.insert(index, item); 33 void insert(int index, E item) => _list.insert(index, item);
31 34
32 // Override from Iterable to fix performance 35 // Override from Iterable to fix performance
33 // Length and last become O(1) instead of O(N) 36 // Length and last become O(1) instead of O(N)
34 // The others are just different constant factor. 37 // The others are just different constant factor.
35 int get length => _list.length; 38 int get length => _list.length;
36 E get last => _list.last; 39 E get last => _list.last;
37 E get first => _list.first; 40 E get first => _list.first;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 E removeAt(int index) => _list.removeAt(index); 77 E removeAt(int index) => _list.removeAt(index);
75 E removeLast() => _list.removeLast(); 78 E removeLast() => _list.removeLast();
76 79
77 void removeWhere(bool test(E element)) => _list.removeWhere(test); 80 void removeWhere(bool test(E element)) => _list.removeWhere(test);
78 void retainWhere(bool test(E element)) => _list.retainWhere(test); 81 void retainWhere(bool test(E element)) => _list.retainWhere(test);
79 82
80 List<E> sublist(int start, [int end]) => _list.sublist(start, end); 83 List<E> sublist(int start, [int end]) => _list.sublist(start, end);
81 84
82 List<E> getRange(int start, int end) => _list.getRange(start, end); 85 List<E> getRange(int start, int end) => _list.getRange(start, end);
83 86
84 void setRange(int start, int length, List<E> from, [int startFrom = 0]) { 87 void setRange(int start, int length, Iterable<E> from, [int startFrom = 0]) {
85 _list.setRange(start, length, from, startFrom); 88 _list.setRange(start, length, from, startFrom);
86 } 89 }
87 void removeRange(int start, int length) { 90 void removeRange(int start, int length) {
88 _list.removeRange(start, length); 91 _list.removeRange(start, length);
89 } 92 }
90 void insertAll(int index, Iterable<E> iterable) { 93 void insertAll(int index, Iterable<E> iterable) {
91 _list.insertAll(index, iterable); 94 _list.insertAll(index, iterable);
92 } 95 }
93 96
94 Iterable<E> get reversed => _list.reversed; 97 Iterable<E> get reversed => _list.reversed;
95 98
96 Map<int, E> asMap() => _list.asMap(); 99 Map<int, E> asMap() => _list.asMap();
97 100
98 void replaceRange(int start, int end, Iterable<E> newContents) => 101 void replaceRange(int start, int end, Iterable<E> newContents) =>
99 _list.replaceRange(start, end, newContents); 102 _list.replaceRange(start, end, newContents);
100 103
101 void setAll(int index, Iterable<E> iterable) => _list.setAll(index, iterable); 104 void setAll(int index, Iterable<E> iterable) => _list.setAll(index, iterable);
102 105
103 void fillRange(int start, int end, [E fillValue]) => 106 void fillRange(int start, int end, [E fillValue]) =>
104 _list.fillRange(start, end, fillValue); 107 _list.fillRange(start, end, fillValue);
105 } 108 }
OLDNEW
« no previous file with comments | « packages/html/lib/src/encoding_parser.dart ('k') | packages/html/lib/src/query_selector.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698