remove temporary map iterables from method lookups
Removes some unnecessary maps and scoots the (fast) supertype check to first.
I don't expect these temporary map iterables to have significant impact (though we should measure) but removing them doesn't hurt readability IMO so I think is a win. Happy for push back though!
Change-Id: I1641da3b34605e255c9d95ef7b490f7182e84e21
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/245560
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
diff --git a/pkg/analyzer/lib/src/error/must_call_super_verifier.dart b/pkg/analyzer/lib/src/error/must_call_super_verifier.dart
index 20856f3..e66ab21 100644
--- a/pkg/analyzer/lib/src/error/must_call_super_verifier.dart
+++ b/pkg/analyzer/lib/src/error/must_call_super_verifier.dart
@@ -6,6 +6,7 @@
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/element/element.dart';
+import 'package:analyzer/dart/element/type.dart';
import 'package:analyzer/error/listener.dart';
import 'package:analyzer/src/dart/element/element.dart';
import 'package:analyzer/src/dart/error/hint_codes.dart';
@@ -111,20 +112,15 @@
var classElement = element.enclosingElement as ClassElement;
String name = element.name;
- bool isConcrete(ClassElement element) =>
- element.lookUpConcreteMethod(name, element.library) != null;
-
- if (classElement.mixins.map((i) => i.element).any(isConcrete)) {
- return true;
- }
- if (classElement.superclassConstraints
- .map((i) => i.element)
- .any(isConcrete)) {
+ if (classElement.supertype.isConcrete(name)) {
return true;
}
- var supertype = classElement.supertype;
- if (supertype != null && isConcrete(supertype.element)) {
+ if (classElement.mixins.any((m) => m.isConcrete(name))) {
+ return true;
+ }
+
+ if (classElement.superclassConstraints.any((c) => c.isConcrete(name))) {
return true;
}
@@ -143,3 +139,12 @@
return;
}
}
+
+extension on InterfaceType? {
+ bool isConcrete(String name) {
+ var self = this;
+ if (self == null) return false;
+ var element = self.element;
+ return element.lookUpConcreteMethod(name, element.library) != null;
+ }
+}