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

Unified Diff: runtime/lib/collection_patch.dart

Issue 12827018: Add a new implementation of HashMap that uses JS objects for its (multiple) hash tables. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove type. Created 7 years, 9 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 | « pkg/unittest/test/matchers_test.dart ('k') | runtime/lib/collection_sources.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/collection_patch.dart
diff --git a/sdk/lib/collection/hash_map.dart b/runtime/lib/collection_patch.dart
similarity index 68%
copy from sdk/lib/collection/hash_map.dart
copy to runtime/lib/collection_patch.dart
index d90b4b9f0646c5ebbb689695696bf87f07a94d51..a9b74b7b4dc33b13cd702f65bbf547b8171f66df 100644
--- a/sdk/lib/collection/hash_map.dart
+++ b/runtime/lib/collection_patch.dart
@@ -2,40 +2,19 @@
// 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.
-part of dart.collection;
+patch class HashMap<K, V> {
+ final _HashMapTable<K, V> _hashTable = new _HashMapTable<K, V>();
-class _HashMapTable<K, V> extends _HashTable<K> {
- static const int _INITIAL_CAPACITY = 8;
- static const int _VALUE_INDEX = 1;
-
- _HashMapTable() : super(_INITIAL_CAPACITY);
-
- int get _entrySize => 2;
-
- V _value(int offset) => _table[offset + _VALUE_INDEX];
- void _setValue(int offset, V value) { _table[offset + _VALUE_INDEX] = value; }
-
- _copyEntry(List fromTable, int fromOffset, int toOffset) {
- _table[toOffset + _VALUE_INDEX] = fromTable[fromOffset + _VALUE_INDEX];
- }
-}
-
-class HashMap<K, V> implements Map<K, V> {
- final _HashMapTable<K, V> _hashTable;
-
- HashMap() : _hashTable = new _HashMapTable<K, V>() {
+ /* patch */ HashMap() {
_hashTable._container = this;
}
- factory HashMap.from(Map<K, V> other) {
- return new HashMap<K, V>()..addAll(other);
- }
- bool containsKey(K key) {
+ /* patch */ bool containsKey(K key) {
return _hashTable._get(key) >= 0;
}
- bool containsValue(V value) {
+ /* patch */ bool containsValue(V value) {
List table = _hashTable._table;
int entrySize = _hashTable._entrySize;
for (int offset = 0; offset < table.length; offset += entrySize) {
@@ -47,7 +26,7 @@ class HashMap<K, V> implements Map<K, V> {
return false;
}
- void addAll(Map<K, V> other) {
+ /* patch */ void addAll(Map<K, V> other) {
other.forEach((K key, V value) {
int offset = _hashTable._put(key);
_hashTable._setValue(offset, value);
@@ -55,19 +34,19 @@ class HashMap<K, V> implements Map<K, V> {
});
}
- V operator [](K key) {
+ /* patch */ V operator [](K key) {
int offset = _hashTable._get(key);
if (offset >= 0) return _hashTable._value(offset);
return null;
}
- void operator []=(K key, V value) {
+ /* patch */ void operator []=(K key, V value) {
int offset = _hashTable._put(key);
_hashTable._setValue(offset, value);
_hashTable._checkCapacity();
}
- V putIfAbsent(K key, V ifAbsent()) {
+ /* patch */ V putIfAbsent(K key, V ifAbsent()) {
int offset = _hashTable._probeForAdd(_hashTable._hashCodeOf(key), key);
Object entry = _hashTable._table[offset];
if (!_hashTable._isFree(entry)) {
@@ -96,7 +75,7 @@ class HashMap<K, V> implements Map<K, V> {
return value;
}
- V remove(K key) {
+ /* patch */ V remove(K key) {
int offset = _hashTable._remove(key);
if (offset < 0) return null;
V oldValue = _hashTable._value(offset);
@@ -105,11 +84,11 @@ class HashMap<K, V> implements Map<K, V> {
return oldValue;
}
- void clear() {
+ /* patch */ void clear() {
_hashTable._clear();
}
- void forEach(void action (K key, V value)) {
+ /* patch */ void forEach(void action(K key, V value)) {
int modificationCount = _hashTable._modificationCount;
List table = _hashTable._table;
int entrySize = _hashTable._entrySize;
@@ -124,13 +103,11 @@ class HashMap<K, V> implements Map<K, V> {
}
}
- Iterable<K> get keys => new _HashTableKeyIterable<K>(_hashTable);
- Iterable<V> get values =>
+ /* patch */ Iterable<K> get keys => new _HashTableKeyIterable<K>(_hashTable);
+ /* patch */ Iterable<V> get values =>
new _HashTableValueIterable<V>(_hashTable, _HashMapTable._VALUE_INDEX);
- int get length => _hashTable._elementCount;
-
- bool get isEmpty => _hashTable._elementCount == 0;
+ /* patch */ int get length => _hashTable._elementCount;
- String toString() => Maps.mapToString(this);
+ /* patch */ bool get isEmpty => _hashTable._elementCount == 0;
}
« no previous file with comments | « pkg/unittest/test/matchers_test.dart ('k') | runtime/lib/collection_sources.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698