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

Unified Diff: dart/lib/compiler/implementation/namer.dart

Issue 10581036: Ensure uniqueness of global names. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Update comment Created 8 years, 6 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 | « dart/language/namer_test.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dart/lib/compiler/implementation/namer.dart
diff --git a/dart/lib/compiler/implementation/namer.dart b/dart/lib/compiler/implementation/namer.dart
index 09b1870464e19101b5d3d50c52ab01d2ca62fff9..a5b960e7b04ab8da17c48c2f3c2739e29f900c6a 100644
--- a/dart/lib/compiler/implementation/namer.dart
+++ b/dart/lib/compiler/implementation/namer.dart
@@ -106,21 +106,20 @@ class Namer {
}
String getFreshGlobalName(String proposedName) {
- int usedCount = usedGlobals[proposedName];
- if (usedCount === null) {
- // No element with this name has been used before.
- usedGlobals[proposedName] = 1;
- return proposedName;
- } else {
+ String name = proposedName;
+ int count = usedGlobals[name];
+ if (count !== null) {
// Not the first time we see this name. Append a number to make it unique.
- String name;
do {
- usedCount++;
- name = '$proposedName$usedCount';
+ name = '$proposedName${count++}';
} while (usedGlobals[name] !== null);
- usedGlobals[proposedName] = usedCount;
- return name;
+ // Record the count in case we see this name later. We
+ // frequently see names multiple times, as all our closures use
+ // the same name for their class.
+ usedGlobals[proposedName] = count;
}
+ usedGlobals[name] = 0;
+ return name;
}
static final String LIBRARY_PREFIX = "lib";
« no previous file with comments | « dart/language/namer_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698