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

Unified Diff: sdk/lib/_internal/compiler/js_lib/linked_hash_map.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
« no previous file with comments | « sdk/lib/_internal/compiler/js_lib/collection_patch.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/compiler/js_lib/linked_hash_map.dart
diff --git a/sdk/lib/_internal/compiler/js_lib/linked_hash_map.dart b/sdk/lib/_internal/compiler/js_lib/linked_hash_map.dart
index f543e74d706e83feea70ade74a4eddb72705fde0..21a7c13b840953b759c6ac308ed8b6e922ef994f 100644
--- a/sdk/lib/_internal/compiler/js_lib/linked_hash_map.dart
+++ b/sdk/lib/_internal/compiler/js_lib/linked_hash_map.dart
@@ -34,7 +34,6 @@ class JsLinkedHashMap<K, V> implements LinkedHashMap<K, V>, InternalMap {
JsLinkedHashMap();
-
int get length => _length;
bool get isEmpty => _length == 0;
bool get isNotEmpty => !isEmpty;
@@ -51,13 +50,11 @@ class JsLinkedHashMap<K, V> implements LinkedHashMap<K, V>, InternalMap {
if (_isStringKey(key)) {
var strings = _strings;
if (strings == null) return false;
- LinkedHashMapCell cell = _getTableEntry(strings, key);
- return cell != null;
+ return _containsTableEntry(strings, key);
} else if (_isNumericKey(key)) {
var nums = _nums;
if (nums == null) return false;
- LinkedHashMapCell cell = _getTableEntry(nums, key);
- return cell != null;
+ return _containsTableEntry(nums, key);
} else {
return internalContainsKey(key);
}
@@ -253,7 +250,7 @@ class JsLinkedHashMap<K, V> implements LinkedHashMap<K, V>, InternalMap {
}
static bool _isStringKey(var key) {
- return key is String && key != '__proto__';
+ return key is String;
}
static bool _isNumericKey(var key) {
@@ -270,19 +267,6 @@ class JsLinkedHashMap<K, V> implements LinkedHashMap<K, V>, InternalMap {
return JS('int', '# & 0x3ffffff', key.hashCode);
}
- static _getTableEntry(var table, var key) {
- return JS('var', '#[#]', table, key);
- }
-
- static void _setTableEntry(var table, var key, var value) {
- assert(value != null);
- JS('void', '#[#] = #', table, key, value);
- }
-
- static void _deleteTableEntry(var table, var key) {
- JS('void', 'delete #[#]', table, key);
- }
-
List _getBucket(var table, var key) {
var hash = internalComputeHashCode(key);
return JS('var', '#[#]', table, hash);
@@ -298,7 +282,32 @@ class JsLinkedHashMap<K, V> implements LinkedHashMap<K, V>, InternalMap {
return -1;
}
- static _newHashTable() {
+ String toString() => Maps.mapToString(this);
+
+ static bool get supportsEs6Maps {
+ return JS('returns:bool;depends:none;effects:none;',
+ 'typeof Map != "undefined"');
+ }
+
+ _getTableEntry(var table, var key) {
+ return JS('var', '#[#]', table, key);
+ }
+
+ void _setTableEntry(var table, var key, var value) {
+ assert(value != null);
+ JS('void', '#[#] = #', table, key, value);
+ }
+
+ void _deleteTableEntry(var table, var key) {
+ JS('void', 'delete #[#]', table, key);
+ }
+
+ bool _containsTableEntry(var table, var key) {
+ LinkedHashMapCell cell = _getTableEntry(table, key);
+ return cell != null;
+ }
+
+ _newHashTable() {
// Create a new JavaScript object to be used as a hash table. Use
// Object.create to avoid the properties on Object.prototype
// showing up as entries.
@@ -310,8 +319,34 @@ class JsLinkedHashMap<K, V> implements LinkedHashMap<K, V>, InternalMap {
_deleteTableEntry(table, temporaryKey);
return table;
}
+}
- String toString() => Maps.mapToString(this);
+class Es6LinkedHashMap<K, V> extends JsLinkedHashMap<K, V> {
+
+ @override
+ _getTableEntry(var table, var key) {
+ return JS('var', '#.get(#)', table, key);
+ }
+
+ @override
+ void _setTableEntry(var table, var key, var value) {
+ JS('void', '#.set(#, #)', table, key, value);
+ }
+
+ @override
+ void _deleteTableEntry(var table, var key) {
+ JS('void', '#.delete(#)', table, key);
+ }
+
+ @override
+ bool _containsTableEntry(var table, var key) {
+ return JS('bool', '#.has(#)', table, key);
+ }
+
+ @override
+ _newHashTable() {
+ return JS('var', 'new Map()');
+ }
}
class LinkedHashMapCell {
« no previous file with comments | « sdk/lib/_internal/compiler/js_lib/collection_patch.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698