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

Unified Diff: sdk/lib/_internal/compiler/implementation/inferrer/type_graph_inferrer.dart

Issue 24118004: It's not just [] that return the element type of a List. Make the container optimization work for s… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 3 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
Index: sdk/lib/_internal/compiler/implementation/inferrer/type_graph_inferrer.dart
===================================================================
--- sdk/lib/_internal/compiler/implementation/inferrer/type_graph_inferrer.dart (revision 27800)
+++ sdk/lib/_internal/compiler/implementation/inferrer/type_graph_inferrer.dart (working copy)
@@ -19,6 +19,28 @@
part 'type_graph_nodes.dart';
+/**
+ * A set of selector names that [List] implements, that we know return
+ * their element type.
+ */
+Set<String> returnsElementTypeSet = new Set<String>.from(
+ const <String>[
+ 'first',
+ 'last',
+ 'single',
+ 'singleWhere',
+ 'elementAt',
+ '[]',
+ 'removeAt',
+ 'removeLast'
+ ]);
+
+bool returnsElementType(Selector selector) {
+ return (selector.mask != null)
+ && selector.mask.isContainer
+ && returnsElementTypeSet.contains(selector.name.slowToString());
+}
+
class TypeInformationSystem extends TypeSystem<TypeInformation> {
final Compiler compiler;
@@ -766,9 +788,7 @@
if (selector.isSetter() || selector.isIndexSet()) {
return compiler.typesTask.dynamicType;
}
- if (selector.isIndex()
- && selector.mask != null
- && selector.mask.isContainer) {
+ if (returnsElementType(selector)) {
ContainerTypeMask mask = selector.mask;
TypeMask elementType = mask.elementType;
return elementType == null ? compiler.typesTask.dynamicType : elementType;

Powered by Google App Engine
This is Rietveld 408576698