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

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: Restore caching the count 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..7fbcdba5983edef451c685a5d824213a334368d2 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[proposedName];
+ 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 the name again, as all our closures use the
floitsch 2012/06/20 11:04:06 frequently see names multiple times
ahe 2012/06/20 11:15:59 Done.
+ // same name for their class.
+ usedGlobals[proposedName] = count;
}
+ usedGlobals[name] = 0;
floitsch 2012/06/20 11:04:06 usedGlobals.putIfAbsent(name, () => 0) ?
ahe 2012/06/20 11:15:59 At this point we know that usedGlobals[name] === n
+ 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