| 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 18 matching lines...) Expand all Loading... |
| 29 | 29 |
| 30 LinkEntry(T this.head, [Link<T> tail]) | 30 LinkEntry(T this.head, [Link<T> tail]) |
| 31 : this.tail = ((tail == null) ? new Link<T>() : tail); | 31 : this.tail = ((tail == null) ? new Link<T>() : tail); |
| 32 | 32 |
| 33 Link<T> prepend(T element) { | 33 Link<T> prepend(T element) { |
| 34 // TODO(ahe): Use new Link<T>, but this cost 8% performance on VM. | 34 // TODO(ahe): Use new Link<T>, but this cost 8% performance on VM. |
| 35 return new LinkEntry<T>(element, this); | 35 return new LinkEntry<T>(element, this); |
| 36 } | 36 } |
| 37 | 37 |
| 38 void printOn(StringBuffer buffer, [separatedBy]) { | 38 void printOn(StringBuffer buffer, [separatedBy]) { |
| 39 buffer.add(head); | 39 buffer.write(head); |
| 40 if (separatedBy == null) separatedBy = ''; | 40 if (separatedBy == null) separatedBy = ''; |
| 41 for (Link link = tail; !link.isEmpty; link = link.tail) { | 41 for (Link link = tail; !link.isEmpty; link = link.tail) { |
| 42 buffer.add(separatedBy); | 42 buffer.write(separatedBy); |
| 43 buffer.add(link.head); | 43 buffer.write(link.head); |
| 44 } | 44 } |
| 45 } | 45 } |
| 46 | 46 |
| 47 String toString() { | 47 String toString() { |
| 48 StringBuffer buffer = new StringBuffer(); | 48 StringBuffer buffer = new StringBuffer(); |
| 49 buffer.add('[ '); | 49 buffer.write('[ '); |
| 50 printOn(buffer, ', '); | 50 printOn(buffer, ', '); |
| 51 buffer.add(' ]'); | 51 buffer.write(' ]'); |
| 52 return buffer.toString(); | 52 return buffer.toString(); |
| 53 } | 53 } |
| 54 | 54 |
| 55 Link<T> reverse() { | 55 Link<T> reverse() { |
| 56 Link<T> result = const Link(); | 56 Link<T> result = const Link(); |
| 57 for (Link<T> link = this; !link.isEmpty; link = link.tail) { | 57 for (Link<T> link = this; !link.isEmpty; link = link.tail) { |
| 58 result = result.prepend(link.head); | 58 result = result.prepend(link.head); |
| 59 } | 59 } |
| 60 return result; | 60 return result; |
| 61 } | 61 } |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 if (head == null) { | 133 if (head == null) { |
| 134 head = entry; | 134 head = entry; |
| 135 } else { | 135 } else { |
| 136 lastLink.tail = entry; | 136 lastLink.tail = entry; |
| 137 } | 137 } |
| 138 lastLink = entry; | 138 lastLink = entry; |
| 139 } | 139 } |
| 140 | 140 |
| 141 bool get isEmpty => length == 0; | 141 bool get isEmpty => length == 0; |
| 142 } | 142 } |
| OLD | NEW |