Chromium Code Reviews| Index: lib/compiler/implementation/js/printer.dart |
| diff --git a/lib/compiler/implementation/js/printer.dart b/lib/compiler/implementation/js/printer.dart |
| index 17f25c4325efe43348bc1f04ab72685e942541f1..4374f6101b5acab75884dedda9971f7f29649ae6 100644 |
| --- a/lib/compiler/implementation/js/printer.dart |
| +++ b/lib/compiler/implementation/js/printer.dart |
| @@ -948,37 +948,45 @@ class MinifyRenamer implements Namer { |
| if (maps.isEmpty) return oldName; |
| String newName; |
| - int n = nameNumber; |
| - if (n < LETTERS) { |
| - // Start naming variables a, b, c, ..., z, A, B, C, ..., Z. |
| - newName = new String.fromCharCodes([nthLetter(n)]); |
| - } else { |
| - // Then name variables a0, a1, a2, ..., a9, b0, b1, ..., Z9, aa0, aa1, ... |
| - // For all functions with fewer than 500 locals this is just as compact |
| - // as using aa, ab, etc. but avoids clashes with keywords. |
| - n -= LETTERS; |
| - int digit = n % DIGITS; |
| - n ~/= DIGITS; |
| - int alphaChars = 1; |
| - int nameSpaceSize = LETTERS; |
| - // Find out whether we should use the 1-character namespace (size 52), the |
| - // 2-character namespace (size 52*52), etc. |
| - while (n >= nameSpaceSize) { |
| - n -= nameSpaceSize; |
| - alphaChars++; |
| - nameSpaceSize *= LETTERS; |
| - } |
| - var codes = <int>[]; |
| - for (var i = 0; i < alphaChars; i++) { |
| - nameSpaceSize ~/= LETTERS; |
| - codes.add(nthLetter((n ~/ nameSpaceSize) % LETTERS)); |
| + do { |
| + int n = nameNumber; |
| + if (n < LETTERS) { |
| + // Start naming variables a, b, c, ..., z, A, B, C, ..., Z. |
| + newName = new String.fromCharCodes([nthLetter(n)]); |
| + } else { |
| + // Then name variables a0, a1, ..., a9, b0, b1, ..., Z9, aa0, aa1, ... |
| + // For all functions with fewer than 500 locals this is just as compact |
| + // as using aa, ab, etc. but avoids clashes with keywords. |
| + n -= LETTERS; |
| + int digit = n % DIGITS; |
| + n ~/= DIGITS; |
| + int alphaChars = 1; |
| + int nameSpaceSize = LETTERS; |
| + // Find out whether we should use the 1-character namespace (size 52), |
| + // the 2-character namespace (size 52*52), etc. |
| + while (n >= nameSpaceSize) { |
| + n -= nameSpaceSize; |
| + alphaChars++; |
| + nameSpaceSize *= LETTERS; |
| + } |
| + var codes = <int>[]; |
| + for (var i = 0; i < alphaChars; i++) { |
| + nameSpaceSize ~/= LETTERS; |
| + codes.add(nthLetter((n ~/ nameSpaceSize) % LETTERS)); |
| + } |
| + codes.add(charCodes.$0 + digit); |
| + newName = new String.fromCharCodes(codes); |
| } |
| - codes.add(charCodes.$0 + digit); |
| - newName = new String.fromCharCodes(codes); |
| - } |
| - assert(const RegExp(r'[a-zA-Z][a-zA-Z0-9]*').hasMatch(newName)); |
| - nameNumber++; |
| + assert(const RegExp(r'[a-zA-Z][a-zA-Z0-9]*').hasMatch(newName)); |
| + nameNumber++; |
| + } while (isReserved(newName)); |
| maps.last()[oldName] = newName; |
| return newName; |
| } |
| + |
| + // We only have names here that are single-letter or end with a digit, |
| + // since those are the ones we can generate. |
|
floitsch
2012/10/25 08:42:40
assert this.
erikcorry
2012/10/25 09:09:28
Done.
|
| + bool isReserved(String name) { |
| + return name == "I"; // Minified version of Isolate. |
|
floitsch
2012/10/25 12:58:38
Is there a way to get this set from the namer?
erikcorry
2012/12/06 09:38:07
Done.
|
| + } |
| } |