Skip to content

Commit f5db566

Browse files
author
Stephan Herhut
committed
dart2js: Avoid common prefix for frequent bad names.
BUG= [email protected], [email protected] Review URL: https://codereview.chromium.org//1153363003.
1 parent bd25e64 commit f5db566

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

pkg/compiler/lib/src/js_backend/minify_namer.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,17 @@ class MinifyNamer extends Namer {
209209
return h;
210210
}
211211

212+
/// Remember bad hashes to avoid using a the same character with long numbers
213+
/// for frequent hashes. For example, `closure` is a very common name.
214+
Map<int, int> _badNames = new Map<int, int>();
215+
212216
/// If we can't find a hash based name in the three-letter space, then base
213217
/// the name on a letter and a counter.
214218
String _badName(int hash, Set<String> usedNames) {
215-
String startLetter = new String.fromCharCodes([_letterNumber(hash)]);
219+
int count = _badNames.putIfAbsent(hash, () => 0);
220+
String startLetter =
221+
new String.fromCharCodes([_letterNumber(hash + count)]);
222+
_badNames[hash] = count + 1;
216223
String name;
217224
int i = 0;
218225
do {

0 commit comments

Comments
 (0)