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

Unified Diff: pkg/dev_compiler/lib/src/compiler/js_names.dart

Issue 2834663002: Fix ddc perf issue (Closed)
Patch Set: Created 3 years, 8 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/dev_compiler/lib/src/compiler/js_names.dart
diff --git a/pkg/dev_compiler/lib/src/compiler/js_names.dart b/pkg/dev_compiler/lib/src/compiler/js_names.dart
index 456344a6a91e904e6a92f7956947989ab867f436..edfdec795dd3a7d32ea66efb3a126546dea23da3 100644
--- a/pkg/dev_compiler/lib/src/compiler/js_names.dart
+++ b/pkg/dev_compiler/lib/src/compiler/js_names.dart
@@ -178,12 +178,8 @@ class _RenameVisitor extends VariableDeclarationVisitor {
}
void _finishNames() {
- var allNames = new Set<String>();
pendingRenames.forEach((id, scopes) {
- allNames.clear();
- for (var s in scopes) allNames.addAll(s.used);
-
- var name = _findName(id, allNames);
+ var name = _findName(id, scopes);
for (var s in scopes) {
s.used.add(name);
s.renames[id] = name;
@@ -191,7 +187,7 @@ class _RenameVisitor extends VariableDeclarationVisitor {
});
}
- static String _findName(Object id, Set<String> usedNames) {
+ static String _findName(Object id, Set<_FunctionScope> scopes) {
String name;
bool valid;
if (id is TemporaryId) {
@@ -204,7 +200,7 @@ class _RenameVisitor extends VariableDeclarationVisitor {
// Try to use the temp's name, otherwise rename.
String candidate;
- if (valid && !usedNames.contains(name)) {
+ if (valid && !scopes.any((scope) => scope.used.contains(name))) {
candidate = name;
} else {
// This assumes that collisions are rare, hence linear search.
@@ -212,7 +208,9 @@ class _RenameVisitor extends VariableDeclarationVisitor {
// TODO(jmesserly): what's the most readable scheme here? Maybe 1-letter
// names in some cases?
candidate = name == 'function' ? 'func' : '${name}\$';
- for (int i = 0; usedNames.contains(candidate); i++) {
+ for (int i = 0;
+ scopes.any((scope) => scope.used.contains(candidate));
+ i++) {
candidate = '${name}\$$i';
}
}
« 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