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

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

Issue 13685004: Reduce usage of ItearbleMixinWorkaround. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix bug in set-base 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 | « sdk/lib/collection/hash_set.dart ('k') | sdk/lib/collection/queue.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/collection/linked_hash_set.dart
diff --git a/sdk/lib/collection/linked_hash_set.dart b/sdk/lib/collection/linked_hash_set.dart
index 8a4d566130ce6b821fdda7af8dc53518ac83a215..48d48c8d2ca3d711e6dc6848be93a0991770948e 100644
--- a/sdk/lib/collection/linked_hash_set.dart
+++ b/sdk/lib/collection/linked_hash_set.dart
@@ -4,7 +4,7 @@
part of dart.collection;
-class LinkedHashSet<E> extends Collection<E> implements Set<E> {
+class LinkedHashSet<E> extends _HashSetBase<E> {
static const int _INITIAL_CAPACITY = 8;
_LinkedHashTable<E> _table;
@@ -19,6 +19,12 @@ class LinkedHashSet<E> extends Collection<E> implements Set<E> {
// Iterable.
Iterator<E> get iterator => new _LinkedHashTableKeyIterator<E>(_table);
+ int get length => _table._elementCount;
+
+ bool get isEmpty => _table._elementCount == 0;
+
+ bool contains(Object object) => _table._get(object) >= 0;
+
void forEach(void action(E element)) {
int offset = _table._next(_LinkedHashTable._HEAD_OFFSET);
int modificationCount = _table._modificationCount;
@@ -30,12 +36,6 @@ class LinkedHashSet<E> extends Collection<E> implements Set<E> {
}
}
- int get length => _table._elementCount;
-
- bool get isEmpty => _table._elementCount == 0;
-
- bool contains(Object object) => _table._get(object) >= 0;
-
E get first {
int firstOffset = _table._next(_LinkedHashTable._HEAD_OFFSET);
if (firstOffset == _LinkedHashTable._HEAD_OFFSET) {
@@ -65,38 +65,6 @@ class LinkedHashSet<E> extends Collection<E> implements Set<E> {
}
// Collection.
- void add(E element) {
- _table._put(element);
- _table._checkCapacity();
- }
-
- void addAll(Iterable<E> objects) {
- for (E object in objects) {
- _table._put(object);
- _table._checkCapacity();
- }
- }
-
- bool remove(Object object) {
- int offset = _table._remove(object);
- if (offset >= 0) {
- _table._checkCapacity();
- return true;
- }
- return false;
- }
-
- void removeAll(Iterable objectsToRemove) {
- for (Object object in objectsToRemove) {
- _table._remove(object);
- _table._checkCapacity();
- }
- }
-
- void retainAll(Iterable objectsToRemove) {
- IterableMixinWorkaround.retainAll(this, objectsToRemove);
- }
-
void _filterWhere(bool test(E element), bool removeMatching) {
int entrySize = _table._entrySize;
int length = _table._table.length;
@@ -115,48 +83,46 @@ class LinkedHashSet<E> extends Collection<E> implements Set<E> {
_table._checkCapacity();
}
- void removeWhere(bool test(E element)) {
- _filterWhere(test, true);
+ void add(E element) {
+ _table._put(element);
+ _table._checkCapacity();
}
- void retainWhere(bool test(E element)) {
- _filterWhere(test, false);
+ bool remove(Object object) {
+ int offset = _table._remove(object);
+ if (offset >= 0) {
+ _table._checkCapacity();
+ return true;
+ }
+ return false;
}
- void clear() {
- _table._clear();
+ void removeAll(Iterable objectsToRemove) {
+ for (Object object in objectsToRemove) {
+ if (_table.remove(object) >= 0) {
+ _table._checkCapacity();
+ }
+ }
}
- // Set.
- bool isSubsetOf(Collection<E> other) {
- // Deprecated, and using old signature.
- Set otherSet;
- if (other is Set) {
- otherSet = other;
+ void retainAll(Iterable objectsToRetain) {
+ Set retainSet;
+ if (objectsToRetain is Set) {
+ retainSet = objectsToRetain;
} else {
- otherSet = other.toSet();
+ retainSet = objectsToRetain.toSet();
}
- return IterableMixinWorkaround.setContainsAll(otherSet, this);
+ _filterWhere(retainSet.contains, false);
}
- bool containsAll(Iterable<E> other) {
- return IterableMixinWorkaround.setContainsAll(this, other);
- }
-
- Set<E> intersection(Set<E> other) {
- return IterableMixinWorkaround.setIntersection(
- this, other, new LinkedHashSet<E>());
- }
-
- Set<E> union(Set<E> other) {
- return IterableMixinWorkaround.setUnion(
- this, other, new LinkedHashSet<E>());
+ void removeWhere(bool test(E element)) {
+ _filterWhere(test, true);
}
- Set<E> difference(Set<E> other) {
- return IterableMixinWorkaround.setDifference(
- this, other, new LinkedHashSet<E>());
+ retianWhere(bool test(E element)) {
+ _filterWhere(test, false);
}
- String toString() => Collections.collectionToString(this);
+ // Set
+ Set<E> _newSet() => new LinkedHashSet<E>();
}
« no previous file with comments | « sdk/lib/collection/hash_set.dart ('k') | sdk/lib/collection/queue.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698