Chromium Code Reviews| Index: sdk/lib/_internal/compiler/implementation/js_backend/namer.dart |
| =================================================================== |
| --- sdk/lib/_internal/compiler/implementation/js_backend/namer.dart (revision 14946) |
| +++ sdk/lib/_internal/compiler/implementation/js_backend/namer.dart (working copy) |
| @@ -30,12 +30,23 @@ |
| final Map<String, int> usedGlobals; |
| final Map<String, LibraryElement> shortPrivateNameOwners; |
| + /// A cache of names used for bailout methods. We make sure two |
|
karlklose
2012/11/16 09:31:17
I think you should /**...*/ here.
ngeoffray
2012/11/16 10:37:56
Done.
|
| + /// bailout methods cannot have the same name because if one is |
|
karlklose
2012/11/16 09:31:17
I find "because if one is defined in a class that
ngeoffray
2012/11/16 10:37:56
Done.
|
| + /// defined in a class that is a subclass of the other, we would |
| + /// resolve to the wrong bailout method at runtime. To make it |
| + /// simple, we don't keep track of inheritance and always avoid |
| + /// similar names. |
| + final Set<String> usedBailoutNames; |
| + final Map<Element, String> bailoutNames; |
| + |
| final Map<Constant, String> constantNames; |
| Namer(this.compiler) |
| : globals = new Map<Element, String>(), |
| usedGlobals = new Map<String, int>(), |
| shortPrivateNameOwners = new Map<String, LibraryElement>(), |
| + bailoutNames = new Map<Element, String>(), |
| + usedBailoutNames = new Set<String>(), |
| constantNames = new Map<Constant, String>(); |
| final String CURRENT_ISOLATE = r'$'; |
| @@ -237,7 +248,15 @@ |
| } |
| String getBailoutName(Element element) { |
| - return '${getName(element)}\$bailout'; |
| + String name = bailoutNames[element]; |
| + if (name != null) return name; |
| + String candidate = '${getName(element)}\$bailout'; |
| + name = candidate; |
| + int i = 0; |
| + while (usedBailoutNames.contains(name)) name = '$candidate${i++}'; |
|
karlklose
2012/11/16 09:31:17
Should we have a UniqueElementNameGenerator abstra
|
| + bailoutNames[element] = name; |
| + usedBailoutNames.add(name); |
| + return name; |
| } |
| /** |