| 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 class LinkIterator<T> implements Iterator<T> { | 5 class LinkIterator<T> implements Iterator<T> { |
| 6 Link<T> current; | 6 Link<T> current; |
| 7 LinkIterator(Link<T> this.current); | 7 LinkIterator(Link<T> this.current); |
| 8 bool hasNext() => !current.isEmpty(); | 8 bool hasNext() => !current.isEmpty(); |
| 9 T next() { | 9 T next() { |
| 10 T result = current.head; | 10 T result = current.head; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 } | 34 } |
| 35 Link link = new Link<T>(list.last()); | 35 Link link = new Link<T>(list.last()); |
| 36 for (int i = list.length - 1; i > 0; i--) { | 36 for (int i = list.length - 1; i > 0; i--) { |
| 37 link = link.prepend(list[i - 1]); | 37 link = link.prepend(list[i - 1]); |
| 38 } | 38 } |
| 39 return link; | 39 return link; |
| 40 } | 40 } |
| 41 } | 41 } |
| 42 | 42 |
| 43 class LinkTail<T> implements EmptyLink<T> { | 43 class LinkTail<T> implements EmptyLink<T> { |
| 44 T get head() => null; | 44 T get head => null; |
| 45 Link<T> get tail() => null; | 45 Link<T> get tail => null; |
| 46 | 46 |
| 47 const LinkTail(); | 47 const LinkTail(); |
| 48 | 48 |
| 49 Link<T> prepend(T element) { | 49 Link<T> prepend(T element) { |
| 50 // TODO(ahe): Use new Link<T>, but this cost 8% performance on VM. | 50 // TODO(ahe): Use new Link<T>, but this cost 8% performance on VM. |
| 51 return new LinkEntry<T>(element, this); | 51 return new LinkEntry<T>(element, this); |
| 52 } | 52 } |
| 53 | 53 |
| 54 Iterator<T> iterator() => new LinkIterator<T>(this); | 54 Iterator<T> iterator() => new LinkIterator<T>(this); |
| 55 | 55 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 length++; | 156 length++; |
| 157 LinkEntry<T> entry = new LinkEntry<T>(t, null); | 157 LinkEntry<T> entry = new LinkEntry<T>(t, null); |
| 158 if (head === null) { | 158 if (head === null) { |
| 159 head = entry; | 159 head = entry; |
| 160 } else { | 160 } else { |
| 161 lastLink.tail = entry; | 161 lastLink.tail = entry; |
| 162 } | 162 } |
| 163 lastLink = entry; | 163 lastLink = entry; |
| 164 } | 164 } |
| 165 } | 165 } |
| OLD | NEW |