Chromium Code Reviews| Index: sdk/lib/_internal/compiler/implementation/js_backend/minify_namer.dart |
| diff --git a/sdk/lib/_internal/compiler/implementation/js_backend/minify_namer.dart b/sdk/lib/_internal/compiler/implementation/js_backend/minify_namer.dart |
| index 98344a1e0a202b35b5f63fdd6c8f6749dda38fc8..4c537497f728daf359803c901e2872106ba4be92 100644 |
| --- a/sdk/lib/_internal/compiler/implementation/js_backend/minify_namer.dart |
| +++ b/sdk/lib/_internal/compiler/implementation/js_backend/minify_namer.dart |
| @@ -16,6 +16,9 @@ class MinifyNamer extends Namer { |
| String get isolatePropertiesName => 'p'; |
| bool get shouldMinify => true; |
| + final String getterPrefix = 'g'; |
| + final String setterPrefix = 's'; |
| + |
| const ALPHABET_CHARACTERS = 52; // a-zA-Z. |
| const ALPHANUMERIC_CHARACTERS = 62; // a-zA-Z0-9. |
| @@ -69,11 +72,17 @@ class MinifyNamer extends Namer { |
| 'refY', 'RGBA', 'root', 'rows', 'save', 'seed', 'seek', 'self', 'send', |
| 'show', 'SINE', 'size', 'span', 'stat', 'step', 'stop', 'tags', 'text', |
| 'Text', 'time', 'type', 'view', 'warn', 'wrap', 'ZERO']; |
| + |
| for (var name in reservedNativeProperties) { |
| if (name.length < 2) { |
| instanceNameMap[name] = name; |
| } |
| usedInstanceNames.add(name); |
| + // Getter and setter names are autogenerated by prepending 'g' and 's' to |
| + // field names. Therefore there are some field names we don't want to |
| + // use. |
| + if (name.startsWith('g')) usedInstanceNames.add(name.substring(1)); |
|
karlklose
2013/02/12 14:41:19
Can you use _hasBannedPrefix here?
erikcorry
2013/02/12 14:50:40
Yes, but the substring(1) still retains implicit k
|
| + if (name.startsWith('s')) usedInstanceNames.add(name.substring(1)); |
| } |
| // This list of popular instance variable names generated with: |
| @@ -152,7 +161,9 @@ class MinifyNamer extends Namer { |
| h2 ~/= ALPHANUMERIC_CHARACTERS; |
| } |
| final candidate = new String.fromCharCodes(codes); |
| - if (!usedNames.contains(candidate) && !jsReserved.contains(candidate)) { |
| + if (!usedNames.contains(candidate) && |
| + !jsReserved.contains(candidate) && |
| + !_hasBannedPrefix(candidate)) { |
| return candidate; |
| } |
| // Try again with a slightly different hash. After around 10 turns |
| @@ -168,9 +179,20 @@ class MinifyNamer extends Namer { |
| while (usedNames.contains("$startLetter$i")) { |
| i++; |
| } |
| + // We don't need to check for banned prefix because the name is in the form |
| + // xnnn, where nnn is a number. There can be no getter or setter called |
| + // gnnn since that would imply a numeric field name. |
| return "$startLetter$i"; |
| } |
| + // Instance members starting with g and s are reserved for getters and |
|
karlklose
2013/02/12 14:41:19
Use /// to turn comment into dart doc.
erikcorry
2013/02/12 14:50:40
Done.
|
| + // setters. |
| + bool _hasBannedPrefix(String name) { |
| + int code = name.codeUnitAt(0); |
| + if (code == $g || code == $s) return true; |
|
karlklose
2013/02/12 14:41:19
'return (code == $g || code == $s)'?
erikcorry
2013/02/12 14:50:40
Done.
|
| + return false; |
| + } |
| + |
| int _calculateHash(String name) { |
| int h = 0; |
| for (int i = 0; i < name.length; i++) { |