OLD | NEW |
---|---|
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 util_implementation; | 5 part of util_implementation; |
6 | 6 |
7 class LinkIterator<T> implements Iterator<T> { | 7 class LinkIterator<T> implements Iterator<T> { |
8 T _current; | 8 T _current; |
9 Link<T> _link; | 9 Link<T> _link; |
10 | 10 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
74 if (link.isEmpty) { | 74 if (link.isEmpty) { |
75 throw new RangeError('Index $n out of range'); | 75 throw new RangeError('Index $n out of range'); |
76 } | 76 } |
77 link = link.tail; | 77 link = link.tail; |
78 } | 78 } |
79 return link; | 79 return link; |
80 } | 80 } |
81 | 81 |
82 bool get isEmpty => false; | 82 bool get isEmpty => false; |
83 | 83 |
84 List<T> toList() { | 84 List<T> toList({ bool growable: false }) { |
floitsch
2013/02/26 13:54:19
=> new List<T>.from(this, growable: growable);
Lasse Reichstein Nielsen
2013/02/26 15:26:00
Done.
| |
85 List<T> list = new List<T>(); | 85 List<T> list = new List<T>(); |
86 for (Link<T> link = this; !link.isEmpty; link = link.tail) { | 86 for (Link<T> link = this; !link.isEmpty; link = link.tail) { |
87 list.addLast(link.head); | 87 list.addLast(link.head); |
88 } | 88 } |
89 if (!growable) { | |
90 list = new List<T>.from(list); | |
91 } | |
89 return list; | 92 return list; |
90 } | 93 } |
91 | 94 |
92 void forEach(void f(T element)) { | 95 void forEach(void f(T element)) { |
93 for (Link<T> link = this; !link.isEmpty; link = link.tail) { | 96 for (Link<T> link = this; !link.isEmpty; link = link.tail) { |
94 f(link.head); | 97 f(link.head); |
95 } | 98 } |
96 } | 99 } |
97 | 100 |
98 bool operator ==(other) { | 101 bool operator ==(other) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 if (head == null) { | 136 if (head == null) { |
134 head = entry; | 137 head = entry; |
135 } else { | 138 } else { |
136 lastLink.tail = entry; | 139 lastLink.tail = entry; |
137 } | 140 } |
138 lastLink = entry; | 141 lastLink = entry; |
139 } | 142 } |
140 | 143 |
141 bool get isEmpty => length == 0; | 144 bool get isEmpty => length == 0; |
142 } | 145 } |
OLD | NEW |