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

Unified Diff: tool/input_sdk/private/ddc_runtime/operations.dart

Issue 1963733003: Faster ignore. (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 4 years, 7 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 | « lib/runtime/dart_sdk.js ('k') | tool/input_sdk/private/ddc_runtime/types.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tool/input_sdk/private/ddc_runtime/operations.dart
diff --git a/tool/input_sdk/private/ddc_runtime/operations.dart b/tool/input_sdk/private/ddc_runtime/operations.dart
index 97359b68e263c0fb5b73c9a93407d39f31b294e6..dcf385485b2c6dbd08d11071679ff401c1c3fee2 100644
--- a/tool/input_sdk/private/ddc_runtime/operations.dart
+++ b/tool/input_sdk/private/ddc_runtime/operations.dart
@@ -176,22 +176,44 @@ dindex(obj, index) => _callMethod(obj, 'get', null, JS('', '[#]', index), '[]');
dsetindex(obj, index, value) =>
_callMethod(obj, 'set', null, JS('', '[#, #]', index, value), '[]=');
-_ignoreTypeFailure(actual, type) => JS('', '''(() => {
- // TODO(vsm): Remove this hack ...
- // This is primarily due to the lack of generic methods,
- // but we need to triage all the types.
- if (!!$isSubtype($type, $Iterable) && !!$isSubtype($actual, $Iterable) ||
- !!$isSubtype($type, $Future) && !!$isSubtype($actual, $Future) ||
- !!$isSubtype($type, $Map) && !!$isSubtype($actual, $Map) ||
- !!$isSubtype($type, $Function) && !!$isSubtype($actual, $Function) ||
- !!$isSubtype($type, $Stream) && !!$isSubtype($actual, $Stream) ||
- !!$isSubtype($type, $StreamSubscription) &&
- !!$isSubtype($actual, $StreamSubscription)) {
- console.warn('Ignoring cast fail from ' + $typeName($actual) +
- ' to ' + $typeName($type));
- return true;
- }
- return false;
+/// TODO(leafp): This duplicates code in types.dart.
+/// I haven't found a way to factor it out that makes the
+/// code generator happy though.
+_ignoreMemo(f) => JS('', '''(() => {
+ let memo = new Map();
+ return (t1, t2) => {
+ let map = memo.get(t1);
+ let result;
+ if (map) {
+ result = map.get(t2);
+ if (result !== void 0) return result;
+ } else {
+ memo.set(t1, map = new Map());
+ }
+ result = $f(t1, t2);
+ map.set(t2, result);
+ return result;
+ };
+})()''');
+
+final _ignoreTypeFailure = JS('', '''(() => {
+ return $_ignoreMemo((actual, type) => {
+ // TODO(vsm): Remove this hack ...
+ // This is primarily due to the lack of generic methods,
+ // but we need to triage all the types.
+ if (!!$isSubtype(type, $Iterable) && !!$isSubtype(actual, $Iterable) ||
vsm 2016/05/10 15:56:10 FWIW, for gt, I ended up replacing this with: v
Leaf 2016/05/10 16:43:05 Yeah, I started to optimize this, but it completel
+ !!$isSubtype(type, $Future) && !!$isSubtype(actual, $Future) ||
+ !!$isSubtype(type, $Map) && !!$isSubtype(actual, $Map) ||
+ $isFunctionType(type) && $isFunctionType(actual) ||
+ !!$isSubtype(type, $Stream) && !!$isSubtype(actual, $Stream) ||
+ !!$isSubtype(type, $StreamSubscription) &&
+ !!$isSubtype(actual, $StreamSubscription)) {
+ console.warn('Ignoring cast fail from ' + $typeName(actual) +
+ ' to ' + $typeName(type));
+ return true;
+ }
+ return false;
+ });
})()''');
/// Returns true if [obj] is an instance of [type]
« no previous file with comments | « lib/runtime/dart_sdk.js ('k') | tool/input_sdk/private/ddc_runtime/types.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698