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

Unified Diff: sdk/lib/_internal/js_runtime/lib/constant_map.dart

Issue 1539033002: js_runtime tweaks for better code (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years 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/js_runtime/lib/constant_map.dart
diff --git a/sdk/lib/_internal/js_runtime/lib/constant_map.dart b/sdk/lib/_internal/js_runtime/lib/constant_map.dart
index 8a6a5c9d930370a3151b5d52ea9fd7058a6cbd1d..9e98b13dd3fbaa7e6d7509d0dd8dfff7037cab59 100644
--- a/sdk/lib/_internal/js_runtime/lib/constant_map.dart
+++ b/sdk/lib/_internal/js_runtime/lib/constant_map.dart
@@ -67,14 +67,18 @@ class ConstantStringMap<K, V> extends ConstantMap<K, V> {
// This constructor is not used for actual compile-time constants.
// The instantiation of constant maps is shortcut by the compiler.
- const ConstantStringMap._(this.length, this._jsObject, this._keys)
+ const ConstantStringMap._(this._length, this._jsObject, this._keys)
: super._();
- final int length;
+ // TODO(18131): Ensure type inference knows the precise types of the fields.
+ final int _length;
// A constant map is backed by a JavaScript object.
final _jsObject;
final List<K> _keys;
+ int get length => JS('JSUInt31', '#', _length);
+ List get _keysArray => JS('JSUnmodifiableArray', '#', _keys);
+
bool containsValue(Object needle) {
return values.any((V value) => value == needle);
}
@@ -97,7 +101,7 @@ class ConstantStringMap<K, V> extends ConstantMap<K, V> {
// Use a JS 'cast' to get efficient loop. Type inferrence doesn't get this
// since constant map representation is chosen after type inferrence and the
// instantiation is shortcut by the compiler.
- var keys = JS('JSArray', '#', _keys);
+ var keys = _keysArray;
for (int i = 0; i < keys.length; i++) {
var key = keys[i];
f(key, _fetch(key));
@@ -109,7 +113,7 @@ class ConstantStringMap<K, V> extends ConstantMap<K, V> {
}
Iterable<V> get values {
- return new MappedIterable<K, V>(_keys, (key) => _fetch(key));
+ return new MappedIterable<K, V>(_keysArray, (key) => _fetch(key));
}
}
@@ -135,9 +139,9 @@ class _ConstantMapKeyIterable<K> extends Iterable<K> {
ConstantStringMap<K, dynamic> _map;
_ConstantMapKeyIterable(this._map);
- Iterator<K> get iterator => _map._keys.iterator;
+ Iterator<K> get iterator => _map._keysArray.iterator;
- int get length => _map._keys.length;
+ int get length => _map._keysArray.length;
}
class GeneralConstantMap<K, V> extends ConstantMap<K, V> {
« no previous file with comments | « pkg/compiler/lib/src/js_backend/constant_system_javascript.dart ('k') | sdk/lib/_internal/js_runtime/lib/js_helper.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698