Chromium Code Reviews| Index: dart/frog/leg/lib/hash_map_set.dart |
| diff --git a/dart/frog/leg/lib/hash_map_set.dart b/dart/frog/leg/lib/hash_map_set.dart |
| index c538951fff31beb62674103b8c7517339c0c8ded..7605cb9a74fad45492abe1c30482ff6ecf456dca 100644 |
| --- a/dart/frog/leg/lib/hash_map_set.dart |
| +++ b/dart/frog/leg/lib/hash_map_set.dart |
| @@ -2,6 +2,8 @@ |
| // for details. All rights reserved. Use of this source code is governed by a |
| // BSD-style license that can be found in the LICENSE file. |
| +// TODO(ahe): Remove this file and use the shared one. |
| + |
| // Hash map implementation with open addressing and quadratic probing. |
| class HashMapImplementation<K extends Hashable, V> implements HashMap<K, V> { |
| @@ -156,14 +158,13 @@ class HashMapImplementation<K extends Hashable, V> implements HashMap<K, V> { |
| // [key] can be either of type [K] or [_DeletedKeySentinel]. |
| Object key = oldKeys[i]; |
| // If there is no key, we don't need to deal with the current slot. |
| - if (key === null || key === _DELETED_KEY) { |
| - continue; |
| + if (key !== null && key !== _DELETED_KEY) { |
| + V value = oldValues[i]; |
| + // Insert the {key, value} pair in their new slot. |
| + int newIndex = _probeForAdding(key); |
| + _keys[newIndex] = key; |
| + _values[newIndex] = value; |
| } |
| - V value = oldValues[i]; |
| - // Insert the {key, value} pair in their new slot. |
| - int newIndex = _probeForAdding(key); |
| - _keys[newIndex] = key; |
| - _values[newIndex] = value; |
| } |
| _numberOfDeleted = 0; |
| } |
| @@ -307,32 +308,36 @@ class HashSetImplementation<E extends Hashable> implements HashSet<E> { |
| } |
| void addAll(Collection<E> collection) { |
| + var self = this; |
|
ahe
2012/02/29 12:37:21
I should be able to remove all the "self" referenc
|
| collection.forEach(void _(E value) { |
| - add(value); |
| + self.add(value); |
| }); |
| } |
| Set<E> intersection(Collection<E> collection) { |
| + var self = this; |
| Set<E> result = new Set<E>(); |
| collection.forEach(void _(E value) { |
| - if (contains(value)) result.add(value); |
| + if (self.contains(value)) result.add(value); |
| }); |
| return result; |
| } |
| bool isSubsetOf(Collection<E> other) { |
| - return new Set<E>.from(other).containsAll(this); |
| + return new Set.from(other).containsAll(this); |
| } |
| void removeAll(Collection<E> collection) { |
| + var self = this; |
| collection.forEach(void _(E value) { |
| - remove(value); |
| + self.remove(value); |
| }); |
| } |
| bool containsAll(Collection<E> collection) { |
| + var self = this; |
| return collection.every(bool _(E value) { |
| - return contains(value); |
| + return self.contains(value); |
| }); |
| } |