Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(433)

Unified Diff: sdk/lib/collection/hash_set.dart

Issue 13598015: Revert 20969: Reduce usage of IterableMixinWorkaround (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « samples/swarm/swarm_ui_lib/observable/observable.dart ('k') | sdk/lib/collection/linked_hash_set.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/collection/hash_set.dart
diff --git a/sdk/lib/collection/hash_set.dart b/sdk/lib/collection/hash_set.dart
index 04516fc02d7a759ebd3fca97ca8092b70c02cde2..977dcfff5bec0b6a5f12ae072933053af03be6c6 100644
--- a/sdk/lib/collection/hash_set.dart
+++ b/sdk/lib/collection/hash_set.dart
@@ -4,57 +4,7 @@
part of dart.collection;
-/** Common parts of [HashSet] and [LinkedHashSet] implementations. */
-abstract class _HashSetBase<E> extends Collection<E> implements Set<E> {
- // Set.
- bool isSubsetOf(Collection<E> other) {
- // Deprecated, and using old signature.
- Set otherSet;
- if (other is Set) {
- otherSet = other;
- } else {
- otherSet = other.toSet();
- }
- return otherSet.containsAll(this);
- }
-
- bool containsAll(Iterable<E> other) {
- for (E object in other) {
- if (!this.contains(object)) return false;
- }
- return true;
- }
-
- Set<E> intersection(Set<E> other) {
- Set<E> result = _newSet();
- if (other.length < this.length) {
- for (E element in other) {
- if (this.contains(element)) result.add(element);
- }
- } else {
- for (E element in this) {
- if (other.contains(element)) result.add(element);
- }
- }
- return result;
- }
-
- Set<E> union(Set<E> other) {
- return _newSet()..addAll(this)..addAll(other);
- }
-
- Set<E> difference(Set<E> other) {
- HashSet<E> result = _newSet();
- for (E element in this) {
- if (!other.contains(element)) result.add(element);
- }
- return result;
- }
-
- String toString() => Collections.collectionToString(this);
-}
-
-class HashSet<E> extends _HashSetBase<E> {
+class HashSet<E> extends Collection<E> implements Set<E> {
external HashSet();
factory HashSet.from(Iterable<E> iterable) {
@@ -80,13 +30,7 @@ class HashSet<E> extends _HashSetBase<E> {
external void removeAll(Iterable objectsToRemove);
void retainAll(Iterable objectsToRetain) {
- Set retainSet;
- if (objectsToRetain is Set) {
- retainSet = objectsToRetain;
- } else {
- retainSet = objectsToRetain.toSet();
- }
- retainWhere(retainSet.contains);
+ IterableMixinWorkaround.retainAll(this, objectsToRetain);
}
external void removeWhere(bool test(E element));
@@ -96,5 +40,33 @@ class HashSet<E> extends _HashSetBase<E> {
external void clear();
// Set.
- Set<E> _newSet() => new HashSet<E>();
+ bool isSubsetOf(Collection<E> other) {
+ // Deprecated, and using old signature.
+ Set otherSet;
+ if (other is Set) {
+ otherSet = other;
+ } else {
+ otherSet = other.toSet();
+ }
+ return IterableMixinWorkaround.setContainsAll(otherSet, this);
+ }
+
+ bool containsAll(Iterable<E> other) {
+ return IterableMixinWorkaround.setContainsAll(this, other);
+ }
+
+ Set<E> intersection(Set<E> other) {
+ return IterableMixinWorkaround.setIntersection(
+ this, other, new HashSet<E>());
+ }
+
+ Set<E> union(Set<E> other) {
+ return IterableMixinWorkaround.setUnion(this, other, new HashSet<E>());
+ }
+
+ Set<E> difference(Set<E> other) {
+ return IterableMixinWorkaround.setDifference(this, other, new HashSet<E>());
+ }
+
+ String toString() => Collections.collectionToString(this);
}
« no previous file with comments | « samples/swarm/swarm_ui_lib/observable/observable.dart ('k') | sdk/lib/collection/linked_hash_set.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698