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

Unified Diff: pkg/compiler/lib/src/universe/world_builder.dart

Issue 2597663002: Refactor *WorldBuilder.registerDynamicUse (Closed)
Patch Set: Created 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/universe/world_builder.dart
diff --git a/pkg/compiler/lib/src/universe/world_builder.dart b/pkg/compiler/lib/src/universe/world_builder.dart
index 35e1c0b6a83484f9fa7d50326f35b5806455ec24..05cae632087b4e55bb370f00436ae9f815d95e30 100644
--- a/pkg/compiler/lib/src/universe/world_builder.dart
+++ b/pkg/compiler/lib/src/universe/world_builder.dart
@@ -478,9 +478,6 @@ class ResolutionWorldBuilderImpl implements ResolutionWorldBuilder {
<ClassElement, ClassHierarchyNode>{};
final Map<ClassElement, ClassSet> _classSets = <ClassElement, ClassSet>{};
- final Map<ClassElement, Map<ClassElement, bool>> _subtypeCoveredByCache =
Johnni Winther 2016/12/21 14:37:19 Only needed in ClosedWorldImpl
- <ClassElement, Map<ClassElement, bool>>{};
-
final Set<Element> alreadyPopulated;
final CacheStrategy cacheStrategy;
@@ -681,45 +678,33 @@ class ResolutionWorldBuilderImpl implements ResolutionWorldBuilder {
DynamicUse dynamicUse, MemberUsedCallback memberUsed) {
Selector selector = dynamicUse.selector;
String methodName = selector.name;
+
+ void _process(Map<String, Set<_MemberUsage>> memberMap,
+ EnumSet<MemberUse> action(_MemberUsage usage)) {
+ _processSet(memberMap, methodName, (_MemberUsage usage) {
+ if (dynamicUse.appliesUnnamed(usage.entity, this)) {
+ memberUsed(usage.entity, action(usage));
+ return true;
+ }
+ return false;
+ });
+ }
+
switch (dynamicUse.kind) {
case DynamicUseKind.INVOKE:
if (_registerNewSelector(dynamicUse, _invokedNames)) {
- _processInstanceMembers(methodName, (_MemberUsage usage) {
- if (dynamicUse.appliesUnnamed(usage.entity, this)) {
- memberUsed(usage.entity, usage.invoke());
- return true;
- }
- return false;
- });
+ _process(_instanceMembersByName, (m) => m.invoke());
}
break;
case DynamicUseKind.GET:
if (_registerNewSelector(dynamicUse, _invokedGetters)) {
- _processInstanceMembers(methodName, (_MemberUsage usage) {
- if (dynamicUse.appliesUnnamed(usage.entity, this)) {
- memberUsed(usage.entity, usage.read());
- return true;
- }
- return false;
- });
- _processInstanceFunctions(methodName, (_MemberUsage usage) {
- if (dynamicUse.appliesUnnamed(usage.entity, this)) {
- memberUsed(usage.entity, usage.read());
- return true;
- }
- return false;
- });
+ _process(_instanceMembersByName, (m) => m.read());
+ _process(_instanceFunctionsByName, (m) => m.read());
}
break;
case DynamicUseKind.SET:
if (_registerNewSelector(dynamicUse, _invokedSetters)) {
- _processInstanceMembers(methodName, (_MemberUsage usage) {
- if (dynamicUse.appliesUnnamed(usage.entity, this)) {
- memberUsed(usage.entity, usage.write());
- return true;
- }
- return false;
- });
+ _process(_instanceMembersByName, (m) => m.write());
}
break;
}
@@ -894,15 +879,6 @@ class ResolutionWorldBuilderImpl implements ResolutionWorldBuilder {
map[memberName].addAll(remaining);
}
- void _processInstanceMembers(String name, bool updateUsage(_MemberUsage e)) {
- _processSet(_instanceMembersByName, name, updateUsage);
- }
-
- void _processInstanceFunctions(
- String name, bool updateUsage(_MemberUsage e)) {
- _processSet(_instanceFunctionsByName, name, updateUsage);
- }
-
void _processInstantiatedClassMember(
ClassElement cls, MemberElement member, MemberUsedCallback memberUsed) {
assert(invariant(member, member.isDeclaration));
@@ -1320,47 +1296,35 @@ class CodegenWorldBuilderImpl implements CodegenWorldBuilder {
DynamicUse dynamicUse, MemberUsedCallback memberUsed) {
Selector selector = dynamicUse.selector;
String methodName = selector.name;
+
+ void _process(Map<String, Set<_MemberUsage>> memberMap,
+ EnumSet<MemberUse> action(_MemberUsage usage)) {
+ _processSet(memberMap, methodName, (_MemberUsage usage) {
+ if (dynamicUse.appliesUnnamed(usage.entity, _world)) {
+ memberUsed(usage.entity, action(usage));
+ return true;
+ }
+ return false;
+ });
+ }
+
switch (dynamicUse.kind) {
case DynamicUseKind.INVOKE:
if (_registerNewSelector(dynamicUse, _invokedNames)) {
- _processInstanceMembers(methodName, (_MemberUsage member) {
- if (dynamicUse.appliesUnnamed(member.entity, _world)) {
- memberUsed(member.entity, member.invoke());
- return true;
- }
- return false;
- });
+ _process(_instanceMembersByName, (m) => m.invoke());
return true;
}
break;
case DynamicUseKind.GET:
if (_registerNewSelector(dynamicUse, _invokedGetters)) {
- _processInstanceMembers(methodName, (_MemberUsage member) {
- if (dynamicUse.appliesUnnamed(member.entity, _world)) {
- memberUsed(member.entity, member.read());
- return true;
- }
- return false;
- });
- _processInstanceFunctions(methodName, (_MemberUsage member) {
- if (dynamicUse.appliesUnnamed(member.entity, _world)) {
- memberUsed(member.entity, member.read());
- return true;
- }
- return false;
- });
+ _process(_instanceMembersByName, (m) => m.read());
+ _process(_instanceFunctionsByName, (m) => m.read());
return true;
}
break;
case DynamicUseKind.SET:
if (_registerNewSelector(dynamicUse, _invokedSetters)) {
- _processInstanceMembers(methodName, (_MemberUsage member) {
- if (dynamicUse.appliesUnnamed(member.entity, _world)) {
- memberUsed(member.entity, member.write());
- return true;
- }
- return false;
- });
+ _process(_instanceMembersByName, (m) => m.write());
return true;
}
break;
@@ -1578,14 +1542,6 @@ class CodegenWorldBuilderImpl implements CodegenWorldBuilder {
map[memberName].addAll(remaining);
}
- void _processInstanceMembers(String n, bool f(_MemberUsage e)) {
- _processSet(_instanceMembersByName, n, f);
- }
-
- void _processInstanceFunctions(String n, bool f(_MemberUsage e)) {
- _processSet(_instanceFunctionsByName, n, f);
- }
-
/// Return the canonical [_ClassUsage] for [cls].
_ClassUsage _getClassUsage(ClassElement cls) {
return _processedClasses.putIfAbsent(cls, () => new _ClassUsage(cls));
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698