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..a1d3ba5eb073aec95dab121d0ba3f854d7946c12 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 { |
@@ -521,17 +527,24 @@ class LinkedHashMap<K, V> { |
// Private factory constructor called by generated code for map literals. |
@NoInline() |
factory LinkedHashMap._literal(List keyValuePairs) { |
- return fillLiteralMap(keyValuePairs, new JsLinkedHashMap<K, V>()); |
+ Map map = JsLinkedHashMap.supportsEs6Maps |
Vyacheslav Egorov (Google)
2015/03/26 00:03:57
Can this just call some force-inline static method
Harry Terkelsen
2015/03/26 00:40:06
Won't that require generic methods?
floitsch
2015/03/26 00:53:24
:)
I wondered the same, and had already started. T
|
+ ? new Es6LinkedHashMap<K, V>() |
+ : new JsLinkedHashMap<K, V>(); |
+ return fillLiteralMap(keyValuePairs, map); |
} |
// Private factory constructor called by generated code for map literals. |
@NoThrows() @NoInline() |
factory LinkedHashMap._empty() { |
- return new JsLinkedHashMap<K, V>(); |
+ return JsLinkedHashMap.supportsEs6Maps |
+ ? new Es6LinkedHashMap<K, V>() |
+ : new JsLinkedHashMap<K, V>(); |
} |
} |
+// TODO(floitsch): use ES6 Maps when available. |
class _LinkedIdentityHashMap<K, V> extends JsLinkedHashMap<K, V> { |
+ |
Harry Terkelsen
2015/03/26 00:40:07
unnecessary blank line
floitsch
2015/03/26 00:53:24
Done.
|
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 +563,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); |
+ |
Harry Terkelsen
2015/03/26 00:40:06
unnecessary blank line
floitsch
2015/03/26 00:53:24
Done.
|
V operator[](Object key) { |
if (!_validKey(key)) return null; |
return super.internalGet(key); |