| 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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 int slowLength() => 1 + tail.slowLength(); | 107 int slowLength() => 1 + tail.slowLength(); |
| 108 } | 108 } |
| 109 | 109 |
| 110 class LinkBuilderImplementation<T> implements LinkBuilder<T> { | 110 class LinkBuilderImplementation<T> implements LinkBuilder<T> { |
| 111 LinkEntry<T> head = null; | 111 LinkEntry<T> head = null; |
| 112 LinkEntry<T> lastLink = null; | 112 LinkEntry<T> lastLink = null; |
| 113 int length = 0; | 113 int length = 0; |
| 114 | 114 |
| 115 LinkBuilderImplementation(); | 115 LinkBuilderImplementation(); |
| 116 | 116 |
| 117 Link<T> toLink() { | 117 Link<T> toLink([Link<T> tail = const Link()]) { |
| 118 if (head == null) return const Link(); | 118 if (head == null) return tail; |
| 119 lastLink.tail = const Link(); | 119 lastLink.tail = tail; |
| 120 Link<T> link = head; | 120 Link<T> link = head; |
| 121 lastLink = null; | 121 lastLink = null; |
| 122 head = null; | 122 head = null; |
| 123 return link; | 123 return link; |
| 124 } | 124 } |
| 125 | 125 |
| 126 void addLast(T t) { | 126 void addLast(T t) { |
| 127 length++; | 127 length++; |
| 128 LinkEntry<T> entry = new LinkEntry<T>(t, null); | 128 LinkEntry<T> entry = new LinkEntry<T>(t, null); |
| 129 if (head == null) { | 129 if (head == null) { |
| 130 head = entry; | 130 head = entry; |
| 131 } else { | 131 } else { |
| 132 lastLink.tail = entry; | 132 lastLink.tail = entry; |
| 133 } | 133 } |
| 134 lastLink = entry; | 134 lastLink = entry; |
| 135 } | 135 } |
| 136 | 136 |
| 137 bool get isEmpty => length == 0; | 137 bool get isEmpty => length == 0; |
| 138 } | 138 } |
| OLD | NEW |