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

Unified Diff: sdk/lib/_internal/compiler/js_lib/collection_patch.dart

Issue 1032783003: dart2js: use Es6 maps when available. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Move code around Created 5 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
Index: sdk/lib/_internal/compiler/js_lib/collection_patch.dart
diff --git a/sdk/lib/_internal/compiler/js_lib/collection_patch.dart b/sdk/lib/_internal/compiler/js_lib/collection_patch.dart
index 67e54bc0978c6367684ee3b35025e006361add9f..509b83edd0cb82569cb54c94dea5f04db478de5e 100644
--- a/sdk/lib/_internal/compiler/js_lib/collection_patch.dart
+++ b/sdk/lib/_internal/compiler/js_lib/collection_patch.dart
@@ -5,7 +5,8 @@
// Patch file for dart:collection classes.
import 'dart:_foreign_helper' show JS;
import 'dart:_js_helper' show
- fillLiteralMap, InternalMap, NoInline, NoThrows, patch, JsLinkedHashMap,
+ fillLiteralMap, InternalMap, NoInline, NoThrows, patch,
+ JsLinkedHashMap, Es6LinkedHashMap,
LinkedHashMapCell, LinkedHashMapKeyIterable, LinkedHashMapKeyIterator;
@patch
@@ -386,6 +387,7 @@ class _CustomHashMap<K, V> extends _HashMap<K, V> {
final _Equality<K> _equals;
final _Hasher<K> _hashCode;
final _Predicate _validKey;
+
_CustomHashMap(this._equals, this._hashCode, bool validKey(potentialKey))
: _validKey = (validKey != null) ? validKey : ((v) => v is K);
@@ -492,7 +494,11 @@ class LinkedHashMap<K, V> {
if (isValidKey == null) {
if (hashCode == null) {
if (equals == null) {
- return new JsLinkedHashMap<K, V>();
+ if (JsLinkedHashMap.supportsEs6Maps) {
+ return new Es6LinkedHashMap<K, V>();
+ } else {
+ return new JsLinkedHashMap<K, V>();
+ }
}
hashCode = _defaultHashCode;
} else {
@@ -531,7 +537,9 @@ class LinkedHashMap<K, V> {
}
}
+// TODO(floitsch): use ES6 Maps when available.
class _LinkedIdentityHashMap<K, V> extends JsLinkedHashMap<K, V> {
+
int internalComputeHashCode(var key) {
// We force the hash codes to be unsigned 30-bit integers to avoid
// issues with problematic keys like '__proto__'. Another option
@@ -550,14 +558,17 @@ class _LinkedIdentityHashMap<K, V> extends JsLinkedHashMap<K, V> {
}
}
+// TODO(floitsch): use ES6 maps when available.
class _LinkedCustomHashMap<K, V> extends JsLinkedHashMap<K, V> {
final _Equality<K> _equals;
final _Hasher<K> _hashCode;
final _Predicate _validKey;
+
_LinkedCustomHashMap(this._equals, this._hashCode,
bool validKey(potentialKey))
: _validKey = (validKey != null) ? validKey : ((v) => v is K);
+
V operator[](Object key) {
if (!_validKey(key)) return null;
return super.internalGet(key);

Powered by Google App Engine
This is Rietveld 408576698