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

Unified Diff: sdk/lib/html/dart2js/html_dart2js.dart

Issue 11412086: Make 'where' lazy. (Closed) Base URL: https://dart.googlecode.com/svn/experimental/lib_v2/dart
Patch Set: FilteredIterable/Iterator -> WhereIterable/Iterator. Created 8 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 side-by-side diff with in-line comments
Download patch
Index: sdk/lib/html/dart2js/html_dart2js.dart
diff --git a/sdk/lib/html/dart2js/html_dart2js.dart b/sdk/lib/html/dart2js/html_dart2js.dart
index b6b08ca5d4992d8a9835b319c787eb7ee1ea89d3..3e7f49b73e90aae8b490509bb1bf5b26bae90ee4 100644
--- a/sdk/lib/html/dart2js/html_dart2js.dart
+++ b/sdk/lib/html/dart2js/html_dart2js.dart
@@ -5338,8 +5338,7 @@ class DOMMimeTypeArray implements JavaScriptIndexingBehavior, List<DOMMimeType>
Iterable mappedBy(f(DOMMimeType element)) => new MappedIterable(this, f);
- Collection<DOMMimeType> where(bool f(DOMMimeType element)) =>
- _Collections.where(this, <DOMMimeType>[], f);
+ Iterable<DOMMimeType> where(bool f(DOMMimeType element)) => new FilteredIterable<DOMMimeType>(this, f);
bool every(bool f(DOMMimeType element)) => _Collections.every(this, f);
@@ -5477,8 +5476,7 @@ class DOMPluginArray implements JavaScriptIndexingBehavior, List<DOMPlugin> nati
Iterable mappedBy(f(DOMPlugin element)) => new MappedIterable(this, f);
- Collection<DOMPlugin> where(bool f(DOMPlugin element)) =>
- _Collections.where(this, <DOMPlugin>[], f);
+ Iterable<DOMPlugin> where(bool f(DOMPlugin element)) => new FilteredIterable<DOMPlugin>(this, f);
bool every(bool f(DOMPlugin element)) => _Collections.every(this, f);
@@ -6738,15 +6736,8 @@ class _ChildrenElementList implements List {
}
}
- List<Element> where(bool f(Element element)) {
- final output = [];
- forEach((Element element) {
- if (f(element)) {
- output.add(element);
- }
- });
- return new _FrozenElementList._wrap(output);
- }
+ Iterable<Element> where(bool f(Element element))
+ => new FilteredIterable<Element>(this, f);
bool every(bool f(Element element)) {
for (Element element in this) {
@@ -6879,13 +6870,8 @@ class _FrozenElementList implements List {
Iterable mappedBy(f(Element element)) => new MappedIterable(this, f);
- List<Element> where(bool f(Element element)) {
- final out = [];
- for (Element el in this) {
- if (f(el)) out.add(el);
- }
- return out;
- }
+ Iterable<Element> where(bool f(Element element))
+ => new FilteredIterable<Element>(this, f);
bool every(bool f(Element element)) {
for(Element element in this) {
@@ -8618,8 +8604,7 @@ class Float32Array extends ArrayBufferView implements JavaScriptIndexingBehavior
Iterable mappedBy(f(num element)) => new MappedIterable(this, f);
- Collection<num> where(bool f(num element)) =>
- _Collections.where(this, <num>[], f);
+ Iterable<num> where(bool f(num element)) => new FilteredIterable<num>(this, f);
bool every(bool f(num element)) => _Collections.every(this, f);
@@ -8727,8 +8712,7 @@ class Float64Array extends ArrayBufferView implements JavaScriptIndexingBehavior
Iterable mappedBy(f(num element)) => new MappedIterable(this, f);
- Collection<num> where(bool f(num element)) =>
- _Collections.where(this, <num>[], f);
+ Iterable<num> where(bool f(num element)) => new FilteredIterable<num>(this, f);
bool every(bool f(num element)) => _Collections.every(this, f);
@@ -9093,8 +9077,7 @@ class HTMLAllCollection implements JavaScriptIndexingBehavior, List<Node> native
Iterable mappedBy(f(Node element)) => new MappedIterable(this, f);
- Collection<Node> where(bool f(Node element)) =>
- _Collections.where(this, <Node>[], f);
+ Iterable<Node> where(bool f(Node element)) => new FilteredIterable<Node>(this, f);
bool every(bool f(Node element)) => _Collections.every(this, f);
@@ -9196,8 +9179,7 @@ class HTMLCollection implements JavaScriptIndexingBehavior, List<Node> native "*
Iterable mappedBy(f(Node element)) => new MappedIterable(this, f);
- Collection<Node> where(bool f(Node element)) =>
- _Collections.where(this, <Node>[], f);
+ Iterable<Node> where(bool f(Node element)) => new FilteredIterable<Node>(this, f);
bool every(bool f(Node element)) => _Collections.every(this, f);
@@ -10764,8 +10746,7 @@ class Int16Array extends ArrayBufferView implements JavaScriptIndexingBehavior,
Iterable mappedBy(f(int element)) => new MappedIterable(this, f);
- Collection<int> where(bool f(int element)) =>
- _Collections.where(this, <int>[], f);
+ Iterable<int> where(bool f(int element)) => new FilteredIterable<int>(this, f);
bool every(bool f(int element)) => _Collections.every(this, f);
@@ -10873,8 +10854,7 @@ class Int32Array extends ArrayBufferView implements JavaScriptIndexingBehavior,
Iterable mappedBy(f(int element)) => new MappedIterable(this, f);
- Collection<int> where(bool f(int element)) =>
- _Collections.where(this, <int>[], f);
+ Iterable<int> where(bool f(int element)) => new FilteredIterable<int>(this, f);
bool every(bool f(int element)) => _Collections.every(this, f);
@@ -10982,8 +10962,7 @@ class Int8Array extends ArrayBufferView implements JavaScriptIndexingBehavior, L
Iterable mappedBy(f(int element)) => new MappedIterable(this, f);
- Collection<int> where(bool f(int element)) =>
- _Collections.where(this, <int>[], f);
+ Iterable<int> where(bool f(int element)) => new FilteredIterable<int>(this, f);
bool every(bool f(int element)) => _Collections.every(this, f);
@@ -13132,8 +13111,7 @@ class NamedNodeMap implements JavaScriptIndexingBehavior, List<Node> native "*Na
Iterable mappedBy(f(Node element)) => new MappedIterable(this, f);
- Collection<Node> where(bool f(Node element)) =>
- _Collections.where(this, <Node>[], f);
+ Iterable<Node> where(bool f(Node element)) => new FilteredIterable<Node>(this, f);
bool every(bool f(Node element)) => _Collections.every(this, f);
@@ -13367,8 +13345,8 @@ class _ChildNodeListLazy implements List {
Iterable mappedBy(f(Node element)) => new MappedIterable(this, f);
- Collection<Node> where(bool f(Node element)) =>
- new _NodeListWrapper(_Collections.where(this, <Node>[], f));
+ Iterable<Node> where(bool f(Node element)) =>
+ new FilteredIterable<Node>(this, f);
bool every(bool f(Node element)) => _Collections.every(this, f);
@@ -13658,7 +13636,7 @@ class _ListWrapper<E> implements List<E> {
Iterable mappedBy(f(E element)) => new MappedIterable(this, f);
- List<E> where(bool f(E element)) => _list.where(f);
+ Iterable<E> where(bool f(E element)) => _list.where(f);
bool every(bool f(E element)) => _list.every(f);
@@ -13715,8 +13693,7 @@ class _ListWrapper<E> implements List<E> {
class _NodeListWrapper extends _ListWrapper<Node> implements List {
_NodeListWrapper(List list) : super(list);
- List<Node> where(bool f(Node element)) =>
- new _NodeListWrapper(_list.where(f));
+ Iterable<Node> where(bool f(Node element)) => new FilteredIterable(this, f);
List<Node> getRange(int start, int rangeLength) =>
new _NodeListWrapper(_list.getRange(start, rangeLength));
@@ -13775,8 +13752,7 @@ class NodeList implements JavaScriptIndexingBehavior, List<Node> native "*NodeLi
Iterable mappedBy(f(Node element)) => new MappedIterable(this, f);
- Collection<Node> where(bool f(Node element)) =>
- new _NodeListWrapper(_Collections.where(this, <Node>[], f));
+ Iterable<Node> where(bool f(Node element)) => new FilteredIterable(this, f);
bool every(bool f(Node element)) => _Collections.every(this, f);
@@ -15448,8 +15424,7 @@ class SQLResultSetRowList implements JavaScriptIndexingBehavior, List<Map> nativ
Iterable mappedBy(f(Map element)) => new MappedIterable(this, f);
- Collection<Map> where(bool f(Map element)) =>
- _Collections.where(this, <Map>[], f);
+ Iterable<Map> where(bool f(Map element)) => new FilteredIterable<Map>(this, f);
bool every(bool f(Map element)) => _Collections.every(this, f);
@@ -15773,13 +15748,13 @@ class SelectElement extends Element implements Element native "*HTMLSelectElemen
// Override default options, since IE returns SelectElement itself and it
// does not operate as a List.
List<OptionElement> get options {
- return this.elements.where((e) => e is OptionElement);
+ return this.elements.where((e) => e is OptionElement).toList();
}
List<OptionElement> get selectedOptions {
// IE does not change the selected flag for single-selection items.
if (this.multiple) {
- return this.options.where((o) => o.selected);
+ return this.options.where((o) => o.selected).toList();
} else {
return [this.options[this.selectedIndex]];
}
@@ -15962,8 +15937,7 @@ class SourceBufferList extends EventTarget implements JavaScriptIndexingBehavior
Iterable mappedBy(f(SourceBuffer element)) => new MappedIterable(this, f);
- Collection<SourceBuffer> where(bool f(SourceBuffer element)) =>
- _Collections.where(this, <SourceBuffer>[], f);
+ Iterable<SourceBuffer> where(bool f(SourceBuffer element)) => new FilteredIterable<SourceBuffer>(this, f);
bool every(bool f(SourceBuffer element)) => _Collections.every(this, f);
@@ -16115,8 +16089,7 @@ class SpeechGrammarList implements JavaScriptIndexingBehavior, List<SpeechGramma
Iterable mappedBy(f(SpeechGrammar element)) => new MappedIterable(this, f);
- Collection<SpeechGrammar> where(bool f(SpeechGrammar element)) =>
- _Collections.where(this, <SpeechGrammar>[], f);
+ Iterable<SpeechGrammar> where(bool f(SpeechGrammar element)) => new FilteredIterable<SpeechGrammar>(this, f);
bool every(bool f(SpeechGrammar element)) => _Collections.every(this, f);
@@ -17134,8 +17107,7 @@ class TextTrackCueList implements List<TextTrackCue>, JavaScriptIndexingBehavior
Iterable mappedBy(f(TextTrackCue element)) => new MappedIterable(this, f);
- Collection<TextTrackCue> where(bool f(TextTrackCue element)) =>
- _Collections.where(this, <TextTrackCue>[], f);
+ Iterable<TextTrackCue> where(bool f(TextTrackCue element)) => new FilteredIterable<TextTrackCue>(this, f);
bool every(bool f(TextTrackCue element)) => _Collections.every(this, f);
@@ -17240,8 +17212,7 @@ class TextTrackList extends EventTarget implements JavaScriptIndexingBehavior, L
Iterable mappedBy(f(TextTrack element)) => new MappedIterable(this, f);
- Collection<TextTrack> where(bool f(TextTrack element)) =>
- _Collections.where(this, <TextTrack>[], f);
+ Iterable<TextTrack> where(bool f(TextTrack element)) => new FilteredIterable<TextTrack>(this, f);
bool every(bool f(TextTrack element)) => _Collections.every(this, f);
@@ -17464,8 +17435,7 @@ class TouchList implements JavaScriptIndexingBehavior, List<Touch> native "*Touc
Iterable mappedBy(f(Touch element)) => new MappedIterable(this, f);
- Collection<Touch> where(bool f(Touch element)) =>
- _Collections.where(this, <Touch>[], f);
+ Iterable<Touch> where(bool f(Touch element)) => new FilteredIterable<Touch>(this, f);
bool every(bool f(Touch element)) => _Collections.every(this, f);
@@ -17738,8 +17708,7 @@ class Uint16Array extends ArrayBufferView implements JavaScriptIndexingBehavior,
Iterable mappedBy(f(int element)) => new MappedIterable(this, f);
- Collection<int> where(bool f(int element)) =>
- _Collections.where(this, <int>[], f);
+ Iterable<int> where(bool f(int element)) => new FilteredIterable<int>(this, f);
bool every(bool f(int element)) => _Collections.every(this, f);
@@ -17847,8 +17816,7 @@ class Uint32Array extends ArrayBufferView implements JavaScriptIndexingBehavior,
Iterable mappedBy(f(int element)) => new MappedIterable(this, f);
- Collection<int> where(bool f(int element)) =>
- _Collections.where(this, <int>[], f);
+ Iterable<int> where(bool f(int element)) => new FilteredIterable<int>(this, f);
bool every(bool f(int element)) => _Collections.every(this, f);
@@ -17956,8 +17924,7 @@ class Uint8Array extends ArrayBufferView implements JavaScriptIndexingBehavior,
Iterable mappedBy(f(int element)) => new MappedIterable(this, f);
- Collection<int> where(bool f(int element)) =>
- _Collections.where(this, <int>[], f);
+ Iterable<int> where(bool f(int element)) => new FilteredIterable<int>(this, f);
bool every(bool f(int element)) => _Collections.every(this, f);
@@ -20142,8 +20109,7 @@ class _CSSRuleList implements JavaScriptIndexingBehavior, List<CSSRule> native "
Iterable mappedBy(f(CSSRule element)) => new MappedIterable(this, f);
- Collection<CSSRule> where(bool f(CSSRule element)) =>
- _Collections.where(this, <CSSRule>[], f);
+ Iterable<CSSRule> where(bool f(CSSRule element)) => new FilteredIterable<CSSRule>(this, f);
bool every(bool f(CSSRule element)) => _Collections.every(this, f);
@@ -20239,8 +20205,7 @@ class _CSSValueList extends CSSValue implements List<CSSValue>, JavaScriptIndexi
Iterable mappedBy(f(CSSValue element)) => new MappedIterable(this, f);
- Collection<CSSValue> where(bool f(CSSValue element)) =>
- _Collections.where(this, <CSSValue>[], f);
+ Iterable<CSSValue> where(bool f(CSSValue element)) => new FilteredIterable<CSSValue>(this, f);
bool every(bool f(CSSValue element)) => _Collections.every(this, f);
@@ -20336,8 +20301,7 @@ class _ClientRectList implements JavaScriptIndexingBehavior, List<ClientRect> na
Iterable mappedBy(f(ClientRect element)) => new MappedIterable(this, f);
- Collection<ClientRect> where(bool f(ClientRect element)) =>
- _Collections.where(this, <ClientRect>[], f);
+ Iterable<ClientRect> where(bool f(ClientRect element)) => new FilteredIterable<ClientRect>(this, f);
bool every(bool f(ClientRect element)) => _Collections.every(this, f);
@@ -20442,8 +20406,7 @@ class _DOMStringList implements JavaScriptIndexingBehavior, List<String> native
Iterable mappedBy(f(String element)) => new MappedIterable(this, f);
- Collection<String> where(bool f(String element)) =>
- _Collections.where(this, <String>[], f);
+ Iterable<String> where(bool f(String element)) => new FilteredIterable<String>(this, f);
bool every(bool f(String element)) => _Collections.every(this, f);
@@ -20864,8 +20827,7 @@ class _EntryArray implements JavaScriptIndexingBehavior, List<Entry> native "*En
Iterable mappedBy(f(Entry element)) => new MappedIterable(this, f);
- Collection<Entry> where(bool f(Entry element)) =>
- _Collections.where(this, <Entry>[], f);
+ Iterable<Entry> where(bool f(Entry element)) => new FilteredIterable<Entry>(this, f);
bool every(bool f(Entry element)) => _Collections.every(this, f);
@@ -20961,8 +20923,7 @@ class _EntryArraySync implements JavaScriptIndexingBehavior, List<EntrySync> nat
Iterable mappedBy(f(EntrySync element)) => new MappedIterable(this, f);
- Collection<EntrySync> where(bool f(EntrySync element)) =>
- _Collections.where(this, <EntrySync>[], f);
+ Iterable<EntrySync> where(bool f(EntrySync element)) => new FilteredIterable<EntrySync>(this, f);
bool every(bool f(EntrySync element)) => _Collections.every(this, f);
@@ -21067,8 +21028,7 @@ class _FileList implements JavaScriptIndexingBehavior, List<File> native "*FileL
Iterable mappedBy(f(File element)) => new MappedIterable(this, f);
- Collection<File> where(bool f(File element)) =>
- _Collections.where(this, <File>[], f);
+ Iterable<File> where(bool f(File element)) => new FilteredIterable<File>(this, f);
bool every(bool f(File element)) => _Collections.every(this, f);
@@ -21193,8 +21153,7 @@ class _GamepadList implements JavaScriptIndexingBehavior, List<Gamepad> native "
Iterable mappedBy(f(Gamepad element)) => new MappedIterable(this, f);
- Collection<Gamepad> where(bool f(Gamepad element)) =>
- _Collections.where(this, <Gamepad>[], f);
+ Iterable<Gamepad> where(bool f(Gamepad element)) => new FilteredIterable<Gamepad>(this, f);
bool every(bool f(Gamepad element)) => _Collections.every(this, f);
@@ -21343,8 +21302,7 @@ class _MediaStreamList implements JavaScriptIndexingBehavior, List<MediaStream>
Iterable mappedBy(f(MediaStream element)) => new MappedIterable(this, f);
- Collection<MediaStream> where(bool f(MediaStream element)) =>
- _Collections.where(this, <MediaStream>[], f);
+ Iterable<MediaStream> where(bool f(MediaStream element)) => new FilteredIterable<MediaStream>(this, f);
bool every(bool f(MediaStream element)) => _Collections.every(this, f);
@@ -21603,8 +21561,7 @@ class _SpeechInputResultList implements JavaScriptIndexingBehavior, List<SpeechI
Iterable mappedBy(f(SpeechInputResult element)) => new MappedIterable(this, f);
- Collection<SpeechInputResult> where(bool f(SpeechInputResult element)) =>
- _Collections.where(this, <SpeechInputResult>[], f);
+ Iterable<SpeechInputResult> where(bool f(SpeechInputResult element)) => new FilteredIterable<SpeechInputResult>(this, f);
bool every(bool f(SpeechInputResult element)) => _Collections.every(this, f);
@@ -21709,8 +21666,7 @@ class _SpeechRecognitionResultList implements JavaScriptIndexingBehavior, List<S
Iterable mappedBy(f(SpeechRecognitionResult element)) => new MappedIterable(this, f);
- Collection<SpeechRecognitionResult> where(bool f(SpeechRecognitionResult element)) =>
- _Collections.where(this, <SpeechRecognitionResult>[], f);
+ Iterable<SpeechRecognitionResult> where(bool f(SpeechRecognitionResult element)) => new FilteredIterable<SpeechRecognitionResult>(this, f);
bool every(bool f(SpeechRecognitionResult element)) => _Collections.every(this, f);
@@ -21806,8 +21762,7 @@ class _StyleSheetList implements JavaScriptIndexingBehavior, List<StyleSheet> na
Iterable mappedBy(f(StyleSheet element)) => new MappedIterable(this, f);
- Collection<StyleSheet> where(bool f(StyleSheet element)) =>
- _Collections.where(this, <StyleSheet>[], f);
+ Iterable<StyleSheet> where(bool f(StyleSheet element)) => new FilteredIterable<StyleSheet>(this, f);
bool every(bool f(StyleSheet element)) => _Collections.every(this, f);
@@ -21927,8 +21882,7 @@ class _WebKitAnimationList implements JavaScriptIndexingBehavior, List<Animation
Iterable mappedBy(f(Animation element)) => new MappedIterable(this, f);
- Collection<Animation> where(bool f(Animation element)) =>
- _Collections.where(this, <Animation>[], f);
+ Iterable<Animation> where(bool f(Animation element)) => new FilteredIterable<Animation>(this, f);
bool every(bool f(Animation element)) => _Collections.every(this, f);
@@ -22087,7 +22041,7 @@ abstract class CssClassSet implements Set<String> {
Iterable mappedBy(f(String element)) => readClasses().mappedBy(f);
- Collection<String> where(bool f(String element)) => readClasses().where(f);
+ Iterable<String> where(bool f(String element)) => readClasses().where(f);
bool every(bool f(String element)) => readClasses().every(f);
@@ -22291,7 +22245,7 @@ class FilteredElementList implements List {
}
Iterable mappedBy(f(Element element)) => _filtered.mappedBy(f);
- Collection<Element> where(bool f(Element element)) => _filtered.where(f);
+ Iterable<Element> where(bool f(Element element)) => _filtered.where(f);
bool every(bool f(Element element)) => _filtered.every(f);
bool some(bool f(Element element)) => _filtered.some(f);
bool get isEmpty => _filtered.isEmpty;
@@ -23125,10 +23079,6 @@ class _Collections {
}
}
- static Iterable mappedBy(Iterable<Object> source, f(o)) {
- return new MappedIterable(source, f);
- }
-
static bool some(Iterable<Object> iterable, bool f(Object o)) {
for (final e in iterable) {
if (f(e)) return true;
@@ -23143,15 +23093,6 @@ class _Collections {
return true;
}
- static List where(Iterable<Object> source,
- List<Object> destination,
- bool f(o)) {
- for (final e in source) {
- if (f(e)) destination.add(e);
- }
- return destination;
- }
-
static bool isEmpty(Iterable<Object> iterable) {
return !iterable.iterator.moveNext();
}

Powered by Google App Engine
This is Rietveld 408576698