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

Unified Diff: lib/compiler/implementation/js_backend/emitter.dart

Issue 10967013: Avoid generating duplicate stubs. Fixes issue 3184. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 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
« no previous file with comments | « no previous file | tests/compiler/dart2js/no_duplicate_stub_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/compiler/implementation/js_backend/emitter.dart
===================================================================
--- lib/compiler/implementation/js_backend/emitter.dart (revision 12681)
+++ lib/compiler/implementation/js_backend/emitter.dart (working copy)
@@ -351,7 +351,8 @@
*/
void addParameterStub(FunctionElement member,
Selector selector,
- DefineMemberFunction defineInstanceMember) {
+ DefineMemberFunction defineInstanceMember,
+ Set<String> alreadyGenerated) {
FunctionSignature parameters = member.computeSignature(compiler);
int positionalArgumentCount = selector.positionalArgumentCount;
if (positionalArgumentCount == parameters.parameterCount) {
@@ -371,6 +372,8 @@
String invocationName =
namer.instanceMethodInvocationName(member.getLibrary(), member.name,
selector);
+ if (alreadyGenerated.contains(invocationName)) return;
+ alreadyGenerated.add(invocationName);
CodeBuffer buffer = new CodeBuffer();
buffer.add('function(');
@@ -474,9 +477,15 @@
// stub arguments and the real method may be different.
Set<Selector> selectors = compiler.codegenWorld.invokedNames[member.name];
if (selectors == null) return;
+ // Keep a cache of which stubs have already been generated, to
+ // avoid duplicates. Note that even if selectors are
+ // canonicalized, we would still need this cache: a typed selector
+ // on A and a typed selector on B could yield the same stub.
+ Set<String> generatedStubNames = new Set<String>();
for (Selector selector in selectors) {
if (!selector.applies(member, compiler)) continue;
- addParameterStub(member, selector, defineInstanceMember);
+ addParameterStub(
+ member, selector, defineInstanceMember, generatedStubNames);
}
}
« no previous file with comments | « no previous file | tests/compiler/dart2js/no_duplicate_stub_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698