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

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

Issue 11783009: Big merge from experimental to bleeding edge. (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
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 part of org_dartlang_compiler_util; 5 part of org_dartlang_compiler_util;
6 6
7 class Link<T> implements Iterable<T> { 7 class Link<T> extends Iterable<T> {
8 T get head => null; 8 T get head => null;
9 Link<T> get tail => null; 9 Link<T> get tail => null;
10 10
11 factory Link.fromList(List<T> list) { 11 factory Link.fromList(List<T> list) {
12 switch (list.length) { 12 switch (list.length) {
13 case 0: 13 case 0:
14 return new Link<T>(); 14 return new Link<T>();
15 case 1: 15 case 1:
16 return new LinkEntry<T>(list[0]); 16 return new LinkEntry<T>(list[0]);
17 case 2: 17 case 2:
18 return new LinkEntry<T>(list[0], new LinkEntry<T>(list[1])); 18 return new LinkEntry<T>(list[0], new LinkEntry<T>(list[1]));
19 case 3: 19 case 3:
20 return new LinkEntry<T>( 20 return new LinkEntry<T>(
21 list[0], new LinkEntry<T>(list[1], new LinkEntry<T>(list[2]))); 21 list[0], new LinkEntry<T>(list[1], new LinkEntry<T>(list[2])));
22 } 22 }
23 Link link = new Link<T>(); 23 Link link = new Link<T>();
24 for (int i = list.length ; i > 0; i--) { 24 for (int i = list.length ; i > 0; i--) {
25 link = link.prepend(list[i - 1]); 25 link = link.prepend(list[i - 1]);
26 } 26 }
27 return link; 27 return link;
28 } 28 }
29 29
30 const Link(); 30 const Link();
31 31
32 Link<T> prepend(T element) { 32 Link<T> prepend(T element) {
33 return new LinkEntry<T>(element, this); 33 return new LinkEntry<T>(element, this);
34 } 34 }
35 35
36 Iterator<T> iterator() => new LinkIterator<T>(this); 36 Iterator<T> get iterator => new LinkIterator<T>(this);
37 37
38 void printOn(StringBuffer buffer, [separatedBy]) { 38 void printOn(StringBuffer buffer, [separatedBy]) {
39 } 39 }
40 40
41 List toList() => new List<T>(0); 41 List toList() => new List<T>.fixedLength(0);
42 42
43 bool get isEmpty => true; 43 bool get isEmpty => true;
44 44
45 Link<T> reverse() => this; 45 Link<T> reverse() => this;
46 46
47 Link<T> reversePrependAll(Link<T> from) { 47 Link<T> reversePrependAll(Link<T> from) {
48 if (from.isEmpty) return this; 48 if (from.isEmpty) return this;
49 return this.prepend(from.head).reversePrependAll(from.tail); 49 return this.prepend(from.head).reversePrependAll(from.tail);
50 } 50 }
51 51
52 void forEach(void f(T element)) {} 52 void forEach(void f(T element)) {}
53 53
54 bool operator ==(other) { 54 bool operator ==(other) {
55 if (other is !Link<T>) return false; 55 if (other is !Link<T>) return false;
56 return other.isEmpty; 56 return other.isEmpty;
57 } 57 }
58 58
59 String toString() => "[]"; 59 String toString() => "[]";
60 } 60 }
61 61
62 abstract class LinkBuilder<T> { 62 abstract class LinkBuilder<T> {
63 factory LinkBuilder() = LinkBuilderImplementation; 63 factory LinkBuilder() = LinkBuilderImplementation;
64 64
65 Link<T> toLink(); 65 Link<T> toLink();
66 void addLast(T t); 66 void addLast(T t);
67 67
68 final int length; 68 final int length;
69 final bool isEmpty; 69 final bool isEmpty;
70 } 70 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698