Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 dart.collection; | 5 part of dart.collection; |
| 6 | 6 |
| 7 /** Common parts of [HashSet] and [LinkedHashSet] implementations. */ | 7 /** Common parts of [HashSet] and [LinkedHashSet] implementations. */ |
| 8 abstract class _HashSetBase<E> extends IterableBase<E> implements Set<E> { | 8 abstract class _HashSetBase<E> extends IterableBase<E> implements Set<E> { |
| 9 | 9 |
| 10 // Set. | 10 // Set. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 50 Set retainSet = _newSet(); | 50 Set retainSet = _newSet(); |
| 51 for (Object o in objectsToRetain) { | 51 for (Object o in objectsToRetain) { |
| 52 if (isValidKey(o)) { | 52 if (isValidKey(o)) { |
| 53 retainSet.add(o); | 53 retainSet.add(o); |
| 54 } | 54 } |
| 55 } | 55 } |
| 56 retainWhere(retainSet.contains); | 56 retainWhere(retainSet.contains); |
| 57 } | 57 } |
| 58 | 58 |
| 59 List<E> toList({bool growable: true}) { | 59 List<E> toList({bool growable: true}) { |
| 60 List<E> result = new List<E>()..length = this.length; | 60 List<E> result = growable ? (new List<E>()..length = this.length) |
|
floitsch
2013/10/10 13:04:53
do in a separate CL.
| |
| 61 : new List<E>(this.length); | |
| 61 int i = 0; | 62 int i = 0; |
| 62 for (E element in this) result[i++] = element; | 63 for (E element in this) result[i++] = element; |
| 63 return result; | 64 return result; |
| 64 } | 65 } |
| 65 | 66 |
| 66 Set<E> toSet() => _newSet()..addAll(this); | 67 Set<E> toSet() => _newSet()..addAll(this); |
| 67 | 68 |
| 68 // TODO(zarah) Remove this, and let it be inherited by IterableBase | 69 // TODO(zarah) Remove this, and let it be inherited by IterableBase |
| 69 String toString() => IterableMixinWorkaround.toStringIterable(this, '{', '}'); | 70 String toString() => IterableMixinWorkaround.toStringIterable(this, '{', '}'); |
| 70 } | 71 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 122 /** | 123 /** |
| 123 * Create a hash set containing the elements of [iterable]. | 124 * Create a hash set containing the elements of [iterable]. |
| 124 * | 125 * |
| 125 * Creates a hash set as by `new HashSet<E>()` and adds each element of | 126 * Creates a hash set as by `new HashSet<E>()` and adds each element of |
| 126 * `iterable` to this set in the order they are iterated. | 127 * `iterable` to this set in the order they are iterated. |
| 127 */ | 128 */ |
| 128 factory HashSet.from(Iterable<E> iterable) { | 129 factory HashSet.from(Iterable<E> iterable) { |
| 129 return new HashSet<E>()..addAll(iterable); | 130 return new HashSet<E>()..addAll(iterable); |
| 130 } | 131 } |
| 131 } | 132 } |
| OLD | NEW |